From: Michael Tremer Date: Tue, 21 Oct 2025 18:05:52 +0000 (+0000) Subject: source: Implement actually migrating databases X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fcc999ab2b1da234870155090e1a5c37996ed49;p=telemetry.git source: Implement actually migrating databases Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index 21102f7..aa940ce 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -506,13 +506,22 @@ int td_source_submit(td_source* self, return td_daemon_submit(self->daemon, self, object, value); } -static int td_source_create_database(td_source* self, const char* path) { +static int td_source_create_database(td_source* self, const char* path, const char* source) { td_args* args = NULL; char min[24]; char max[24]; int r; - DEBUG(self->ctx, "Creating database for %s at %s\n", td_source_name(self), path); + // Source files when we are migrating + const char* sources[] = { + source, NULL, + }; + + // Log action + if (source) + DEBUG(self->ctx, "Creating database for %s at %s\n", td_source_name(self), path); + else + DEBUG(self->ctx, "Migrating database for %s from %s\n", td_source_name(self), source); // Allocate a new argument array r = td_args_create(&args, self->ctx); @@ -558,7 +567,7 @@ static int td_source_create_database(td_source* self, const char* path) { goto ERROR; // Create the RRD file - r = rrd_create_r(path, USEC_TO_SEC(HEARTBEAT / 2), 0, + r = rrd_create_r2(path, USEC_TO_SEC(HEARTBEAT / 2), 0, 0, sources, NULL, td_args_argc(args), td_args_argv(args)); if (r < 0) { ERROR(self->ctx, "Failed to create %s: %s\n", path, rrd_get_error()); @@ -857,7 +866,10 @@ static int td_source_migrate(td_source* self, const char* path) { } else if (r) { DEBUG(self->ctx, "%s needs migration!\n", path); - // XXX TODO + // Create a new database but use the old one as source + r = td_source_create_database(self, path, path); + if (r < 0) + goto ERROR; } ERROR: @@ -886,7 +898,7 @@ int td_source_commit(td_source* self, if (r < 0) { switch (errno) { case ENOENT: - r = td_source_create_database(self, path); + r = td_source_create_database(self, path, NULL); if (r < 0) return r; break;