infdahai commented on code in PR #1489:
URL: 
https://github.com/apache/incubator-kvrocks/pull/1489#discussion_r1234260165


##########
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;
+}
+
+static size_t GetIndexFromNumberCursor(uint64_t number_cursor) { return 
(number_cursor >> 48) % CURSOR_DICT_SIZE; }

Review Comment:
   hi @jihuayu can I ask why the counter puts the high bit? I mean maybe we 
don't need to move the bit here.



-- 
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]

Reply via email to