@@ -135,57 +135,6 @@ class DeleteFileTest : public DBTestBase {
135
135
}
136
136
};
137
137
138
- TEST_F (DeleteFileTest, AddKeysAndQueryLevels) {
139
- Options options = CurrentOptions ();
140
- SetOptions (&options);
141
- Destroy (options);
142
- options.create_if_missing = true ;
143
- Reopen (options);
144
-
145
- CreateTwoLevels ();
146
- std::vector<LiveFileMetaData> metadata;
147
- db_->GetLiveFilesMetaData (&metadata);
148
-
149
- std::string level1file;
150
- int level1keycount = 0 ;
151
- std::string level2file;
152
- int level2keycount = 0 ;
153
- int level1index = 0 ;
154
- int level2index = 1 ;
155
-
156
- ASSERT_EQ ((int )metadata.size (), 2 );
157
- if (metadata[0 ].level == 2 ) {
158
- level1index = 1 ;
159
- level2index = 0 ;
160
- }
161
-
162
- level1file = metadata[level1index].name ;
163
- int startkey = atoi (metadata[level1index].smallestkey .c_str ());
164
- int endkey = atoi (metadata[level1index].largestkey .c_str ());
165
- level1keycount = (endkey - startkey + 1 );
166
- level2file = metadata[level2index].name ;
167
- startkey = atoi (metadata[level2index].smallestkey .c_str ());
168
- endkey = atoi (metadata[level2index].largestkey .c_str ());
169
- level2keycount = (endkey - startkey + 1 );
170
-
171
- // COntrolled setup. Levels 1 and 2 should both have 50K files.
172
- // This is a little fragile as it depends on the current
173
- // compaction heuristics.
174
- ASSERT_EQ (level1keycount, 50000 );
175
- ASSERT_EQ (level2keycount, 50000 );
176
-
177
- Status status = db_->DEPRECATED_DeleteFile (" 0.sst" );
178
- ASSERT_TRUE (status.IsInvalidArgument ());
179
-
180
- // intermediate level files cannot be deleted.
181
- status = db_->DEPRECATED_DeleteFile (level1file);
182
- ASSERT_TRUE (status.IsInvalidArgument ());
183
-
184
- // Lowest level file deletion should succeed.
185
- status = db_->DEPRECATED_DeleteFile (level2file);
186
- ASSERT_OK (status);
187
- }
188
-
189
138
TEST_F (DeleteFileTest, PurgeObsoleteFilesTest) {
190
139
Options options = CurrentOptions ();
191
140
SetOptions (&options);
@@ -496,145 +445,6 @@ TEST_F(DeleteFileTest, BackgroundPurgeTestMultipleJobs) {
496
445
CheckFileTypeCounts (dbname_, 0 , 1 , 1 );
497
446
}
498
447
499
- TEST_F (DeleteFileTest, DeleteFileWithIterator) {
500
- Options options = CurrentOptions ();
501
- SetOptions (&options);
502
- Destroy (options);
503
- options.create_if_missing = true ;
504
- Reopen (options);
505
-
506
- CreateTwoLevels ();
507
- ReadOptions read_options;
508
- Iterator* it = db_->NewIterator (read_options);
509
- ASSERT_OK (it->status ());
510
- std::vector<LiveFileMetaData> metadata;
511
- db_->GetLiveFilesMetaData (&metadata);
512
-
513
- std::string level2file;
514
-
515
- ASSERT_EQ (metadata.size (), static_cast <size_t >(2 ));
516
- if (metadata[0 ].level == 1 ) {
517
- level2file = metadata[1 ].name ;
518
- } else {
519
- level2file = metadata[0 ].name ;
520
- }
521
-
522
- Status status = db_->DEPRECATED_DeleteFile (level2file);
523
- fprintf (stdout, " Deletion status %s: %s\n " , level2file.c_str (),
524
- status.ToString ().c_str ());
525
- ASSERT_OK (status);
526
- it->SeekToFirst ();
527
- int numKeysIterated = 0 ;
528
- while (it->Valid ()) {
529
- numKeysIterated++;
530
- it->Next ();
531
- }
532
- ASSERT_EQ (numKeysIterated, 50000 );
533
- delete it;
534
- }
535
-
536
- TEST_F (DeleteFileTest, DeleteLogFiles) {
537
- Options options = CurrentOptions ();
538
- SetOptions (&options);
539
- Destroy (options);
540
- options.create_if_missing = true ;
541
- Reopen (options);
542
-
543
- AddKeys (10 , 0 );
544
- VectorLogPtr logfiles;
545
- ASSERT_OK (db_->GetSortedWalFiles (logfiles));
546
- ASSERT_GT (logfiles.size (), 0UL );
547
- // Take the last log file which is expected to be alive and try to delete it
548
- // Should not succeed because live logs are not allowed to be deleted
549
- std::unique_ptr<LogFile> alive_log = std::move (logfiles.back ());
550
- ASSERT_EQ (alive_log->Type (), kAliveLogFile );
551
- ASSERT_OK (env_->FileExists (wal_dir_ + " /" + alive_log->PathName ()));
552
- fprintf (stdout, " Deleting alive log file %s\n " ,
553
- alive_log->PathName ().c_str ());
554
- ASSERT_NOK (db_->DEPRECATED_DeleteFile (alive_log->PathName ()));
555
- ASSERT_OK (env_->FileExists (wal_dir_ + " /" + alive_log->PathName ()));
556
- logfiles.clear ();
557
-
558
- // Call Flush to bring about a new working log file and add more keys
559
- // Call Flush again to flush out memtable and move alive log to archived log
560
- // and try to delete the archived log file
561
- FlushOptions fopts;
562
- ASSERT_OK (db_->Flush (fopts));
563
- AddKeys (10 , 0 );
564
- ASSERT_OK (db_->Flush (fopts));
565
- ASSERT_OK (db_->GetSortedWalFiles (logfiles));
566
- ASSERT_GT (logfiles.size (), 0UL );
567
- std::unique_ptr<LogFile> archived_log = std::move (logfiles.front ());
568
- ASSERT_EQ (archived_log->Type (), kArchivedLogFile );
569
- ASSERT_OK (env_->FileExists (wal_dir_ + " /" + archived_log->PathName ()));
570
- fprintf (stdout, " Deleting archived log file %s\n " ,
571
- archived_log->PathName ().c_str ());
572
- ASSERT_OK (db_->DEPRECATED_DeleteFile (archived_log->PathName ()));
573
- ASSERT_TRUE (
574
- env_->FileExists (wal_dir_ + " /" + archived_log->PathName ()).IsNotFound ());
575
- }
576
-
577
- TEST_F (DeleteFileTest, DeleteNonDefaultColumnFamily) {
578
- Options options = CurrentOptions ();
579
- SetOptions (&options);
580
- Destroy (options);
581
- options.create_if_missing = true ;
582
- Reopen (options);
583
- CreateAndReopenWithCF ({" new_cf" }, options);
584
-
585
- Random rnd (5 );
586
- for (int i = 0 ; i < 1000 ; ++i) {
587
- ASSERT_OK (db_->Put (WriteOptions (), handles_[1 ], test::RandomKey (&rnd, 10 ),
588
- test::RandomKey (&rnd, 10 )));
589
- }
590
- ASSERT_OK (db_->Flush (FlushOptions (), handles_[1 ]));
591
- for (int i = 0 ; i < 1000 ; ++i) {
592
- ASSERT_OK (db_->Put (WriteOptions (), handles_[1 ], test::RandomKey (&rnd, 10 ),
593
- test::RandomKey (&rnd, 10 )));
594
- }
595
- ASSERT_OK (db_->Flush (FlushOptions (), handles_[1 ]));
596
-
597
- std::vector<LiveFileMetaData> metadata;
598
- db_->GetLiveFilesMetaData (&metadata);
599
- ASSERT_EQ (2U , metadata.size ());
600
- ASSERT_EQ (" new_cf" , metadata[0 ].column_family_name );
601
- ASSERT_EQ (" new_cf" , metadata[1 ].column_family_name );
602
- auto old_file = metadata[0 ].smallest_seqno < metadata[1 ].smallest_seqno
603
- ? metadata[0 ].name
604
- : metadata[1 ].name ;
605
- auto new_file = metadata[0 ].smallest_seqno > metadata[1 ].smallest_seqno
606
- ? metadata[0 ].name
607
- : metadata[1 ].name ;
608
- ASSERT_TRUE (db_->DEPRECATED_DeleteFile (new_file).IsInvalidArgument ());
609
- ASSERT_OK (db_->DEPRECATED_DeleteFile (old_file));
610
-
611
- {
612
- std::unique_ptr<Iterator> itr (db_->NewIterator (ReadOptions (), handles_[1 ]));
613
- ASSERT_OK (itr->status ());
614
- int count = 0 ;
615
- for (itr->SeekToFirst (); itr->Valid (); itr->Next ()) {
616
- ASSERT_OK (itr->status ());
617
- ++count;
618
- }
619
- ASSERT_OK (itr->status ());
620
- ASSERT_EQ (count, 1000 );
621
- }
622
-
623
- Close ();
624
- ReopenWithColumnFamilies ({kDefaultColumnFamilyName , " new_cf" }, options);
625
-
626
- {
627
- std::unique_ptr<Iterator> itr (db_->NewIterator (ReadOptions (), handles_[1 ]));
628
- int count = 0 ;
629
- for (itr->SeekToFirst (); itr->Valid (); itr->Next ()) {
630
- ASSERT_OK (itr->status ());
631
- ++count;
632
- }
633
- ASSERT_OK (itr->status ());
634
- ASSERT_EQ (count, 1000 );
635
- }
636
- }
637
-
638
448
} // namespace ROCKSDB_NAMESPACE
639
449
640
450
int main (int argc, char ** argv) {
0 commit comments