mapleFU commented on code in PR #1704:
URL: https://github.com/apache/kvrocks/pull/1704#discussion_r1310578560


##########
src/types/redis_stream.cc:
##########
@@ -160,6 +163,142 @@ rocksdb::Status Stream::Add(const Slice &stream_name, 
const StreamAddOptions &op
   return storage_->Write(storage_->DefaultWriteOptions(), 
batch->GetWriteBatch());
 }
 
+std::string Stream::internalKeyFromGroupName(const std::string &ns_key, const 
StreamMetadata &metadata,
+                                             const std::string &group_name) 
const {
+  std::string sub_key;
+  PutFixed64(&sub_key, group_name.size());
+  sub_key += group_name;
+  sub_key += "METADATA";
+  std::string entry_key = InternalKey(ns_key, sub_key, metadata.version, 
storage_->IsSlotIdEncoded()).Encode();
+  return entry_key;
+}
+
+std::string Stream::groupNameFromInternalKey(const rocksdb::Slice &key) const {
+  InternalKey ikey(key, storage_->IsSlotIdEncoded());
+  Slice group_name_metadata = ikey.GetSubKey();
+  uint64_t len = 0;
+  GetFixed64(&group_name_metadata, &len);
+  std::string group_name = group_name_metadata.ToString().substr(0, len);

Review Comment:
   Oh I think we won't overflow `u64`. It's a kind of defensive programming, 
since maybe internal key passed to `groupNameFromInternalKey` is kind of 
rubbish, it might to short or given a bad `length`. And `substr` it might 
causing a segment fault.
   
   It might not happen if everything works well, and if something bad happens, 
we still suffer from error or bug. However I think adding a `Status` and 
checking here is no risky 



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