Repository: valkey-io/valkey
File: src/aof.c (C)

Code before:
        rdbSaveInfo rsi = RDB_SAVE_INFO_INIT;
        int rdb_flags = RDBFLAGS_AOF_PREAMBLE;
        int rsi_is_valid = 0;
        if (iAmPrimary()) {
            if (server.repl_backlog == NULL) createReplicationBacklog();
            rdb_flags |= RDBFLAGS_FEED_REPL;
        }
        if (rdbLoadRio(&rdb, rdb_flags, &rsi) != C_OK) {
            if (old_style)
                serverLog(LL_WARNING, "Error reading the RDB preamble of the AOF file %s, AOF loading aborted",
                          filename);
            else
                serverLog(LL_WARNING, "Error reading the RDB base file %s, AOF loading aborted", filename);

            ret = AOF_FAILED;
            goto cleanup;
        } else {
            /* Restore the replication ID / offset from the RDB file. */
            rsi_is_valid = rdbRestoreOffsetFromSaveInfo(&rsi, true);
            loadingAbsProgress(ftello(fp));
            last_progress_report_size = ftello(fp);
            if (old_style) serverLog(LL_NOTICE, "Reading the remaining AOF tail...");
        }
        if (!rsi_is_valid && server.repl_backlog && listLength(server.replicas) == 0) freeReplicationBacklog();
    }

    /* Read the actual AOF file, in REPL format, command by command. */
    while (1) {
        int argc, j;
        unsigned long len;
        robj **argv;
        char buf[AOF_ANNOTATION_LINE_MAX_LEN];
        sds argsds;
        struct serverCommand *cmd;

        /* Serve the clients from time to time */
        if (!(loops++ % 1024)) {
            off_t progress_delta = ftello(fp) - last_progress_report_size;
            loadingIncrProgress(progress_delta);
            last_progress_report_size += progress_delta;
            processEventsWhileBlocked();
            processModuleLoadingProgressEvent(1);
        }
        if (fgets(buf, sizeof(buf), fp) == NULL) {
            if (feof(fp)) {
                break;
            } else {
                goto readerr;
            }
        }
        if (buf[0] == '#') continue; /* Skip annotations */

Review comment (suggestion):
I was curious why we do this and I found the answer in a comment in the corresponding code for RDB load. Is it worth adding a similar comment here? A shorter one perhaps like this?

```suggestion
        /* If the AOF didn't contain replication info, it's not possible to
         * support partial resync, so we can free the backlog to save memory. */
        if (!rsi_is_valid && server.repl_backlog && listLength(server.replicas) == 0) freeReplicationBacklog();
```

Code after:
        rdbSaveInfo rsi = RDB_SAVE_INFO_INIT;
        int rdb_flags = RDBFLAGS_AOF_PREAMBLE;
        int rsi_is_valid = 0;
        if (iAmPrimary()) {
            if (server.repl_backlog == NULL) createReplicationBacklog();
            rdb_flags |= RDBFLAGS_FEED_REPL;
        }
        if (rdbLoadRio(&rdb, rdb_flags, &rsi) != C_OK) {
            if (old_style)
                serverLog(LL_WARNING, "Error reading the RDB preamble of the AOF file %s, AOF loading aborted",
                          filename);
            else
                serverLog(LL_WARNING, "Error reading the RDB base file %s, AOF loading aborted", filename);

            ret = AOF_FAILED;
            goto cleanup;
        } else {
            /* Restore the replication ID / offset from the RDB file. */
            rsi_is_valid = rdbRestoreOffsetFromSaveInfo(&rsi, true);
            loadingAbsProgress(ftello(fp));
            last_progress_report_size = ftello(fp);
            if (old_style) serverLog(LL_NOTICE, "Reading the remaining AOF tail...");
        }
        /* If the AOF didn't contain replication info, it's not possible to
         * support partial resync, so we can free the backlog to save memory. */
        if (!rsi_is_valid && server.repl_backlog && listLength(server.replicas) == 0) freeReplicationBacklog();
    }

    /* Read the actual AOF file, in REPL format, command by command. */
    while (1) {
        int argc, j;
        unsigned long len;
        robj **argv;
        char buf[AOF_ANNOTATION_LINE_MAX_LEN];
        sds argsds;
        struct serverCommand *cmd;

        /* Serve the clients from time to time */
        if (!(loops++ % 1024)) {
            off_t progress_delta = ftello(fp) - last_progress_report_size;
            loadingIncrProgress(progress_delta);
            last_progress_report_size += progress_delta;
            processEventsWhileBlocked();
            processModuleLoadingProgressEvent(1);
        }
        if (fgets(buf, sizeof(buf), fp) == NULL) {
            if (feof(fp)) {
                break;
            } else {
                goto readerr;
            }