torwig commented on code in PR #1870:
URL: https://github.com/apache/kvrocks/pull/1870#discussion_r1382640463
##########
src/commands/cmd_stream.cc:
##########
@@ -472,6 +488,72 @@ class CommandXInfo : public Commander {
return Status::OK();
}
+
+ Status getGroupInfo(Server *srv, Connection *conn, std::string *output) {
+ redis::Stream stream_db(srv->storage, conn->GetNamespace());
+ std::vector<std::pair<std::string, StreamConsumerGroupMetadata>>
result_vector;
+ auto s = stream_db.GetGroupInfo(args_[2], result_vector);
+ if (!s.ok() && !s.IsNotFound()) {
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ if (s.IsNotFound()) {
+ return {Status::RedisExecErr, errNoSuchKey};
+ }
+
+ output->append(redis::MultiLen(result_vector.size()));
+ for (auto const &it : result_vector) {
+ output->append(redis::MultiLen(12));
+ output->append(redis::BulkString("name"));
+ output->append(redis::BulkString(it.first));
+ output->append(redis::BulkString("consumers"));
+ output->append(redis::Integer(it.second.consumer_number));
+ output->append(redis::BulkString("pending"));
+ output->append(redis::Integer(it.second.pending_number));
+ output->append(redis::BulkString("last-delivered-id"));
+
output->append(redis::BulkString(it.second.last_delivered_id.ToString()));
+ output->append(redis::BulkString("entries-read"));
+ if (it.second.entries_read == -1) {
+ output->append(redis::NilString());
+ } else {
+ output->append(redis::Integer(it.second.entries_read));
+ }
+ output->append(redis::BulkString("lag"));
+ output->append(redis::Integer(it.second.lag));
Review Comment:
Do we have any cases when the `lag` can't be determined? According to the
Redis documentation, there are 2 such cases.
##########
src/types/redis_stream.cc:
##########
@@ -232,6 +241,34 @@ std::string
Stream::encodeStreamConsumerMetadataValue(const StreamConsumerMetada
return dst;
}
+StreamConsumerMetadata Stream::decodeStreamConsumerMetadataValue(const
std::string &value) {
+ StreamConsumerMetadata consumer_metadata;
+ rocksdb::Slice input(value);
+ GetFixed64(&input, &consumer_metadata.pending_number);
+ GetFixed64(&input, &consumer_metadata.last_idle);
+ GetFixed64(&input, &consumer_metadata.last_active);
+ return consumer_metadata;
+}
+
+StreamSubkeyType Stream::identifySubkeyType(const rocksdb::Slice &key) {
+ InternalKey ikey(key, storage_->IsSlotIdEncoded());
+ Slice subkey = ikey.GetSubKey();
+ if (subkey.size() <= 16) { // id.ms(uint64) + id.seq(uint64)
Review Comment:
If you can introduce constants with descriptive names for the values `8`,
`16`, and another `8`, you will be able to get rid of explanation comments in
the code.
--
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]