infdahai commented on code in PR #1489:
URL:
https://github.com/apache/incubator-kvrocks/pull/1489#discussion_r1234660238
##########
src/server/server.cc:
##########
@@ -1753,3 +1755,52 @@ std::list<std::pair<std::string, uint32_t>>
Server::GetSlaveHostAndPort() {
slave_threads_mu_.unlock();
return result;
}
+
+// The numeric cursor consists of a 32-bit hash, a 16-bit time stamp, and a
16-bit counter, with the highest bit set to
+// 1 to prevent a zero cursor from occurring. The hash is used to prevent
information leakage. The time_stamp is used to
+// prevent the generation of the same cursor in the extremely short period
before and after a restart.
+static uint64_t GetNumberCursor(const std::string &key_name, uint16_t counter)
{
+ auto hash = static_cast<uint32_t>(std::hash<std::string>{}(key_name));
+ auto time_stamp = static_cast<uint16_t>(util::GetTimeStamp());
+ // set first bit 1, so number cursor not be 0
+ return static_cast<uint64_t>(hash) | static_cast<uint64_t>(time_stamp) << 32
| static_cast<uint64_t>(counter) << 48 |
+ static_cast<uint64_t>(1) << 63;
Review Comment:
I just wondering you use GetIndexFromNumberCursor() to generate the index of
the array `cursor_dict_`. It seems we will ignore the high bit of the index
because we module the num by `CURSOR_DICT_SIZE`. So the key point is that we
need the `1` to block the `numeric cursor` from 0 and we will reduce the
confilct if we put the bit to the counter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]