Skip to content

Commit

Permalink
Add support for Delete/SingleDelete with secondary indices (#13291)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #13291

Differential Revision: D68041422
  • Loading branch information
ltamasi authored and facebook-github-bot committed Jan 14, 2025
1 parent 8bccd39 commit af5db67
Showing 1 changed file with 93 additions and 31 deletions.
124 changes: 93 additions & 31 deletions utilities/secondary_index/secondary_index_mixin.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,35 @@ class SecondaryIndexMixin : public Txn {
}

using Txn::Delete;
Status Delete(ColumnFamilyHandle* /* column_family */, const Slice& /* key */,
const bool /* assume_tracked */ = false) override {
return Status::NotSupported(
"Delete with secondary indices not yet supported");
Status Delete(ColumnFamilyHandle* column_family, const Slice& key,
const bool assume_tracked = false) override {
return PerformWithSavePoint([&]() {
const bool do_validate = !assume_tracked;
return DeleteWithSecondaryIndices(column_family, key, do_validate);
});
}
Status Delete(ColumnFamilyHandle* /* column_family */,
const SliceParts& /* key */,
const bool /* assume_tracked */ = false) override {
return Status::NotSupported(
"Delete with secondary indices not yet supported");
Status Delete(ColumnFamilyHandle* column_family, const SliceParts& key,
const bool assume_tracked = false) override {
std::string key_str;
const Slice key_slice(key, &key_str);

return Delete(column_family, key_slice, assume_tracked);
}

using Txn::SingleDelete;
Status SingleDelete(ColumnFamilyHandle* /* column_family */,
const Slice& /* key */,
const bool /* assume_tracked */ = false) override {
return Status::NotSupported(
"SingleDelete with secondary indices not yet supported");
Status SingleDelete(ColumnFamilyHandle* column_family, const Slice& key,
const bool assume_tracked = false) override {
return PerformWithSavePoint([&]() {
const bool do_validate = !assume_tracked;
return SingleDeleteWithSecondaryIndices(column_family, key, do_validate);
});
}
Status SingleDelete(ColumnFamilyHandle* /* column_family */,
const SliceParts& /* key */,
const bool /* assume_tracked */ = false) override {
return Status::NotSupported(
"SingleDelete with secondary indices not yet supported");
Status SingleDelete(ColumnFamilyHandle* column_family, const SliceParts& key,
const bool assume_tracked = false) override {
std::string key_str;
const Slice key_slice(key, &key_str);

return SingleDelete(column_family, key_slice, assume_tracked);
}

using Txn::PutUntracked;
Expand Down Expand Up @@ -136,22 +141,28 @@ class SecondaryIndexMixin : public Txn {
}

using Txn::DeleteUntracked;
Status DeleteUntracked(ColumnFamilyHandle* /* column_family */,
const Slice& /* key */) override {
return Status::NotSupported(
"DeleteUntracked with secondary indices not yet supported");
Status DeleteUntracked(ColumnFamilyHandle* column_family,
const Slice& key) override {
return PerformWithSavePoint([&]() {
constexpr bool do_validate = false;
return DeleteWithSecondaryIndices(column_family, key, do_validate);
});
}
Status DeleteUntracked(ColumnFamilyHandle* /* column_family */,
const SliceParts& /* key */) override {
return Status::NotSupported(
"DeleteUntracked with secondary indices not yet supported");
Status DeleteUntracked(ColumnFamilyHandle* column_family,
const SliceParts& key) override {
std::string key_str;
const Slice key_slice(key, &key_str);

return DeleteUntracked(column_family, key_slice);
}

using Txn::SingleDeleteUntracked;
Status SingleDeleteUntracked(ColumnFamilyHandle* /* column_family */,
const Slice& /* key */) override {
return Status::NotSupported(
"SingleDeleteUntracked with secondary indices not yet supported");
Status SingleDeleteUntracked(ColumnFamilyHandle* column_family,
const Slice& key) override {
return PerformWithSavePoint([&]() {
constexpr bool do_validate = false;
return SingleDeleteWithSecondaryIndices(column_family, key, do_validate);
});
}

private:
Expand Down Expand Up @@ -510,6 +521,57 @@ class SecondaryIndexMixin : public Txn {
do_validate);
}

template <typename Operation>
Status DeleteWithSecondaryIndicesImpl(ColumnFamilyHandle* column_family,
const Slice& key, bool do_validate,
Operation&& operation) {
if (!column_family) {
column_family = Txn::DefaultColumnFamily();
}

{
const Status s = RemoveSecondaryEntries(column_family, key, do_validate);
if (!s.ok()) {
return s;
}
}

{
const Status s = operation(column_family, key);
if (!s.ok()) {
return s;
}
}

return Status::OK();
}

Status DeleteWithSecondaryIndices(ColumnFamilyHandle* column_family,
const Slice& key, bool do_validate) {
return DeleteWithSecondaryIndicesImpl(
column_family, key, do_validate,
[&](ColumnFamilyHandle* cfh, const Slice& primary_key) {
assert(cfh);

constexpr bool assume_tracked = true;

return Txn::Delete(cfh, primary_key, assume_tracked);
});
}

Status SingleDeleteWithSecondaryIndices(ColumnFamilyHandle* column_family,
const Slice& key, bool do_validate) {
return DeleteWithSecondaryIndicesImpl(
column_family, key, do_validate,
[&](ColumnFamilyHandle* cfh, const Slice& primary_key) {
assert(cfh);

constexpr bool assume_tracked = true;

return Txn::SingleDelete(cfh, primary_key, assume_tracked);
});
}

const std::vector<std::shared_ptr<SecondaryIndex>>* secondary_indices_;
};

Expand Down

0 comments on commit af5db67

Please sign in to comment.