Skip to content

Commit 591f5b1

Browse files
mszeszko-metafacebook-github-bot
authored andcommitted
Remove deprecated DB::DeleteFile API references (#13322)
Summary: Cleanup post #13284. Pull Request resolved: #13322 Test Plan: 1. We did not find any evidence of breakage in internal pre-release integration pipeline runs after renaming the deprecated API in `9.10`. 2. _To the extent possible_, we manually validated partner use cases of file deletion and confirmed deprecated API is no longer in use. Reviewed By: jaykorean Differential Revision: D68476852 Pulled By: mszeszko-meta fbshipit-source-id: fbe1f873e16ae7c60d7706a3c44ecc695ab86a4b
1 parent ac6c671 commit 591f5b1

File tree

12 files changed

+46
-388
lines changed

12 files changed

+46
-388
lines changed

db/c.cc

-4
Original file line numberDiff line numberDiff line change
@@ -1858,10 +1858,6 @@ extern ROCKSDB_LIBRARY_API void rocksdb_approximate_sizes_cf_with_flags(
18581858
delete[] ranges;
18591859
}
18601860

1861-
void DEPRECATED_rocksdb_delete_file(rocksdb_t* db, const char* name) {
1862-
db->rep->DEPRECATED_DeleteFile(name);
1863-
}
1864-
18651861
const rocksdb_livefiles_t* rocksdb_livefiles(rocksdb_t* db) {
18661862
rocksdb_livefiles_t* result = new rocksdb_livefiles_t;
18671863
db->rep->GetLiveFilesMetaData(&result->rep);

db/db_impl/db_impl.cc

-102
Original file line numberDiff line numberDiff line change
@@ -4883,108 +4883,6 @@ Status DBImpl::GetUpdatesSince(
48834883
return wal_manager_.GetUpdatesSince(seq, iter, read_options, versions_.get());
48844884
}
48854885

4886-
Status DBImpl::DEPRECATED_DeleteFile(std::string name) {
4887-
// TODO: plumb Env::IOActivity, Env::IOPriority
4888-
const ReadOptions read_options;
4889-
const WriteOptions write_options;
4890-
4891-
uint64_t number;
4892-
FileType type;
4893-
WalFileType log_type;
4894-
if (!ParseFileName(name, &number, &type, &log_type) ||
4895-
(type != kTableFile && type != kWalFile)) {
4896-
ROCKS_LOG_ERROR(immutable_db_options_.info_log, "DeleteFile %s failed.\n",
4897-
name.c_str());
4898-
return Status::InvalidArgument("Invalid file name");
4899-
}
4900-
4901-
if (type == kWalFile) {
4902-
// Only allow deleting archived log files
4903-
if (log_type != kArchivedLogFile) {
4904-
ROCKS_LOG_ERROR(immutable_db_options_.info_log,
4905-
"DeleteFile %s failed - not archived log.\n",
4906-
name.c_str());
4907-
return Status::NotSupported("Delete only supported for archived logs");
4908-
}
4909-
Status status = wal_manager_.DeleteFile(name, number);
4910-
if (!status.ok()) {
4911-
ROCKS_LOG_ERROR(immutable_db_options_.info_log,
4912-
"DeleteFile %s failed -- %s.\n", name.c_str(),
4913-
status.ToString().c_str());
4914-
}
4915-
return status;
4916-
}
4917-
4918-
Status status;
4919-
int level;
4920-
FileMetaData* metadata;
4921-
ColumnFamilyData* cfd;
4922-
VersionEdit edit;
4923-
JobContext job_context(next_job_id_.fetch_add(1), true);
4924-
{
4925-
InstrumentedMutexLock l(&mutex_);
4926-
status = versions_->GetMetadataForFile(number, &level, &metadata, &cfd);
4927-
if (!status.ok()) {
4928-
ROCKS_LOG_WARN(immutable_db_options_.info_log,
4929-
"DeleteFile %s failed. File not found\n", name.c_str());
4930-
job_context.Clean();
4931-
return Status::InvalidArgument("File not found");
4932-
}
4933-
assert(level < cfd->NumberLevels());
4934-
4935-
// If the file is being compacted no need to delete.
4936-
if (metadata->being_compacted) {
4937-
ROCKS_LOG_INFO(immutable_db_options_.info_log,
4938-
"DeleteFile %s Skipped. File about to be compacted\n",
4939-
name.c_str());
4940-
job_context.Clean();
4941-
return Status::OK();
4942-
}
4943-
4944-
// Only the files in the last level can be deleted externally.
4945-
// This is to make sure that any deletion tombstones are not
4946-
// lost. Check that the level passed is the last level.
4947-
auto* vstoreage = cfd->current()->storage_info();
4948-
for (int i = level + 1; i < cfd->NumberLevels(); i++) {
4949-
if (vstoreage->NumLevelFiles(i) != 0) {
4950-
ROCKS_LOG_WARN(immutable_db_options_.info_log,
4951-
"DeleteFile %s FAILED. File not in last level\n",
4952-
name.c_str());
4953-
job_context.Clean();
4954-
return Status::InvalidArgument("File not in last level");
4955-
}
4956-
}
4957-
// if level == 0, it has to be the oldest file
4958-
if (level == 0 &&
4959-
vstoreage->LevelFiles(0).back()->fd.GetNumber() != number) {
4960-
ROCKS_LOG_WARN(immutable_db_options_.info_log,
4961-
"DeleteFile %s failed ---"
4962-
" target file in level 0 must be the oldest.",
4963-
name.c_str());
4964-
job_context.Clean();
4965-
return Status::InvalidArgument("File in level 0, but not oldest");
4966-
}
4967-
edit.SetColumnFamily(cfd->GetID());
4968-
edit.DeleteFile(level, number);
4969-
status = versions_->LogAndApply(cfd, read_options, write_options, &edit,
4970-
&mutex_, directories_.GetDbDir());
4971-
if (status.ok()) {
4972-
InstallSuperVersionAndScheduleWork(
4973-
cfd, job_context.superversion_contexts.data());
4974-
}
4975-
FindObsoleteFiles(&job_context, false);
4976-
} // lock released here
4977-
4978-
LogFlush(immutable_db_options_.info_log);
4979-
// remove files outside the db-lock
4980-
if (job_context.HaveSomethingToDelete()) {
4981-
// Call PurgeObsoleteFiles() without holding mutex.
4982-
PurgeObsoleteFiles(job_context);
4983-
}
4984-
job_context.Clean();
4985-
return status;
4986-
}
4987-
49884886
Status DBImpl::DeleteFilesInRanges(ColumnFamilyHandle* column_family,
49894887
const RangePtr* ranges, size_t n,
49904888
bool include_end) {

db/db_impl/db_impl.h

-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,6 @@ class DBImpl : public DB {
535535
SequenceNumber seq_number, std::unique_ptr<TransactionLogIterator>* iter,
536536
const TransactionLogIterator::ReadOptions& read_options =
537537
TransactionLogIterator::ReadOptions()) override;
538-
Status DEPRECATED_DeleteFile(std::string name) override;
539538
Status DeleteFilesInRanges(ColumnFamilyHandle* column_family,
540539
const RangePtr* ranges, size_t n,
541540
bool include_end = true);

db/db_test.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -3409,10 +3409,6 @@ class ModelDB : public DB {
34093409
return Status::NotSupported();
34103410
}
34113411

3412-
Status DEPRECATED_DeleteFile(std::string /*name*/) override {
3413-
return Status::OK();
3414-
}
3415-
34163412
Status GetUpdatesSince(
34173413
ROCKSDB_NAMESPACE::SequenceNumber,
34183414
std::unique_ptr<ROCKSDB_NAMESPACE::TransactionLogIterator>*,
@@ -5319,7 +5315,7 @@ TEST_F(DBTest, DynamicLevelCompressionPerLevel) {
53195315
options.compression_per_level[0] = kNoCompression;
53205316
// No compression for the Ln whre L0 is compacted to
53215317
options.compression_per_level[1] = kNoCompression;
5322-
// Snpapy compression for Ln+1
5318+
// Snappy compression for Ln+1
53235319
options.compression_per_level[2] = kSnappyCompression;
53245320

53255321
OnFileDeletionListener* listener = new OnFileDeletionListener();
@@ -5373,7 +5369,10 @@ TEST_F(DBTest, DynamicLevelCompressionPerLevel) {
53735369
db_->GetColumnFamilyMetaData(&cf_meta);
53745370
for (const auto& file : cf_meta.levels[4].files) {
53755371
listener->SetExpectedFileName(dbname_ + file.name);
5376-
ASSERT_OK(dbfull()->DEPRECATED_DeleteFile(file.name));
5372+
Slice start(file.smallestkey), limit(file.largestkey);
5373+
const RangePtr ranges(&start, &limit);
5374+
EXPECT_OK(dbfull()->DeleteFilesInRanges(dbfull()->DefaultColumnFamily(),
5375+
&ranges, true /* include_end */));
53775376
}
53785377
listener->VerifyMatchedCount(cf_meta.levels[4].files.size());
53795378

db/deletefile_test.cc

-190
Original file line numberDiff line numberDiff line change
@@ -135,57 +135,6 @@ class DeleteFileTest : public DBTestBase {
135135
}
136136
};
137137

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-
189138
TEST_F(DeleteFileTest, PurgeObsoleteFilesTest) {
190139
Options options = CurrentOptions();
191140
SetOptions(&options);
@@ -496,145 +445,6 @@ TEST_F(DeleteFileTest, BackgroundPurgeTestMultipleJobs) {
496445
CheckFileTypeCounts(dbname_, 0, 1, 1);
497446
}
498447

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-
638448
} // namespace ROCKSDB_NAMESPACE
639449

640450
int main(int argc, char** argv) {

include/rocksdb/c.h

-3
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,6 @@ extern ROCKSDB_LIBRARY_API void rocksdb_compact_range_cf_opt(
692692
rocksdb_compactoptions_t* opt, const char* start_key, size_t start_key_len,
693693
const char* limit_key, size_t limit_key_len);
694694

695-
extern ROCKSDB_LIBRARY_API void DEPRECATED_rocksdb_delete_file(
696-
rocksdb_t* db, const char* name);
697-
698695
extern ROCKSDB_LIBRARY_API const rocksdb_livefiles_t* rocksdb_livefiles(
699696
rocksdb_t* db);
700697

include/rocksdb/db.h

-13
Original file line numberDiff line numberDiff line change
@@ -1836,19 +1836,6 @@ class DB {
18361836
const TransactionLogIterator::ReadOptions& read_options =
18371837
TransactionLogIterator::ReadOptions()) = 0;
18381838

1839-
// WARNING: This API is planned for removal in RocksDB 7.0 since it does not
1840-
// operate at the proper level of abstraction for a key-value store, and its
1841-
// contract/restrictions are poorly documented. For example, it returns non-OK
1842-
// `Status` for non-bottommost files and files undergoing compaction. Since we
1843-
// do not plan to maintain it, the contract will likely remain underspecified
1844-
// until its removal. Any user is encouraged to read the implementation
1845-
// carefully and migrate away from it when possible.
1846-
//
1847-
// Delete the file name from the db directory and update the internal state to
1848-
// reflect that. Supports deletion of sst and log files only. 'name' must be
1849-
// path relative to the db directory. eg. 000001.sst, /archive/000003.log
1850-
virtual Status DEPRECATED_DeleteFile(std::string name) = 0;
1851-
18521839
// Obtains a list of all live table (SST) files and how they fit into the
18531840
// LSM-trees, such as column family, level, key range, etc.
18541841
// This builds a de-normalized form of GetAllColumnFamilyMetaData().

0 commit comments

Comments
 (0)