From ad79fd83c17f2e2dac2012a18054b3126c90e318 Mon Sep 17 00:00:00 2001 From: heyuchen Date: Mon, 22 Mar 2021 18:07:48 +0800 Subject: [PATCH] fix by cr --- src/base/pegasus_const.cpp | 2 +- src/server/key_ttl_compaction_filter.h | 18 ++++++++++-------- src/server/pegasus_server_impl.cpp | 8 ++++---- src/server/pegasus_server_impl.h | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/base/pegasus_const.cpp b/src/base/pegasus_const.cpp index 07e0187bf0..da529b8485 100644 --- a/src/base/pegasus_const.cpp +++ b/src/base/pegasus_const.cpp @@ -89,6 +89,6 @@ const std::string ROCKSDB_ENV_SLOW_QUERY_THRESHOLD("replica.slow_query_threshold const std::string ROCKSDB_ITERATION_THRESHOLD_TIME_MS("replica.rocksdb_iteration_threshold_time_ms"); -/// true means compaction and scan will check partition_hash, otherwise false +/// true means compaction and scan will validate partition_hash, otherwise false const std::string SPLIT_VALIDATE_PARTITION_HASH("replica.split.validate_partition_hash"); } // namespace pegasus diff --git a/src/server/key_ttl_compaction_filter.h b/src/server/key_ttl_compaction_filter.h index 234d26e10f..4f26844411 100644 --- a/src/server/key_ttl_compaction_filter.h +++ b/src/server/key_ttl_compaction_filter.h @@ -39,13 +39,13 @@ class KeyWithTTLCompactionFilter : public rocksdb::CompactionFilter bool enabled, int32_t pidx, int32_t partition_version, - bool check_hash) + bool validate_hash) : _pegasus_data_version(pegasus_data_version), _default_ttl(default_ttl), _enabled(enabled), _partition_index(pidx), _partition_version(partition_version), - _check_partition_hash(check_hash) + _validate_partition_hash(validate_hash) { } @@ -74,9 +74,11 @@ class KeyWithTTLCompactionFilter : public rocksdb::CompactionFilter const char *Name() const override { return "KeyWithTTLCompactionFilter"; } + // Check if the record is stale after partition split, which will split the partition into two + // halves. The stale record belongs to the other half. bool check_if_stale_split_data(const rocksdb::Slice &key) const { - if (!_check_partition_hash || key.size() < 2 || _partition_version < 0 || + if (!_validate_partition_hash || key.size() < 2 || _partition_version < 0 || _partition_index > _partition_version) { return false; } @@ -90,7 +92,7 @@ class KeyWithTTLCompactionFilter : public rocksdb::CompactionFilter mutable pegasus_value_generator _gen; int32_t _partition_index; int32_t _partition_version; - bool _check_partition_hash; + bool _validate_partition_hash; }; class KeyWithTTLCompactionFilterFactory : public rocksdb::CompactionFilterFactory @@ -108,7 +110,7 @@ class KeyWithTTLCompactionFilterFactory : public rocksdb::CompactionFilterFactor _enabled.load(), _partition_index.load(), _partition_version.load(), - _check_partition_hash.load())); + _validate_partition_hash.load())); } const char *Name() const override { return "KeyWithTTLCompactionFilterFactory"; } @@ -118,9 +120,9 @@ class KeyWithTTLCompactionFilterFactory : public rocksdb::CompactionFilterFactor } void EnableFilter() { _enabled.store(true, std::memory_order_release); } void SetDefaultTTL(uint32_t ttl) { _default_ttl.store(ttl, std::memory_order_release); } - void SetCheckPartitionHash(bool check_hash) + void SetValidatePartitionHash(bool validate_hash) { - _check_partition_hash.store(check_hash, std::memory_order_release); + _validate_partition_hash.store(validate_hash, std::memory_order_release); } void SetPartitionIndex(int32_t pidx) { @@ -137,7 +139,7 @@ class KeyWithTTLCompactionFilterFactory : public rocksdb::CompactionFilterFactor std::atomic_bool _enabled; // only process filtering when _enabled == true std::atomic _partition_index{0}; std::atomic _partition_version{-1}; - std::atomic_bool _check_partition_hash{false}; + std::atomic_bool _validate_partition_hash{false}; }; } // namespace server diff --git a/src/server/pegasus_server_impl.cpp b/src/server/pegasus_server_impl.cpp index f0e2d80164..7816bcda2c 100644 --- a/src/server/pegasus_server_impl.cpp +++ b/src/server/pegasus_server_impl.cpp @@ -2453,11 +2453,11 @@ void pegasus_server_impl::update_validate_partition_hash( return; } } - if (new_value != _check_partition_hash) { + if (new_value != _validate_partition_hash) { ddebug_replica( - "update '_check_partition_hash' from {} to {}", _check_partition_hash, new_value); - _check_partition_hash = new_value; - _key_ttl_compaction_filter_factory->SetCheckPartitionHash(_check_partition_hash); + "update '_validate_partition_hash' from {} to {}", _validate_partition_hash, new_value); + _validate_partition_hash = new_value; + _key_ttl_compaction_filter_factory->SetValidatePartitionHash(_validate_partition_hash); } } diff --git a/src/server/pegasus_server_impl.h b/src/server/pegasus_server_impl.h index a67937a78f..2b314c3916 100644 --- a/src/server/pegasus_server_impl.h +++ b/src/server/pegasus_server_impl.h @@ -404,7 +404,7 @@ class pegasus_server_impl : public pegasus_read_service pegasus_manual_compact_service _manual_compact_svc; std::atomic _partition_version; - bool _check_partition_hash{false}; + bool _validate_partition_hash{false}; dsn::replication::ingestion_status::type _ingestion_status{ dsn::replication::ingestion_status::IS_INVALID};