Yangsx-1 commented on code in PR #2190:
URL: https://github.com/apache/kvrocks/pull/2190#discussion_r1545721260


##########
src/types/redis_stream.cc:
##########
@@ -343,8 +346,26 @@ rocksdb::Status Stream::DeletePelEntries(const Slice 
&stream_name, const std::st
     std::string entry_key = internalPelKeyFromGroupAndEntryId(ns_key, 
metadata, group_name, id);
     std::string value;
     s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, entry_key, 
&value);
+
     if (s.ok()) {
       *acknowledged += 1;
+      StreamPelEntry pel_entry = decodeStreamPelEntryValue(value);
+
+      const std::string &consumer_name = pel_entry.consumer_name;
+      std::string consumer_key = internalKeyFromConsumerName(ns_key, metadata, 
group_name, consumer_name);
+      std::string get_consumer_value;
+      s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, 
consumer_key, &get_consumer_value);
+      if (!s.ok() && !s.IsNotFound()) {
+        return s;
+      }
+      if (s.IsNotFound()) {
+        return rocksdb::Status::OK();
+      }
+
+      StreamConsumerMetadata consumer_metadata = 
decodeStreamConsumerMetadataValue(get_consumer_value);
+      consumer_metadata.pending_number -= 1;
+
+      batch->Put(stream_cf_handle_, consumer_key, 
encodeStreamConsumerMetadataValue(consumer_metadata));
       batch->Delete(stream_cf_handle_, entry_key);

Review Comment:
   I think this line should be put after `*acknowledged += 1` , because the 
entry_key may not be delete due to the early return.



##########
src/types/redis_stream.cc:
##########
@@ -343,8 +346,26 @@ rocksdb::Status Stream::DeletePelEntries(const Slice 
&stream_name, const std::st
     std::string entry_key = internalPelKeyFromGroupAndEntryId(ns_key, 
metadata, group_name, id);
     std::string value;
     s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, entry_key, 
&value);
+
     if (s.ok()) {
       *acknowledged += 1;
+      StreamPelEntry pel_entry = decodeStreamPelEntryValue(value);
+
+      const std::string &consumer_name = pel_entry.consumer_name;
+      std::string consumer_key = internalKeyFromConsumerName(ns_key, metadata, 
group_name, consumer_name);
+      std::string get_consumer_value;
+      s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, 
consumer_key, &get_consumer_value);
+      if (!s.ok() && !s.IsNotFound()) {
+        return s;
+      }
+      if (s.IsNotFound()) {
+        return rocksdb::Status::OK();

Review Comment:
   I don't think it's a return here. The above line is the same. It should not 
affect other consumers and the final result.



##########
src/types/redis_stream.cc:
##########
@@ -343,8 +346,26 @@ rocksdb::Status Stream::DeletePelEntries(const Slice 
&stream_name, const std::st
     std::string entry_key = internalPelKeyFromGroupAndEntryId(ns_key, 
metadata, group_name, id);
     std::string value;
     s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, entry_key, 
&value);
+
     if (s.ok()) {
       *acknowledged += 1;
+      StreamPelEntry pel_entry = decodeStreamPelEntryValue(value);
+
+      const std::string &consumer_name = pel_entry.consumer_name;
+      std::string consumer_key = internalKeyFromConsumerName(ns_key, metadata, 
group_name, consumer_name);
+      std::string get_consumer_value;
+      s = storage_->Get(rocksdb::ReadOptions(), stream_cf_handle_, 
consumer_key, &get_consumer_value);
+      if (!s.ok() && !s.IsNotFound()) {
+        return s;
+      }
+      if (s.IsNotFound()) {
+        return rocksdb::Status::OK();
+      }
+
+      StreamConsumerMetadata consumer_metadata = 
decodeStreamConsumerMetadataValue(get_consumer_value);
+      consumer_metadata.pending_number -= 1;

Review Comment:
   Good catch! You're right.



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