]> git.ipfire.org Git - collecty.git/commitdiff
source: Implement actually migrating databases
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 18:05:52 +0000 (18:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Oct 2025 18:05:52 +0000 (18:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c

index 21102f772459a6d69243e787826db79d529da337..aa940ce7e47d19d6e4aca51ccb277060a110a209 100644 (file)
@@ -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;