Expose KeyMayExist in the C API (#7021)

Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/7021

Reviewed By: ajkr

Differential Revision: D22246297

Pulled By: pdillinger

fbshipit-source-id: 81dfd0a49e4d5ce0c9f00772c17cca425757ea24
main
Stanislav Tkach 5 years ago committed by Facebook GitHub Bot
parent d47c871190
commit 1b85d57cf5
  1. 49
      db/c.cc
  2. 23
      db/c_test.c
  3. 15
      include/rocksdb/c.h

@ -996,6 +996,55 @@ void rocksdb_multi_get_cf(
}
}
unsigned char rocksdb_key_may_exist(rocksdb_t* db,
const rocksdb_readoptions_t* options,
const char* key, size_t key_len,
char** value, size_t* val_len,
const char* timestamp, size_t timestamp_len,
unsigned char* value_found) {
std::string tmp;
std::string time;
if (timestamp) {
time.assign(timestamp, timestamp_len);
}
bool found = false;
const bool result = db->rep->KeyMayExist(options->rep, Slice(key, key_len),
&tmp, timestamp ? &time : nullptr,
value_found ? &found : nullptr);
if (value_found) {
*value_found = found;
if (found) {
*val_len = tmp.size();
*value = CopyString(tmp);
}
}
return result;
}
unsigned char rocksdb_key_may_exist_cf(
rocksdb_t* db, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,
size_t key_len, char** value, size_t* val_len, const char* timestamp,
size_t timestamp_len, unsigned char* value_found) {
std::string tmp;
std::string time;
if (timestamp) {
time.assign(timestamp, timestamp_len);
}
bool found = false;
const bool result = db->rep->KeyMayExist(
options->rep, column_family->rep, Slice(key, key_len), &tmp,
timestamp ? &time : nullptr, value_found ? &found : nullptr);
if (value_found) {
*value_found = found;
if (found) {
*val_len = tmp.size();
*value = CopyString(tmp);
}
}
return result;
}
rocksdb_iterator_t* rocksdb_create_iterator(
rocksdb_t* db,
const rocksdb_readoptions_t* options) {

@ -1296,6 +1296,29 @@ int main(int argc, char** argv) {
Free(&vals[i]);
}
{
unsigned char value_found = 0;
CheckCondition(!rocksdb_key_may_exist(db, roptions, "invalid_key", 11,
NULL, NULL, NULL, 0, NULL));
CheckCondition(!rocksdb_key_may_exist(db, roptions, "invalid_key", 11,
&vals[0], &vals_sizes[0], NULL, 0,
&value_found));
if (value_found) {
Free(&vals[0]);
}
CheckCondition(!rocksdb_key_may_exist_cf(db, roptions, handles[1],
"invalid_key", 11, NULL, NULL,
NULL, 0, NULL));
CheckCondition(!rocksdb_key_may_exist_cf(db, roptions, handles[1],
"invalid_key", 11, &vals[0],
&vals_sizes[0], NULL, 0, NULL));
if (value_found) {
Free(&vals[0]);
}
}
rocksdb_iterator_t* iter = rocksdb_create_iterator_cf(db, roptions, handles[1]);
CheckCondition(!rocksdb_iter_valid(iter));
rocksdb_iter_seek_to_first(iter);

@ -320,6 +320,21 @@ extern ROCKSDB_LIBRARY_API void rocksdb_multi_get_cf(
const size_t* keys_list_sizes, char** values_list,
size_t* values_list_sizes, char** errs);
// The value is only allocated (using malloc) and returned if it is found and
// value_found isn't NULL. In that case the user is responsible for freeing it.
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_key_may_exist(
rocksdb_t* db, const rocksdb_readoptions_t* options, const char* key,
size_t key_len, char** value, size_t* val_len, const char* timestamp,
size_t timestamp_len, unsigned char* value_found);
// The value is only allocated (using malloc) and returned if it is found and
// value_found isn't NULL. In that case the user is responsible for freeing it.
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_key_may_exist_cf(
rocksdb_t* db, const rocksdb_readoptions_t* options,
rocksdb_column_family_handle_t* column_family, const char* key,
size_t key_len, char** value, size_t* val_len, const char* timestamp,
size_t timestamp_len, unsigned char* value_found);
extern ROCKSDB_LIBRARY_API rocksdb_iterator_t* rocksdb_create_iterator(
rocksdb_t* db, const rocksdb_readoptions_t* options);

Loading…
Cancel
Save