From 1d5873da395fbb929e1502433158eb5607780d47 Mon Sep 17 00:00:00 2001 From: malavan Date: Tue, 16 Nov 2021 02:13:36 +0000 Subject: [PATCH 1/3] fix dataloss on aof load with storage provider Former-commit-id: 447c8601b5203346fdd4b956ad1ac87c4a6073c8 --- src/aof.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/aof.cpp b/src/aof.cpp index 326c30ba2..f99a90b2e 100644 --- a/src/aof.cpp +++ b/src/aof.cpp @@ -870,6 +870,11 @@ int loadAppendOnlyFile(char *filename) { fakeClient = createAOFClient(); startLoadingFile(fp, filename, RDBFLAGS_AOF_PREAMBLE); + for (int idb = 0; idb < cserver.dbnum; ++idb) + { + g_pserver->db[idb]->trackChanges(true); + } + /* Check if this AOF file has an RDB preamble. In that case we need to * load the RDB file and later continue loading the AOF tail. */ char sig[5]; /* "REDIS" */ @@ -892,11 +897,6 @@ int loadAppendOnlyFile(char *filename) { } } - for (int idb = 0; idb < cserver.dbnum; ++idb) - { - g_pserver->db[idb]->trackChanges(true); - } - /* Read the actual AOF file, in REPL format, command by command. */ while(1) { int argc, j; From a382f2fffdf4452c3f13e5bc9e11f48cf73ef9ce Mon Sep 17 00:00:00 2001 From: malavan Date: Wed, 24 Nov 2021 21:59:01 +0000 Subject: [PATCH 2/3] remove async write from fast sync repl buffer and fix some bugs Former-commit-id: 6c45706f75d8322281296d9c73a3fac4f7f383a1 --- src/replication.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/replication.cpp b/src/replication.cpp index 3651b0113..06160bc8c 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -975,14 +975,7 @@ public: aeAcquireLock(); } - if (ireplica == replicas.size()-1 && replica->replyAsync == nullptr) { - if (prepareClientToWrite(replica) == C_OK) { - replica->replyAsync = reply; - reply = nullptr; - } - } else { - addReplyProto(replica, reply->buf(), reply->size); - } + addReplyProto(replica, reply->buf(), reply->used); } ProcessPendingAsyncWrites(); replicas.erase(std::remove_if(replicas.begin(), replicas.end(), [](const client *c)->bool{ return c->flags.load(std::memory_order_relaxed) & CLIENT_CLOSE_ASAP;}), replicas.end()); @@ -1089,7 +1082,7 @@ int rdbSaveSnapshotForReplication(struct rdbSaveInfo *rsi) { spreplBuf->addLong(rsi->repl_stream_db); spreplBuf->addArrayLen(2); spreplBuf->addString("repl-id", 7); - spreplBuf->addString(rsi->repl_id, CONFIG_RUN_ID_SIZE+1); + spreplBuf->addString(rsi->repl_id, CONFIG_RUN_ID_SIZE); spreplBuf->addArrayLen(2); spreplBuf->addString("repl-offset", 11); spreplBuf->addLong(rsi->master_repl_offset); From 76b900db220257d15c47e0bce9a108e9a4d23465 Mon Sep 17 00:00:00 2001 From: malavan Date: Fri, 26 Nov 2021 17:46:41 +0000 Subject: [PATCH 3/3] client lock for fast sync replbuffer, delay fast sync for next replication cron Former-commit-id: 9fe7f8328d66f9ec57060934462ad85ef60c36aa --- src/replication.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/replication.cpp b/src/replication.cpp index c55617cba..d99346a57 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -975,6 +975,7 @@ public: aeAcquireLock(); } + std::unique_lock lock(replica->lock); addReplyProto(replica, reply->buf(), reply->used); } ProcessPendingAsyncWrites(); @@ -1380,7 +1381,7 @@ void syncCommand(client *c) { /* CASE 0: Fast Sync */ if ((c->slave_capa & SLAVE_CAPA_ROCKSDB_SNAPSHOT) && g_pserver->m_pstorageFactory) { - startBgsaveForReplication(c->slave_capa); + serverLog(LL_NOTICE,"Fast SYNC on next replication cycle"); /* CASE 1: BGSAVE is in progress, with disk target. */ } else if (g_pserver->FRdbSaveInProgress() && g_pserver->rdb_child_type == RDB_CHILD_TYPE_DISK)