feat(replication): Use a ring buffer with messages to serve replication. (#1835)

* feat(replication): Use a ring buffer with messages to serve replication.

* Fix libraries dep graph

* Address PR feedback

* nits

* add a comment

* Lower the default log length
This commit is contained in:
Roy Jacobson 2023-09-18 13:59:41 +03:00 committed by GitHub
parent 1e61ec8114
commit db21b735f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 127 additions and 65 deletions

View file

@ -4,6 +4,8 @@
#include "server/rdb_load.h"
#include "absl/strings/escaping.h"
extern "C" {
#include "redis/intset.h"
@ -2147,20 +2149,28 @@ error_code RdbLoaderBase::HandleJournalBlob(Service* service) {
while (done < num_entries) {
journal::ParsedEntry entry{};
SET_OR_RETURN(journal_reader_.ReadEntry(), entry);
done++;
if (!entry.cmd.cmd_args.empty()) {
if (absl::EqualsIgnoreCase(facade::ToSV(entry.cmd.cmd_args[0]), "FLUSHALL") ||
absl::EqualsIgnoreCase(facade::ToSV(entry.cmd.cmd_args[0]), "FLUSHDB")) {
// Applying a flush* operation in the middle of a load can cause out-of-sync deletions of
// data that should not be deleted, see https://github.com/dragonflydb/dragonfly/issues/1231
// By returning an error we are effectively restarting the replication.
return RdbError(errc::unsupported_operation);
}
// EXEC entries are just for preserving atomicity of transactions. We don't create
// transactions and we don't care about atomicity when we're loading an RDB, so skip them.
// Currently rdb_save also filters those records out, but we filter them additionally here
// for better forward compatibility if we decide to change that.
if (entry.opcode == journal::Op::EXEC)
continue;
if (entry.cmd.cmd_args.empty())
return RdbError(errc::rdb_file_corrupted);
if (absl::EqualsIgnoreCase(facade::ToSV(entry.cmd.cmd_args[0]), "FLUSHALL") ||
absl::EqualsIgnoreCase(facade::ToSV(entry.cmd.cmd_args[0]), "FLUSHDB")) {
// Applying a flush* operation in the middle of a load can cause out-of-sync deletions of
// data that should not be deleted, see https://github.com/dragonflydb/dragonfly/issues/1231
// By returning an error we are effectively restarting the replication.
return RdbError(errc::unsupported_operation);
}
VLOG(1) << "Executing item: " << entry.ToString();
ex.Execute(entry.dbid, entry.cmd);
VLOG(1) << "Reading item: " << entry.ToString();
done++;
}
return std::error_code{};