LindaSummer commented on code in PR #2826:
URL: https://github.com/apache/kvrocks/pull/2826#discussion_r1996861392


##########
src/types/redis_tdigest.cc:
##########
@@ -238,7 +238,46 @@ rocksdb::Status TDigest::Quantile(engine::Context& ctx, 
const Slice& digest_name
 
   return rocksdb::Status::OK();
 }
+rocksdb::Status TDigest::Reset(engine::Context& ctx, const Slice& digest_name) 
{
+  auto ns_key = AppendNamespacePrefix(digest_name);
+
+  TDigestMetadata metadata;
+  auto status = getMetaDataByNsKey(ctx, ns_key, &metadata);
+  if (!status.ok()) {
+    return status;
+  }
+
+  auto batch = storage_->GetWriteBatchBase();
+  WriteBatchLogData log_data(kRedisTDigest);
+  status = batch->PutLogData(log_data.Encode());
+  if (!status.ok()) {
+    return status;
+  }
 
+  // metadata.compression = 0;

Review Comment:
   Hi @SharonIV0x86 ,
   
   It will be better to remove unused code comments. 😊
   
   Best Regards,
   Edward



##########
src/types/redis_tdigest.cc:
##########
@@ -238,7 +238,46 @@ rocksdb::Status TDigest::Quantile(engine::Context& ctx, 
const Slice& digest_name
 
   return rocksdb::Status::OK();
 }
+rocksdb::Status TDigest::Reset(engine::Context& ctx, const Slice& digest_name) 
{
+  auto ns_key = AppendNamespacePrefix(digest_name);
+
+  TDigestMetadata metadata;
+  auto status = getMetaDataByNsKey(ctx, ns_key, &metadata);
+  if (!status.ok()) {
+    return status;
+  }
+
+  auto batch = storage_->GetWriteBatchBase();
+  WriteBatchLogData log_data(kRedisTDigest);
+  status = batch->PutLogData(log_data.Encode());
+  if (!status.ok()) {
+    return status;
+  }
 
+  // metadata.compression = 0;
+  // metadata.capacity = 0;
+  metadata.unmerged_nodes = 0;
+  metadata.merged_nodes = 0;
+  metadata.total_weight = 0;
+  metadata.merged_weight = 0;
+  metadata.minimum = std::numeric_limits<double>::max();
+  metadata.maximum = std::numeric_limits<double>::lowest();
+  metadata.total_observations = 0;
+  metadata.merge_times = 0;
+
+  std::string metadata_bytes;
+  metadata.Encode(&metadata_bytes);
+
+  status = batch->Put(metadata_cf_handle_, ns_key, metadata_bytes);
+  if (!status.ok()) {
+    return status;
+  }
+

Review Comment:
   ```suggestion
   
     auto start_key = internalSegmentGuardPrefixKey(metadata, ns_key, 
SegmentType::kBuffer);
     auto guard_key = internalSegmentGuardPrefixKey(metadata, ns_key, 
SegmentType::kGuardFlag);
     status = batch->DeleteRange(cf_handle_, start_key, guard_key);
     if (!status.ok()) {
       return status;
    }
   ```
   
   Hi @SharonIV0x86 ,
   
   It will be better to delete buffer and centroid keys. 😊
   The [`DeleteRange`](https://github.com/facebook/rocksdb/wiki/DeleteRange) 
action is the one mentioned like `deletebyprefix`. It's a lightweight action 
and just add tombstones for keys. This will make rocksdb cleanup current data 
in future compaction.
   
   Best Regards,
   Edward



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