Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cpp_library_wrapper(name="rocksdb_lib", srcs=[
"db/db_impl/db_impl_files.cc",
"db/db_impl/db_impl_follower.cc",
"db/db_impl/db_impl_open.cc",
"db/db_impl/db_impl_prefix_exists.cc",
"db/db_impl/db_impl_readonly.cc",
"db/db_impl/db_impl_secondary.cc",
"db/db_impl/db_impl_write.cc",
Expand Down Expand Up @@ -5410,6 +5411,12 @@ cpp_unittest_wrapper(name="prefetch_test",
extra_compiler_flags=[])


cpp_unittest_wrapper(name="prefix_exists_test",
srcs=["db/prefix_exists_test.cc"],
deps=[":rocksdb_test_lib"],
extra_compiler_flags=[])


cpp_unittest_wrapper(name="prefix_test",
srcs=["db/prefix_test.cc"],
deps=[":rocksdb_test_lib"],
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ set(SOURCES
db/db_impl/db_impl_debug.cc
db/db_impl/db_impl_experimental.cc
db/db_impl/db_impl_readonly.cc
db/db_impl/db_impl_prefix_exists.cc
db/db_impl/db_impl_secondary.cc
db/db_info_dumper.cc
db/db_iter.cc
Expand Down Expand Up @@ -1412,6 +1413,7 @@ if(WITH_TESTS)
db/plain_table_db_test.cc
db/seqno_time_test.cc
db/prefix_test.cc
db/prefix_exists_test.cc
db/range_del_aggregator_test.cc
db/range_tombstone_fragmenter_test.cc
db/repair_test.cc
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,9 @@ perf_context_test: $(OBJ_DIR)/db/perf_context_test.o $(TEST_LIBRARY) $(LIBRARY)
prefix_test: $(OBJ_DIR)/db/prefix_test.o $(TEST_LIBRARY) $(LIBRARY)
$(AM_LINK)

prefix_exists_test: $(OBJ_DIR)/db/prefix_exists_test.o $(TEST_LIBRARY) $(LIBRARY)
$(AM_LINK)

backup_engine_test: $(OBJ_DIR)/utilities/backup/backup_engine_test.o $(TEST_LIBRARY) $(LIBRARY)
$(AM_LINK)

Expand Down
102 changes: 102 additions & 0 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,108 @@ static inline char* CopyString(const Slice& slice) {
return result;
}

unsigned char rocksdb_prefix_exists(rocksdb_t* db,
const rocksdb_readoptions_t* options,
const char* prefix, size_t prefix_len,
char** errptr) {
Status s = db->rep->PrefixExists(options->rep, Slice(prefix, prefix_len));
if (s.ok()) {
return 1;
}
if (s.IsNotFound()) {
return 0;
}
SaveError(errptr, s);
return 0;
}

unsigned char rocksdb_prefix_exists_cf(
rocksdb_t* db, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* prefix,
size_t prefix_len, char** errptr) {
Status s = db->rep->PrefixExists(options->rep, column_family->rep,
Slice(prefix, prefix_len));
if (s.ok()) {
return 1;
}
if (s.IsNotFound()) {
return 0;
}
SaveError(errptr, s);
return 0;
}

unsigned char rocksdb_prefix_exists_multi(
rocksdb_t* db, const rocksdb_readoptions_t* options,
unsigned char prefixes_sorted, size_t num_prefixes,
const char* const* prefixes, const size_t* prefix_lens,
unsigned char* out_exists, char** errptr) {
if (num_prefixes == 0) {
return 1;
}
// Build Slice array
std::vector<Slice> pfx;
pfx.reserve(num_prefixes);
for (size_t i = 0; i < num_prefixes; ++i) {
pfx.emplace_back(prefixes[i], prefix_lens[i]);
}
// Output statuses
std::vector<Status> statuses(num_prefixes);
db->rep->PrefixExistsMulti(options->rep, static_cast<bool>(prefixes_sorted),
num_prefixes, pfx.data(), statuses.data());
bool ok = true;
for (size_t i = 0; i < num_prefixes; ++i) {
if (statuses[i].ok()) {
out_exists[i] = 1;
} else if (statuses[i].IsNotFound()) {
out_exists[i] = 0;
} else {
ok = false;
// capture first error
if (errptr && *errptr == nullptr) {
SaveError(errptr, statuses[i]);
}
out_exists[i] = 0;
}
}
return ok ? 1 : 0;
}

unsigned char rocksdb_prefix_exists_multi_cf(
rocksdb_t* db, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family,
unsigned char prefixes_sorted, size_t num_prefixes,
const char* const* prefixes, const size_t* prefix_lens,
unsigned char* out_exists, char** errptr) {
if (num_prefixes == 0) {
return 1;
}
std::vector<Slice> pfx;
pfx.reserve(num_prefixes);
for (size_t i = 0; i < num_prefixes; ++i) {
pfx.emplace_back(prefixes[i], prefix_lens[i]);
}
std::vector<Status> statuses(num_prefixes);
db->rep->PrefixExistsMulti(options->rep, column_family->rep,
static_cast<bool>(prefixes_sorted), num_prefixes,
pfx.data(), statuses.data());
bool ok = true;
for (size_t i = 0; i < num_prefixes; ++i) {
if (statuses[i].ok()) {
out_exists[i] = 1;
} else if (statuses[i].IsNotFound()) {
out_exists[i] = 0;
} else {
ok = false;
if (errptr && *errptr == nullptr) {
SaveError(errptr, statuses[i]);
}
out_exists[i] = 0;
}
}
return ok ? 1 : 0;
}

rocksdb_t* rocksdb_open(const rocksdb_options_t* options, const char* name,
char** errptr) {
DB* db;
Expand Down
Loading
Loading