if (rocksdb::kDefaultColumnFamilyName == base_name) {
default_cf = handles[i];
must_close_default_cf = true;
+ std::unique_ptr<rocksdb::ColumnFamilyHandle, cf_deleter_t> ptr{
+ cf, [](rocksdb::ColumnFamilyHandle*) {}};
+ to_process_columns.emplace(full_name, std::move(ptr));
} else {
for (const auto& nsd : new_sharding_def) {
if (nsd.name == base_name) {
break;
}
}
+ std::unique_ptr<rocksdb::ColumnFamilyHandle, cf_deleter_t> ptr{
+ cf, [this](rocksdb::ColumnFamilyHandle* handle) {
+ db->DestroyColumnFamilyHandle(handle);
+ }};
+ to_process_columns.emplace(full_name, std::move(ptr));
}
- to_process_columns.emplace(full_name, cf);
}
//8. check if all cf_handles are filled
// verify that column is empty
std::unique_ptr<rocksdb::Iterator> it{
- db->NewIterator(rocksdb::ReadOptions(), handle)};
+ db->NewIterator(rocksdb::ReadOptions(), handle.get())};
ceph_assert(it);
it->SeekToFirst();
ceph_assert(!it->Valid());
- if (rocksdb::Status status = db->DropColumnFamily(handle); !status.ok()) {
+ if (rocksdb::Status status = db->DropColumnFamily(handle.get()); !status.ok()) {
derr << __func__ << " Failed to drop column: " << name << dendl;
return -EINVAL;
}
for (auto& [name, handle] : to_process_columns) {
dout(5) << "Processing column=" << name
- << " handle=" << handle << dendl;
+ << " handle=" << handle.get() << dendl;
if (name == rocksdb::kDefaultColumnFamilyName) {
- ceph_assert(handle == default_cf);
+ ceph_assert(handle.get() == default_cf);
r = process_column(default_cf, std::string());
} else {
std::string fixed_prefix = name.substr(0, name.find('-'));
dout(10) << "Prefix: " << fixed_prefix << dendl;
- r = process_column(handle, fixed_prefix);
+ r = process_column(handle.get(), fixed_prefix);
}
if (r != 0) {
derr << "Error processing column " << name << dendl;
r = -EIO;
}
- cleanup:
- //close column handles
- for (const auto& col: cf_handles) {
- for (size_t i = 0; i < col.second.handles.size(); i++) {
- db->DestroyColumnFamilyHandle(col.second.handles[i]);
- }
- }
+cleanup:
cf_handles.clear();
close();
return r;
private:
WholeSpaceIterator get_default_cf_iterator();
- using columns_t = std::map<std::string, rocksdb::ColumnFamilyHandle*>;
+ using cf_deleter_t = std::function<void(rocksdb::ColumnFamilyHandle*)>;
+ using columns_t = std::map<std::string,
+ std::unique_ptr<rocksdb::ColumnFamilyHandle,
+ cf_deleter_t>>;
int prepare_for_reshard(const std::string& new_sharding,
columns_t& to_process_columns);
int reshard_cleanup(const columns_t& current_columns);