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


##########
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:
   Right! I wanted to do something exactly like that, but i was just no getting 
the idea how to do so. Thanks so much for this review, ill add this.



##########
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:
   Will do it, i was just waiting for the review, also earlier i was also 
modifying the **compression** rate and **capacity**, but i realized that they 
should not be changed in a reset as they are being set by user when creating a 
tdigest.
   
   
https://github.com/apache/kvrocks/blob/b8db0e75553ccf6e02cde66c382d86a7d7ec5570/src/types/redis_tdigest.cc#L121
   
   



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