@@ -1278,12 +1278,6 @@ class DelayFilterFactory : public CompactionFilterFactory {
12781278};
12791279} // anonymous namespace
12801280
1281- static std::string CompressibleString (Random* rnd, int len) {
1282- std::string r;
1283- test::CompressibleString (rnd, 0.8 , len, &r);
1284- return r;
1285- }
1286-
12871281TEST_F (DBTest, FailMoreDbPaths) {
12881282 Options options = CurrentOptions ();
12891283 options.db_paths .emplace_back (dbname_, 10000000 );
@@ -5407,271 +5401,6 @@ TEST_F(DBTest, FlushOnDestroy) {
54075401 CancelAllBackgroundWork (db_);
54085402}
54095403
5410- TEST_F (DBTest, DynamicLevelCompressionPerLevel) {
5411- if (!Snappy_Supported ()) {
5412- return ;
5413- }
5414- const int kNKeys = 120 ;
5415- int keys[kNKeys ];
5416- for (int i = 0 ; i < kNKeys ; i++) {
5417- keys[i] = i;
5418- }
5419-
5420- Random rnd (301 );
5421- Options options;
5422- options.env = env_;
5423- options.create_if_missing = true ;
5424- options.db_write_buffer_size = 20480 ;
5425- options.write_buffer_size = 20480 ;
5426- options.max_write_buffer_number = 2 ;
5427- options.level0_file_num_compaction_trigger = 2 ;
5428- options.level0_slowdown_writes_trigger = 2 ;
5429- options.level0_stop_writes_trigger = 2 ;
5430- options.target_file_size_base = 20480 ;
5431- options.level_compaction_dynamic_level_bytes = true ;
5432- options.max_bytes_for_level_base = 102400 ;
5433- options.max_bytes_for_level_multiplier = 4 ;
5434- options.max_background_compactions = 1 ;
5435- options.num_levels = 5 ;
5436- options.statistics = CreateDBStatistics ();
5437-
5438- options.compression_per_level .resize (3 );
5439- // No compression for L0
5440- options.compression_per_level [0 ] = kNoCompression ;
5441- // No compression for the Ln whre L0 is compacted to
5442- options.compression_per_level [1 ] = kNoCompression ;
5443- // Snappy compression for Ln+1
5444- options.compression_per_level [2 ] = kSnappyCompression ;
5445-
5446- OnFileDeletionListener* listener = new OnFileDeletionListener ();
5447- options.listeners .emplace_back (listener);
5448-
5449- DestroyAndReopen (options);
5450-
5451- // Insert more than 80K. L4 should be base level. Neither L0 nor L4 should
5452- // be compressed, so there shouldn't be any compression.
5453- for (int i = 0 ; i < 20 ; i++) {
5454- ASSERT_OK (Put (Key (keys[i]), CompressibleString (&rnd, 4000 )));
5455- ASSERT_OK (dbfull ()->TEST_WaitForBackgroundWork ());
5456- }
5457- ASSERT_OK (Flush ());
5458- ASSERT_OK (dbfull ()->TEST_WaitForCompact ());
5459-
5460- ASSERT_EQ (NumTableFilesAtLevel (1 ), 0 );
5461- ASSERT_EQ (NumTableFilesAtLevel (2 ), 0 );
5462- ASSERT_EQ (NumTableFilesAtLevel (3 ), 0 );
5463- ASSERT_TRUE (NumTableFilesAtLevel (0 ) > 0 || NumTableFilesAtLevel (4 ) > 0 );
5464-
5465- // Verify there was no compression
5466- auto num_block_compressed =
5467- options.statistics ->getTickerCount (NUMBER_BLOCK_COMPRESSED );
5468- ASSERT_EQ (num_block_compressed, 0 );
5469-
5470- // Insert 400KB and there will be some files end up in L3. According to the
5471- // above compression settings for each level, there will be some compression.
5472- ASSERT_OK (options.statistics ->Reset ());
5473- ASSERT_EQ (num_block_compressed, 0 );
5474- for (int i = 20 ; i < 120 ; i++) {
5475- ASSERT_OK (Put (Key (keys[i]), CompressibleString (&rnd, 4000 )));
5476- ASSERT_OK (dbfull ()->TEST_WaitForBackgroundWork ());
5477- }
5478- ASSERT_OK (Flush ());
5479- ASSERT_OK (dbfull ()->TEST_WaitForCompact ());
5480- ASSERT_EQ (NumTableFilesAtLevel (1 ), 0 );
5481- ASSERT_EQ (NumTableFilesAtLevel (2 ), 0 );
5482- ASSERT_GE (NumTableFilesAtLevel (3 ), 1 );
5483- ASSERT_GE (NumTableFilesAtLevel (4 ), 1 );
5484-
5485- // Verify there was compression
5486- num_block_compressed =
5487- options.statistics ->getTickerCount (NUMBER_BLOCK_COMPRESSED );
5488- ASSERT_GT (num_block_compressed, 0 );
5489-
5490- // Make sure data in files in L3 is not compacted by removing all files
5491- // in L4 and calculate number of rows
5492- ASSERT_OK (dbfull ()->SetOptions ({
5493- {" disable_auto_compactions" , " true" },
5494- }));
5495- ColumnFamilyMetaData cf_meta;
5496- db_->GetColumnFamilyMetaData (&cf_meta);
5497-
5498- // Ensure that L1+ files are non-overlapping and together with L0 encompass
5499- // full key range between smallestkey and largestkey from CF file metadata.
5500- int largestkey_in_prev_level = -1 ;
5501- int keys_found = 0 ;
5502- for (int level = (int )cf_meta.levels .size () - 1 ; level >= 0 ; level--) {
5503- int files_in_level = (int )cf_meta.levels [level].files .size ();
5504- int largestkey_in_prev_file = -1 ;
5505- for (int j = 0 ; j < files_in_level; j++) {
5506- int smallestkey = IdFromKey (cf_meta.levels [level].files [j].smallestkey );
5507- int largestkey = IdFromKey (cf_meta.levels [level].files [j].largestkey );
5508- int num_entries = (int )cf_meta.levels [level].files [j].num_entries ;
5509- ASSERT_EQ (num_entries, largestkey - smallestkey + 1 );
5510- keys_found += num_entries;
5511- if (level > 0 ) {
5512- if (j == 0 ) {
5513- ASSERT_GT (smallestkey, largestkey_in_prev_level);
5514- }
5515- if (j > 0 ) {
5516- ASSERT_GT (smallestkey, largestkey_in_prev_file);
5517- }
5518- if (j == files_in_level - 1 ) {
5519- largestkey_in_prev_level = largestkey;
5520- }
5521- }
5522- largestkey_in_prev_file = largestkey;
5523- }
5524- }
5525- ASSERT_EQ (keys_found, kNKeys );
5526-
5527- for (const auto & file : cf_meta.levels [4 ].files ) {
5528- listener->SetExpectedFileName (dbname_ + file.name );
5529- const RangeOpt ranges (file.smallestkey , file.largestkey );
5530- // Given verification from above, we're guaranteed that by deleting all the
5531- // files in [<smallestkey>, <largestkey>] range, we're effectively deleting
5532- // that very single file and nothing more.
5533- EXPECT_OK (dbfull ()->DeleteFilesInRanges (dbfull ()->DefaultColumnFamily (),
5534- &ranges, true /* include_end */ ));
5535- }
5536- listener->VerifyMatchedCount (cf_meta.levels [4 ].files .size ());
5537-
5538- int num_keys = 0 ;
5539- std::unique_ptr<Iterator> iter (db_->NewIterator (ReadOptions ()));
5540- for (iter->SeekToFirst (); iter->Valid (); iter->Next ()) {
5541- num_keys++;
5542- }
5543- ASSERT_OK (iter->status ());
5544-
5545- ASSERT_EQ (NumTableFilesAtLevel (1 ), 0 );
5546- ASSERT_EQ (NumTableFilesAtLevel (2 ), 0 );
5547- ASSERT_GE (NumTableFilesAtLevel (3 ), 1 );
5548- ASSERT_EQ (NumTableFilesAtLevel (4 ), 0 );
5549-
5550- ASSERT_GT (SizeAtLevel (0 ) + SizeAtLevel (3 ), num_keys * 4000U + num_keys * 10U );
5551- }
5552-
5553- TEST_F (DBTest, DynamicLevelCompressionPerLevel2) {
5554- if (!Snappy_Supported () || !LZ4_Supported () || !Zlib_Supported ()) {
5555- return ;
5556- }
5557- const int kNKeys = 500 ;
5558- int keys[kNKeys ];
5559- for (int i = 0 ; i < kNKeys ; i++) {
5560- keys[i] = i;
5561- }
5562- RandomShuffle (std::begin (keys), std::end (keys));
5563-
5564- Random rnd (301 );
5565- Options options;
5566- options.create_if_missing = true ;
5567- options.db_write_buffer_size = 6000000 ;
5568- options.write_buffer_size = 600000 ;
5569- options.max_write_buffer_number = 2 ;
5570- options.level0_file_num_compaction_trigger = 2 ;
5571- options.level0_slowdown_writes_trigger = 2 ;
5572- options.level0_stop_writes_trigger = 2 ;
5573- options.soft_pending_compaction_bytes_limit = 1024 * 1024 ;
5574- options.target_file_size_base = 20 ;
5575- options.env = env_;
5576- options.level_compaction_dynamic_level_bytes = true ;
5577- options.max_bytes_for_level_base = 200 ;
5578- options.max_bytes_for_level_multiplier = 8 ;
5579- options.max_background_compactions = 1 ;
5580- options.num_levels = 5 ;
5581- std::shared_ptr<mock::MockTableFactory> mtf (new mock::MockTableFactory);
5582- options.table_factory = mtf;
5583-
5584- options.compression_per_level .resize (3 );
5585- options.compression_per_level [0 ] = kNoCompression ;
5586- options.compression_per_level [1 ] = kLZ4Compression ;
5587- options.compression_per_level [2 ] = kZlibCompression ;
5588-
5589- DestroyAndReopen (options);
5590- // When base level is L4, L4 is LZ4.
5591- std::atomic<int > num_zlib (0 );
5592- std::atomic<int > num_lz4 (0 );
5593- std::atomic<int > num_no (0 );
5594- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->SetCallBack (
5595- " LevelCompactionPicker::PickCompaction:Return" , [&](void * arg) {
5596- Compaction* compaction = static_cast <Compaction*>(arg);
5597- if (compaction->output_level () == 4 ) {
5598- ASSERT_TRUE (compaction->output_compression () == kLZ4Compression );
5599- num_lz4.fetch_add (1 );
5600- }
5601- });
5602- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->SetCallBack (
5603- " FlushJob::WriteLevel0Table:output_compression" , [&](void * arg) {
5604- auto * compression = static_cast <CompressionType*>(arg);
5605- ASSERT_TRUE (*compression == kNoCompression );
5606- num_no.fetch_add (1 );
5607- });
5608- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->EnableProcessing ();
5609-
5610- for (int i = 0 ; i < 100 ; i++) {
5611- std::string value = rnd.RandomString (200 );
5612- ASSERT_OK (Put (Key (keys[i]), value));
5613- if (i % 25 == 24 ) {
5614- ASSERT_OK (Flush ());
5615- ASSERT_OK (dbfull ()->TEST_WaitForCompact ());
5616- }
5617- }
5618-
5619- ASSERT_OK (Flush ());
5620- ASSERT_OK (dbfull ()->TEST_WaitForFlushMemTable ());
5621- ASSERT_OK (dbfull ()->TEST_WaitForCompact ());
5622- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->DisableProcessing ();
5623- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->ClearAllCallBacks ();
5624-
5625- ASSERT_EQ (NumTableFilesAtLevel (1 ), 0 );
5626- ASSERT_EQ (NumTableFilesAtLevel (2 ), 0 );
5627- ASSERT_EQ (NumTableFilesAtLevel (3 ), 0 );
5628- ASSERT_GT (NumTableFilesAtLevel (4 ), 0 );
5629- ASSERT_GT (num_no.load (), 2 );
5630- ASSERT_GT (num_lz4.load (), 0 );
5631- int prev_num_files_l4 = NumTableFilesAtLevel (4 );
5632-
5633- // After base level turn L4->L3, L3 becomes LZ4 and L4 becomes Zlib
5634- num_lz4.store (0 );
5635- num_no.store (0 );
5636- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->SetCallBack (
5637- " LevelCompactionPicker::PickCompaction:Return" , [&](void * arg) {
5638- Compaction* compaction = static_cast <Compaction*>(arg);
5639- if (compaction->output_level () == 4 && compaction->start_level () == 3 ) {
5640- ASSERT_TRUE (compaction->output_compression () == kZlibCompression );
5641- num_zlib.fetch_add (1 );
5642- } else {
5643- ASSERT_TRUE (compaction->output_compression () == kLZ4Compression );
5644- num_lz4.fetch_add (1 );
5645- }
5646- });
5647- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->SetCallBack (
5648- " FlushJob::WriteLevel0Table:output_compression" , [&](void * arg) {
5649- auto * compression = static_cast <CompressionType*>(arg);
5650- ASSERT_TRUE (*compression == kNoCompression );
5651- num_no.fetch_add (1 );
5652- });
5653- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->EnableProcessing ();
5654-
5655- for (int i = 101 ; i < 500 ; i++) {
5656- std::string value = rnd.RandomString (200 );
5657- ASSERT_OK (Put (Key (keys[i]), value));
5658- if (i % 100 == 99 ) {
5659- ASSERT_OK (Flush ());
5660- ASSERT_OK (dbfull ()->TEST_WaitForCompact ());
5661- }
5662- }
5663-
5664- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->ClearAllCallBacks ();
5665- ROCKSDB_NAMESPACE::SyncPoint::GetInstance ()->DisableProcessing ();
5666- ASSERT_EQ (NumTableFilesAtLevel (1 ), 0 );
5667- ASSERT_EQ (NumTableFilesAtLevel (2 ), 0 );
5668- ASSERT_GT (NumTableFilesAtLevel (3 ), 0 );
5669- ASSERT_GT (NumTableFilesAtLevel (4 ), prev_num_files_l4);
5670- ASSERT_GT (num_no.load (), 2 );
5671- ASSERT_GT (num_lz4.load (), 0 );
5672- ASSERT_GT (num_zlib.load (), 0 );
5673- }
5674-
56755404TEST_F (DBTest, DynamicCompactionOptions) {
56765405 // minimum write buffer size is enforced at 64KB
56775406 const uint64_t k32KB = 1 << 15 ;
@@ -7349,27 +7078,6 @@ TEST_F(DBTest, LastWriteBufferDelay) {
73497078}
73507079#endif // !defined(ROCKSDB_DISABLE_STALL_NOTIFICATION)
73517080
7352- TEST_F (DBTest, FailWhenCompressionNotSupportedTest) {
7353- CompressionType compressions[] = {kZlibCompression , kBZip2Compression ,
7354- kLZ4Compression , kLZ4HCCompression ,
7355- kXpressCompression };
7356- for (auto comp : compressions) {
7357- if (!CompressionTypeSupported (comp)) {
7358- // not supported, we should fail the Open()
7359- Options options = CurrentOptions ();
7360- options.compression = comp;
7361- ASSERT_TRUE (!TryReopen (options).ok ());
7362- // Try if CreateColumnFamily also fails
7363- options.compression = kNoCompression ;
7364- ASSERT_OK (TryReopen (options));
7365- ColumnFamilyOptions cf_options (options);
7366- cf_options.compression = comp;
7367- ColumnFamilyHandle* handle;
7368- ASSERT_TRUE (!db_->CreateColumnFamily (cf_options, " name" , &handle).ok ());
7369- }
7370- }
7371- }
7372-
73737081TEST_F (DBTest, CreateColumnFamilyShouldFailOnIncompatibleOptions) {
73747082 Options options = CurrentOptions ();
73757083 options.max_open_files = 100 ;
0 commit comments