Skip to content

Commit c6699c8

Browse files
committed
Remove useless Scalerk0 and add necessary comments.
1 parent f1c736d commit c6699c8

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/types/redis_tdigest.cc

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
namespace redis {
4848

49-
// It should be replaced by a iteration of the rocksdb iterator
49+
// TODO: It should be replaced by a iteration of the rocksdb iterator
5050
class DummyCentroids {
5151
public:
5252
DummyCentroids(const TDigestMetadata& meta_data, const std::vector<Centroid>& centroids)
@@ -68,6 +68,9 @@ class DummyCentroids {
6868
}
6969
return iter_ != centroids_.cend();
7070
}
71+
72+
// The Prev function can only be called for item is not cend,
73+
// because we must gurantee the iterator to be inside the valid range before iteration.
7174
bool Prev() {
7275
if (Valid() && iter_ != centroids_.cbegin()) {
7376
std::advance(iter_, -1);
@@ -306,13 +309,25 @@ rocksdb::Status TDigest::decodeCentroidFromKeyValue(const rocksdb::Slice& key, c
306309
InternalKey ikey(key, storage_->IsSlotIdEncoded());
307310
auto subkey = ikey.GetSubKey();
308311
auto type_flg = static_cast<uint8_t>(SegmentType::kGuardFlag);
309-
GetFixed8(&subkey, &type_flg);
312+
if (!GetFixed8(&subkey, &type_flg)) {
313+
LOG(ERROR) << "corrupted tdigest centroid key, extract type failed";
314+
return rocksdb::Status::Corruption("corrupted tdigest centroid key");
315+
}
310316
if (static_cast<SegmentType>(type_flg) != SegmentType::kCentroids) {
311-
return rocksdb::Status::Corruption(fmt::format("corrupted tdigest centroid key type: {}", type_flg));
317+
LOG(ERROR) << "corrupted tdigest centroid key type: " << type_flg << ", expect to be "
318+
<< static_cast<uint8_t>(SegmentType::kCentroids);
319+
return rocksdb::Status::Corruption("corrupted tdigest centroid key type");
320+
}
321+
if (!GetDouble(&subkey, &centroid->mean)) {
322+
LOG(ERROR) << "corrupted tdigest centroid key, extract mean failed";
323+
return rocksdb::Status::Corruption("corrupted tdigest centroid key");
324+
}
325+
326+
if (rocksdb::Slice value_slice = value; // GetDouble needs a mutable pointer of slice
327+
!GetDouble(&value_slice, &centroid->weight)) {
328+
LOG(ERROR) << "corrupted tdigest centroid value, extract weight failed";
329+
return rocksdb::Status::Corruption("corrupted tdigest centroid value");
312330
}
313-
GetDouble(&subkey, &centroid->mean);
314-
rocksdb::Slice value_slice = value; // GetDouble needs a mutable pointer of slice
315-
GetDouble(&value_slice, &centroid->weight);
316331
return rocksdb::Status::OK();
317332
}
318333

src/types/tdigest.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ refer to https://github.com/apache/arrow/blob/27bbd593625122a4a25d9471c8aaf5df54
3535
#include "common/status.h"
3636

3737
namespace {
38-
// scale function K0: linear function, as baseline
39-
struct ScalerK0 {
40-
explicit ScalerK0(uint32_t delta) : delta_norm(delta / 2.0) {}
41-
42-
double K(double q) const { return delta_norm * q; }
43-
double Q(double k) const { return k / delta_norm; }
44-
45-
const double delta_norm;
46-
};
47-
4838
// scale function K1
4939
struct ScalerK1 {
5040
explicit ScalerK1(uint32_t delta) : delta_norm(delta / (2.0 * M_PI)) {}

0 commit comments

Comments
 (0)