Fix backwards compatibility with older snapshots

This commit is contained in:
Antonio Andelic 2022-06-15 13:46:27 +00:00
parent c403ebf4d2
commit ac0b7ab20b
3 changed files with 16 additions and 3 deletions

View File

@ -268,9 +268,14 @@ void KeeperStorageSnapshot::deserialize(SnapshotDeserializationResult & deserial
recalculate_digest = false;
}
}
storage.old_snapshot_zxid = 0;
}
else
{
storage.zxid = deserialization_result.snapshot_meta->get_last_log_idx();
storage.old_snapshot_zxid = storage.zxid;
}
int64_t session_id;
readBinary(session_id, in);

View File

@ -1769,9 +1769,10 @@ void KeeperStorage::preprocessRequest(
if (uncommitted_transactions.empty())
{
if (new_last_zxid <= last_zxid)
// if we have no uncommitted transactions it means the last zxid is possibly loaded from snapshot
if (last_zxid != old_snapshot_zxid && new_last_zxid <= last_zxid)
throw Exception(
ErrorCodes::LOGICAL_ERROR, "Got new ZXID {} smaller or equal to current ZXID ({}). It's a bug", new_last_zxid, last_zxid);
ErrorCodes::LOGICAL_ERROR, "Got new ZXID ({}) smaller or equal to current ZXID ({}). It's a bug", new_last_zxid, last_zxid);
}
else
{
@ -1781,7 +1782,7 @@ void KeeperStorage::preprocessRequest(
if (new_last_zxid <= last_zxid)
throw Exception(
ErrorCodes::LOGICAL_ERROR, "Got new ZXID {} smaller or equal to current ZXID ({}). It's a bug", new_last_zxid, last_zxid);
ErrorCodes::LOGICAL_ERROR, "Got new ZXID ({}) smaller or equal to current ZXID ({}). It's a bug", new_last_zxid, last_zxid);
}
std::vector<Delta> new_deltas;

View File

@ -298,6 +298,13 @@ public:
/// Global id of all requests applied to storage
int64_t zxid{0};
// older Keeper node (pre V5 snapshots) can create snapshots and receive logs from newer Keeper nodes
// this can lead to some inconsistencies, e.g. from snapshot it will use log_idx as zxid
// while the log will have a smaller zxid because it's generated by the newer nodes
// we save the value loaded from snapshot to know when is it okay to have
// smaller zxid in newer requests
int64_t old_snapshot_zxid{0};
struct TransactionInfo
{
int64_t zxid;