Skip to content

Commit

Permalink
Make different internal id for different nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyWoo committed Jan 2, 2024
1 parent 6b3201e commit 3ae3c98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/Service/KeeperDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class KeeperDispatcher : public std::enable_shared_from_this<KeeperDispatcher>
/// Push forwarding request
bool pushForwardingRequest(size_t server_id, size_t client_id, ForwardRequestPtr request);

/// TODO remove
int64_t newSession(int64_t session_timeout_ms) { return server->newSession(session_timeout_ms); }
bool updateSessionTimeout(int64_t session_id, int64_t session_timeout_ms)
{
Expand Down Expand Up @@ -222,7 +223,11 @@ class KeeperDispatcher : public std::enable_shared_from_this<KeeperDispatcher>
int32_t myId() const { return server->myId(); }

/// When user create new session, we use this id as request id.
int64_t getNewSessionInternalId() { return new_session_internal_id_counter++; }
/// Note that the internal id for different nodes can be same.
int64_t getNewSessionInternalId() {
auto increment = myId() + 1; /// In case of my_id is 0
return new_session_internal_id_counter.fetch_add(increment) + increment;
}
};

}
12 changes: 6 additions & 6 deletions src/Service/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ using RaftSettingsPtr = std::shared_ptr<RaftSettings>;

struct Settings
{
static constexpr int NOT_EXIST = -1;
static constexpr int32_t NOT_EXIST = -1;
static const String DEFAULT_FOUR_LETTER_WORD_CMD;

Settings();
int my_id;
uint32_t my_id;

String host;
int port;
int32_t port;

// TODO add forwarding_port
int internal_port;
int32_t internal_port;

String log_dir;
String snapshot_dir;

int snapshot_create_interval;
int thread_count;
int32_t snapshot_create_interval;
int32_t thread_count;

String four_letter_word_white_list;

Expand Down

0 comments on commit 3ae3c98

Please sign in to comment.