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

Code before:
        serverLog(LL_WARNING, "Wrong signature trying to load DB from file");
        return C_ERR;
    }
    rdbver = atoi(buf + 6);
    if (rdbver < 1 || (rdbver < RDB_FOREIGN_VERSION_MIN && !is_redis_magic) ||
        (rdbver >= RDB_FOREIGN_VERSION_MIN && rdbver <= RDB_FOREIGN_VERSION_MAX) ||
        (rdbver > RDB_FOREIGN_VERSION_MAX && !is_valkey_magic) ||
        (rdbver > RDB_VERSION && server.rdb_version_check == RDB_VERSION_CHECK_STRICT)) {
        serverLog(LL_WARNING, "Can't handle RDB format version %d", rdbver);
        return C_ERR;
    }

    /* Key-specific attributes, set by opcodes before the key type. */
    long long lru_idle = -1, lfu_freq = -1, expiretime = -1, now = mstime();
    long long lru_clock = LRU_CLOCK();

    while (1) {
        sds key;
        robj *val;

        /* Read type. */
        if ((type = rdbLoadType(rdb)) == -1) goto eoferr;

        /* Safeguard for unknown foreign opcode interpretations. */
        if (is_redis_magic && type >= RDB_FOREIGN_TYPE_MIN && type <= RDB_FOREIGN_TYPE_MAX) {
            serverLog(LL_WARNING, "Can't handle foreign type or opcode %d in RDB %d",
                      type, rdbver);
            return C_ERR;
        }

        /* Handle special types. */
        if (type == RDB_OPCODE_EXPIRETIME) {
            /* EXPIRETIME: load an expire associated with the next key
             * to load. Note that after loading an expire we need to
             * load the actual type, and continue. */
            expiretime = rdbLoadTime(rdb);
            expiretime *= 1000;
            if (rioGetReadError(rdb)) goto eoferr;
            continue; /* Read next opcode. */
        } else if (type == RDB_OPCODE_EXPIRETIME_MS) {
            /* EXPIRETIME_MS: milliseconds precision expire times introduced
             * with RDB v3. Like EXPIRETIME but no with more precision. */
            expiretime = rdbLoadMillisecondTime(rdb, rdbver);
            if (rioGetReadError(rdb)) goto eoferr;
            continue; /* Read next opcode. */
        } else if (type == RDB_OPCODE_FREQ) {
            /* FREQ: LFU frequency. */
            uint8_t byte;
            if (rioRead(rdb, &byte, 1) == 0) goto eoferr;
            lfu_freq = byte;
            continue; /* Read next opcode. */

Review comment (suggestion):
```suggestion
            serverLog(LL_WARNING, "Can't handle foreign type or opcode %d in RDB with version %d",
```

Code after:
    uint64_t db_size = 0, expires_size = 0;
    int should_expand_db = 0;
    if (rdb_loading_ctx->dbarray[0] == NULL) {
        rdb_loading_ctx->dbarray[0] = createDatabase(0);
    }
    serverDb *db = rdb_loading_ctx->dbarray[0];
    char buf[1024];
    int error;
    long long empty_keys_skipped = 0;
    bool is_valkey_magic = false, is_redis_magic = false;

    rdb->update_cksum = rdbLoadProgressCallback;
    rdb->max_processing_chunk = server.loading_process_events_interval_bytes;
    if (rioRead(rdb, buf, 9) == 0) goto eoferr;
    buf[9] = '\0';
    if (memcmp(buf, "REDIS0", 6) == 0) {
        is_redis_magic = true;
    } else if (memcmp(buf, "VALKEY", 6) == 0) {
        is_valkey_magic = true;
    } else {
        serverLog(LL_WARNING, "Wrong signature trying to load DB from file");
        return C_ERR;
    }
    rdbver = atoi(buf + 6);
    if (!rdbIsVersionAccepted(rdbver, is_valkey_magic, is_redis_magic)) {
        serverLog(LL_WARNING, "Can't handle RDB format version %d", rdbver);
        return C_ERR;
    }

    /* Key-specific attributes, set by opcodes before the key type. */
    long long lru_idle = -1, lfu_freq = -1, expiretime = -1, now = mstime();
    long long lru_clock = LRU_CLOCK();

    while (1) {
        sds key;
        robj *val;

        /* Read type. */
        if ((type = rdbLoadType(rdb)) == -1) goto eoferr;

        /* Safeguard for unknown foreign opcode interpretations. */
        if (is_redis_magic && type >= RDB_FOREIGN_TYPE_MIN && type <= RDB_FOREIGN_TYPE_MAX) {
            serverLog(LL_WARNING, "Can't handle foreign type or opcode %d in RDB with version %d",
                      type, rdbver);
            return C_ERR;
        }

        /* Handle special types. */
        if (type == RDB_OPCODE_EXPIRETIME) {
            /* EXPIRETIME: load an expire associated with the next key
             * to load. Note that after loading an expire we need to