jihuayu commented on code in PR #1489:
URL: https://github.com/apache/kvrocks/pull/1489#discussion_r1238274447
##########
src/server/server.cc:
##########
@@ -1753,3 +1758,51 @@ std::list<std::pair<std::string, uint32_t>>
Server::GetSlaveHostAndPort() {
slave_threads_mu_.unlock();
return result;
}
+
+// The numeric cursor consists of a 16-bit counter, a 16-bit time stamp, a
29-bit hash,and a 3-bit cursor type. 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.
+NumberCursor::NumberCursor(CursorType cursor_type, uint16_t counter, const
std::string &key_name) {
+ auto hash = static_cast<uint32_t>(std::hash<std::string>{}(key_name));
+ auto time_stamp = static_cast<uint16_t>(util::GetTimeStamp());
+ cursor_ = static_cast<uint64_t>(counter) | static_cast<uint64_t>(time_stamp)
<< 16 |
+ static_cast<uint64_t>(hash) << 32 |
static_cast<uint64_t>(cursor_type) << 61;
+}
+
+bool NumberCursor::IsMatch(const CursorDictElement &element, CursorType
cursor_type) const {
+ return cursor_ == element.cursor.cursor_ && cursor_type == getCursorType();
Review Comment:
We need to ensure that the `cursor` generated by the `SCAN` command can only
be used by the `SCAN` command and cannot be used by the `HSCAN` or `ZSCAN`
commands.
--
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]