46
46
47
47
namespace redis {
48
48
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
50
50
class DummyCentroids {
51
51
public:
52
52
DummyCentroids (const TDigestMetadata& meta_data, const std::vector<Centroid>& centroids)
@@ -68,6 +68,9 @@ class DummyCentroids {
68
68
}
69
69
return iter_ != centroids_.cend ();
70
70
}
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.
71
74
bool Prev () {
72
75
if (Valid () && iter_ != centroids_.cbegin ()) {
73
76
std::advance (iter_, -1 );
@@ -306,13 +309,25 @@ rocksdb::Status TDigest::decodeCentroidFromKeyValue(const rocksdb::Slice& key, c
306
309
InternalKey ikey (key, storage_->IsSlotIdEncoded ());
307
310
auto subkey = ikey.GetSubKey ();
308
311
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
+ }
310
316
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, ¢roid->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, ¢roid->weight )) {
328
+ LOG (ERROR) << " corrupted tdigest centroid value, extract weight failed" ;
329
+ return rocksdb::Status::Corruption (" corrupted tdigest centroid value" );
312
330
}
313
- GetDouble (&subkey, ¢roid->mean );
314
- rocksdb::Slice value_slice = value; // GetDouble needs a mutable pointer of slice
315
- GetDouble (&value_slice, ¢roid->weight );
316
331
return rocksdb::Status::OK ();
317
332
}
318
333
0 commit comments