@@ -118,31 +118,6 @@ DEFINE_int32(priority_thread_pool_size, -1,
118
118
" If -1 and max_background_compactions is specified - use max_background_compactions. "
119
119
" If -1 and max_background_compactions is not specified - use sqrt(num_cpus)." );
120
120
121
- namespace {
122
- constexpr int kDbCacheSizeUsePercentage = -1 ;
123
- constexpr int kDbCacheSizeCacheDisabled = -2 ;
124
- constexpr int kDbCacheSizeUseDefault = -3 ;
125
- }
126
-
127
- DEFINE_bool (enable_block_based_table_cache_gc, false ,
128
- " Set to true to enable block based table garbage collector." );
129
-
130
- DEFINE_int64 (db_block_cache_size_bytes, kDbCacheSizeUsePercentage ,
131
- " Size of RocksDB block cache (in bytes). "
132
- " This defaults to -1 for system auto-generated default, which would use "
133
- " FLAGS_db_block_cache_size_percentage to select a percentage of the total "
134
- " memory as the default size for the shared block cache. Value of -2 disables "
135
- " block cache." );
136
-
137
- DEFINE_int32 (db_block_cache_size_percentage, kDbCacheSizeUseDefault ,
138
- " Default percentage of total available memory to use as block cache size, if not "
139
- " asking for a raw number, through FLAGS_db_block_cache_size_bytes. "
140
- " Defaults to -3 (use default percentage as defined by master or tserver)." );
141
-
142
- DEFINE_int32 (db_block_cache_num_shard_bits, 4 ,
143
- " Number of bits to use for sharding the block cache (defaults to 4 bits)" );
144
- TAG_FLAG (db_block_cache_num_shard_bits, advanced);
145
-
146
121
using std::shared_ptr;
147
122
using std::string;
148
123
using std::unique_ptr;
@@ -743,77 +718,5 @@ Status ForceRocksDBCompact(rocksdb::DB* db) {
743
718
return Status::OK ();
744
719
}
745
720
746
- namespace {
747
-
748
- class LRUCacheGC : public GarbageCollector {
749
- public:
750
- explicit LRUCacheGC (std::shared_ptr<rocksdb::Cache> cache) : cache_(std::move(cache)) {}
751
-
752
- void CollectGarbage (size_t required) {
753
- if (!FLAGS_enable_block_based_table_cache_gc) {
754
- return ;
755
- }
756
-
757
- auto evicted = cache_->Evict (required);
758
- LOG (INFO) << " Evicted from table cache: " << HumanReadableNumBytes::ToString (evicted)
759
- << " , new usage: " << HumanReadableNumBytes::ToString (cache_->GetUsage ())
760
- << " , required: " << HumanReadableNumBytes::ToString (required);
761
- }
762
-
763
- virtual ~LRUCacheGC () = default ;
764
-
765
- private:
766
- std::shared_ptr<rocksdb::Cache> cache_;
767
- };
768
-
769
- int64_t GetTargetBlockCacheSize (const int32_t default_block_cache_size_percentage) {
770
- int32_t target_block_cache_size_percentage =
771
- (FLAGS_db_block_cache_size_percentage == kDbCacheSizeUseDefault ) ?
772
- default_block_cache_size_percentage : FLAGS_db_block_cache_size_percentage;
773
-
774
- int64_t target_block_cache_size_bytes = FLAGS_db_block_cache_size_bytes;
775
- // Auto-compute size of block cache if asked to.
776
- if (target_block_cache_size_bytes == kDbCacheSizeUsePercentage ) {
777
- // Check some bounds.
778
- CHECK (target_block_cache_size_percentage > 0 && target_block_cache_size_percentage <= 100 )
779
- << Substitute (
780
- " Flag tablet_block_cache_size_percentage must be between 0 and 100. Current value: "
781
- " $0" ,
782
- target_block_cache_size_percentage);
783
-
784
- const int64_t total_ram_avail = MemTracker::GetRootTracker ()->limit ();
785
- target_block_cache_size_bytes = total_ram_avail * target_block_cache_size_percentage / 100 ;
786
- }
787
- return target_block_cache_size_bytes;
788
- }
789
-
790
- } // namespace
791
-
792
- std::shared_ptr<MemTracker> InitBlockCacheMemTracker (
793
- const int32_t default_block_cache_size_percentage,
794
- const std::shared_ptr<MemTracker>& mem_tracker) {
795
- int64_t block_cache_size_bytes = GetTargetBlockCacheSize (default_block_cache_size_percentage);
796
-
797
- return MemTracker::FindOrCreateTracker (block_cache_size_bytes, " BlockBasedTable" , mem_tracker);
798
- }
799
-
800
- std::shared_ptr<GarbageCollector> InitBlockCache (
801
- const scoped_refptr<MetricEntity>& metrics,
802
- const int32_t default_block_cache_size_percentage,
803
- MemTracker* block_based_table_mem_tracker,
804
- tablet::TabletOptions* options) {
805
- std::shared_ptr<GarbageCollector> block_based_table_gc;
806
- int64_t block_cache_size_bytes = GetTargetBlockCacheSize (default_block_cache_size_percentage);
807
-
808
- if (block_cache_size_bytes != kDbCacheSizeCacheDisabled ) {
809
- options->block_cache = rocksdb::NewLRUCache (block_cache_size_bytes,
810
- FLAGS_db_block_cache_num_shard_bits);
811
- options->block_cache ->SetMetrics (metrics);
812
- block_based_table_gc = std::make_shared<LRUCacheGC>(options->block_cache );
813
- block_based_table_mem_tracker->AddGarbageCollector (block_based_table_gc);
814
- }
815
- return block_based_table_gc;
816
- }
817
-
818
721
} // namespace docdb
819
722
} // namespace yb
0 commit comments