Skip to content

Commit

Permalink
Remove SnapshotVersion:V3 for no usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lzydmxy authored and JackyWoo committed Jun 5, 2024
1 parent 3543aba commit 6fe8382
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Service/NuRaftLogSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdio.h>
#include <unistd.h>

#include "common/find_symbols.h"
#include <common/find_symbols.h>

#include <Poco/DateTime.h>
#include <Poco/DateTimeFormatter.h>
Expand Down Expand Up @@ -886,14 +886,14 @@ size_t KeeperSnapshotManager::loadSnapshotMetas()
continue;
}

auto key = static_cast<uint128_t>(s_obj.log_last_term) << 64 | s_obj.log_last_index;
auto key = getSnapshotStoreMapKey(s_obj);

if (snapshots.find(key) == snapshots.end())
{
ptr<nuraft::cluster_config> config = cs_new<nuraft::cluster_config>(s_obj.log_last_index, s_obj.log_last_index - 1);
nuraft::snapshot meta(s_obj.log_last_index, s_obj.log_last_term, config);
ptr<KeeperSnapshotStore> snap_store = cs_new<KeeperSnapshotStore>(snap_dir, meta, object_node_size);
snap_store->init(s_obj.time_str);
snap_store->init(s_obj.create_time);
snapshots[key] = snap_store;
}
String full_path = snap_dir + "/" + file;
Expand Down
22 changes: 16 additions & 6 deletions src/Service/NuRaftLogSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ struct SnapObject
/// create_time, last_log_term, last_log_index, object_id
static constexpr char SNAPSHOT_FILE_NAME_V1[] = "snapshot_{}_{}_{}_{}";

String time_str;
String create_time;
UInt64 log_last_term;
UInt64 log_last_index;
UInt64 object_id;

SnapObject(String _time_str = "", UInt64 _log_last_term = 1, UInt64 _log_last_index = 1, UInt64 _object_id = 1)
:time_str(_time_str), log_last_term(_log_last_term), log_last_index(_log_last_index), object_id(_object_id)
SnapObject(String _create_time = "", UInt64 _log_last_term = 1, UInt64 _log_last_index = 1, UInt64 _object_id = 1)
:create_time(_create_time), log_last_term(_log_last_term), log_last_index(_log_last_index), object_id(_object_id)
{
}

String getObjectName()
{
return fmt::format(SNAPSHOT_FILE_NAME_V1, time_str, log_last_term, log_last_index, object_id);
return fmt::format(SNAPSHOT_FILE_NAME_V1, create_time, log_last_term, log_last_index, object_id);
}

bool parseInfoFromObjectName(const String & object_name)
Expand Down Expand Up @@ -108,7 +108,7 @@ struct SnapObject
return false;
}

time_str = std::move(tokens[1]);
create_time = std::move(tokens[1]);

return true;
}
Expand Down Expand Up @@ -270,9 +270,19 @@ class KeeperSnapshotStore
};

// In Raft, each log entry can be uniquely identified by the combination of its Log Index and Term.
inline uint128_t getSnapshotStoreMapKeyImpl(UInt64 log_term, UInt64 log_idx)
{
return static_cast<uint128_t>(log_term) << 64 | log_idx;
}

inline uint128_t getSnapshotStoreMapKey(const snapshot & meta)
{
return static_cast<uint128_t>(meta.get_last_log_term()) << 64 | meta.get_last_log_idx();
return getSnapshotStoreMapKeyImpl(meta.get_last_log_term(), meta.get_last_log_idx());
}

inline uint128_t getSnapshotStoreMapKey(const SnapObject & obj)
{
return getSnapshotStoreMapKeyImpl(obj.log_last_term, obj.log_last_index);
}

// Map key is term << 64 | log
Expand Down
1 change: 0 additions & 1 deletion src/Service/SnapshotCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ enum SnapshotVersion : uint8_t
V0 = 0,
V1 = 1, /// Add ACL map
V2 = 2, /// Replace protobuf
V3 = 3, /// Add last_log_term to file name
None = 255,
};

Expand Down

0 comments on commit 6fe8382

Please sign in to comment.