mapleFU commented on code in PR #1799:
URL: https://github.com/apache/kvrocks/pull/1799#discussion_r1355180071
##########
src/types/redis_stream.cc:
##########
@@ -313,6 +334,62 @@ rocksdb::Status Stream::DestroyGroup(const Slice
&stream_name, const std::string
return storage_->Write(storage_->DefaultWriteOptions(),
batch->GetWriteBatch());
}
+rocksdb::Status Stream::CreateConsumer(const Slice &stream_name, const
std::string &group_name,
+ const std::string &consumer_name, int
*created_number) {
+ if (std::isdigit(consumer_name[0])) {
+ return rocksdb::Status::InvalidArgument("consumer name cannot start with
number");
+ }
+ std::string ns_key = AppendNamespacePrefix(stream_name);
+ LockGuard guard(storage_->GetLockManager(), ns_key);
+ StreamMetadata metadata;
+ rocksdb::Status s = GetMetadata(ns_key, &metadata);
+ if (!s.ok() && !s.IsNotFound()) {
+ return s;
+ }
+ if (s.IsNotFound()) {
+ return
rocksdb::Status::InvalidArgument(errXGroupSubcommandRequiresKeyExist);
+ }
+
+ std::string entry_key = internalKeyFromGroupName(ns_key, metadata,
group_name);
+ std::string get_entry_value;
+ s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, entry_key,
&get_entry_value);
+ if (!s.ok() && !s.IsNotFound()) {
+ return s;
+ }
+ if (s.IsNotFound()) {
+ return rocksdb::Status::InvalidArgument("NOGROUP No such consumer group" +
group_name + "for key name" +
+ stream_name.ToString());
+ }
+
+ StreamConsumerMetadata consumer_metadata;
+ auto now = util::GetTimeStampMS();
+ consumer_metadata.last_idle = now;
+ consumer_metadata.last_active = now;
+ std::string consumer_key = internalKeyFromConsumerName(ns_key, metadata,
group_name, consumer_name);
+ std::string consumer_value =
encodeStreamConsumerMetadataValue(consumer_metadata);
+ std::string get_consumer_value;
+ s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, consumer_key,
&get_consumer_value);
+ if (!s.IsNotFound()) {
+ if (!s.ok()) {
+ return s;
+ }
+ return rocksdb::Status::OK();
Review Comment:
```
if (!s.IsNotFound()) {
// if s.ok(), it means it already ...
return s;
}
```
Would code like this ok?
--
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]