Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
nblintao committed Feb 8, 2022
1 parent 2c2039d commit 66f5f40
Show file tree
Hide file tree
Showing 26 changed files with 924 additions and 351 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ endif()
add_subdirectory(fdbbackup)
add_subdirectory(contrib)
add_subdirectory(tests)
add_subdirectory(flowbench EXCLUDE_FROM_ALL)
#add_subdirectory(flowbench EXCLUDE_FROM_ALL)
if(WITH_PYTHON AND WITH_C_BINDING)
add_subdirectory(bindings)
endif()
Expand Down
11 changes: 11 additions & 0 deletions bindings/c/fdb_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ fdb_error_t fdb_future_get_keyvalue_array_v13(FDBFuture* f, FDBKeyValue const**
*out_count = rrr.size(););
}

extern "C" DLLEXPORT fdb_error_t fdb_future_get_keyvalueandmap_array(FDBFuture* f,
FDBKeyValueAndMap const** out_kvm,
int* out_count,
fdb_bool_t* out_more) {
CATCH_AND_RETURN(Standalone<RangeAndMapResultRef> rrr = TSAV(Standalone<RangeAndMapResultRef>, f)->get();
*out_kvm = (FDBKeyValueAndMap*)rrr.begin();
*out_count = rrr.size();
*out_more = rrr.more;);
}

extern "C" DLLEXPORT fdb_error_t fdb_future_get_string_array(FDBFuture* f, const char*** out_strings, int* out_count) {
CATCH_AND_RETURN(Standalone<VectorRef<const char*>> na = TSAV(Standalone<VectorRef<const char*>>, f)->get();
*out_strings = (const char**)na.begin();
Expand Down Expand Up @@ -570,6 +580,7 @@ FDBFuture* fdb_transaction_get_range_impl(FDBTransaction* tr,
.extractPtr());
}

// TODO: Interpret FDBFuture as RangeAndMapResult.
FDBFuture* fdb_transaction_get_range_and_flat_map_impl(FDBTransaction* tr,
uint8_t const* begin_key_name,
int begin_key_name_length,
Expand Down
71 changes: 71 additions & 0 deletions bindings/c/foundationdb/fdb_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,71 @@ typedef struct keyvalue {
int value_length;
} FDBKeyValue;
#endif

#pragma pack(pop)

// Memory layout of GetValueReqAndResultRef.
typedef struct getvaluereqandresult {
FDBKey key;
fdb_bool_t exists;
FDBKey value;
} FDBGetValueReqAndResult;

// Memory layout of KeySelectorRef.
typedef struct keyselector {
FDBKey key;
// orEqual and offset have not be tested in C binding. Just a placeholder.
fdb_bool_t orEqual;
int offset;
} FDBKeySelector;

// Memory layout of GetRangeReqAndResultRef.
typedef struct getrangereqandresult {
FDBKeySelector begin;
FDBKeySelector end;
FDBKeyValue* data;
int m_size, m_capacity;
} FDBGetRangeReqAndResult;

// Memory layout of KeyValueAndMappedReqAndResultRef.
/*
Total 112 bytes
- key (12 bytes)
:74:8F:8E:5F:AE:7F:00:00
:4A:00:00:00
- value (12 bytes)
:70:8F:8E:5F:AE:7F:00:00
:00:00:00:00
- begin selector (20 bytes)
:30:8F:8E:5F:AE:7F:00:00
:2D:00:00:00
:00:7F:00:00
:01:00:00:00
- end selector (20 bytes)
:EC:8E:8E:5F:AE:7F:00:00
:2D:00:00:00
:00:2B:3C:60
:01:00:00:00
- vector (16 bytes)
:74:94:8E:5F:AE:7F:00:00
:01:00:00:00
:01:00:00:00
- buffer (32 bytes)
:00:20:D1:61:00:00:00:00
:00:00:00:00:00:00:00:00
:00:00:00:00:00:00:00:00
:01:00:00:00:AE:7F:00:00
*/
typedef struct keyvalueandmap {
FDBKey key;
FDBKey value;
// It's complicated to map a std::variant to C. For now we assume the underlying requests are always getRange and
// take the shortcut.
FDBGetRangeReqAndResult getRange;
unsigned char buffer[32];
} FDBKeyValueAndMap;

#pragma pack(push, 4)
typedef struct keyrange {
const uint8_t* begin_key;
int begin_key_length;
Expand Down Expand Up @@ -176,6 +241,12 @@ DLLEXPORT WARN_UNUSED_RESULT fdb_error_t fdb_future_get_keyvalue_array(FDBFuture
int* out_count,
fdb_bool_t* out_more);
#endif

DLLEXPORT WARN_UNUSED_RESULT fdb_error_t fdb_future_get_keyvalueandmap_array(FDBFuture* f,
FDBKeyValueAndMap const** out_kv,
int* out_count,
fdb_bool_t* out_more);

DLLEXPORT WARN_UNUSED_RESULT fdb_error_t fdb_future_get_key_array(FDBFuture* f,
FDBKey const** out_key_array,
int* out_count);
Expand Down
74 changes: 41 additions & 33 deletions bindings/c/test/unit/fdb_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ void Future::cancel() {
return fdb_future_get_keyvalue_array(future_, out_kv, out_count, out_more);
}

// KeyValueAndMapArrayFuture

[[nodiscard]] fdb_error_t KeyValueAndMapArrayFuture::get(const FDBKeyValueAndMap** out_kv,
int* out_count,
fdb_bool_t* out_more) {
return fdb_future_get_keyvalueandmap_array(future_, out_kv, out_count, out_more);
}

// Result

Result::~Result() {
Expand Down Expand Up @@ -210,39 +218,39 @@ KeyValueArrayFuture Transaction::get_range(const uint8_t* begin_key_name,
reverse));
}

KeyValueArrayFuture Transaction::get_range_and_flat_map(const uint8_t* begin_key_name,
int begin_key_name_length,
fdb_bool_t begin_or_equal,
int begin_offset,
const uint8_t* end_key_name,
int end_key_name_length,
fdb_bool_t end_or_equal,
int end_offset,
const uint8_t* mapper_name,
int mapper_name_length,
int limit,
int target_bytes,
FDBStreamingMode mode,
int iteration,
fdb_bool_t snapshot,
fdb_bool_t reverse) {
return KeyValueArrayFuture(fdb_transaction_get_range_and_flat_map(tr_,
begin_key_name,
begin_key_name_length,
begin_or_equal,
begin_offset,
end_key_name,
end_key_name_length,
end_or_equal,
end_offset,
mapper_name,
mapper_name_length,
limit,
target_bytes,
mode,
iteration,
snapshot,
reverse));
KeyValueAndMapArrayFuture Transaction::get_range_and_flat_map(const uint8_t* begin_key_name,
int begin_key_name_length,
fdb_bool_t begin_or_equal,
int begin_offset,
const uint8_t* end_key_name,
int end_key_name_length,
fdb_bool_t end_or_equal,
int end_offset,
const uint8_t* mapper_name,
int mapper_name_length,
int limit,
int target_bytes,
FDBStreamingMode mode,
int iteration,
fdb_bool_t snapshot,
fdb_bool_t reverse) {
return KeyValueAndMapArrayFuture(fdb_transaction_get_range_and_flat_map(tr_,
begin_key_name,
begin_key_name_length,
begin_or_equal,
begin_offset,
end_key_name,
end_key_name_length,
end_or_equal,
end_offset,
mapper_name,
mapper_name_length,
limit,
target_bytes,
mode,
iteration,
snapshot,
reverse));
}

EmptyFuture Transaction::watch(std::string_view key) {
Expand Down
44 changes: 28 additions & 16 deletions bindings/c/test/unit/fdb_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ class KeyValueArrayFuture : public Future {
KeyValueArrayFuture(FDBFuture* f) : Future(f) {}
};

class KeyValueAndMapArrayFuture : public Future {
public:
// Call this function instead of fdb_future_get_keyvalueandmap_array when using
// the KeyValueAndMapArrayFuture type. It's behavior is identical to
// fdb_future_get_keyvalueandmap_array.
fdb_error_t get(const FDBKeyValueAndMap** out_kv, int* out_count, fdb_bool_t* out_more);

private:
friend class Transaction;
KeyValueAndMapArrayFuture(FDBFuture* f) : Future(f) {}
};

class KeyRangeArrayFuture : public Future {
public:
// Call this function instead of fdb_future_get_keyrange_array when using
Expand Down Expand Up @@ -254,22 +266,22 @@ class Transaction final {

// WARNING: This feature is considered experimental at this time. It is only allowed when using snapshot isolation
// AND disabling read-your-writes. Returns a future which will be set to an FDBKeyValue array.
KeyValueArrayFuture get_range_and_flat_map(const uint8_t* begin_key_name,
int begin_key_name_length,
fdb_bool_t begin_or_equal,
int begin_offset,
const uint8_t* end_key_name,
int end_key_name_length,
fdb_bool_t end_or_equal,
int end_offset,
const uint8_t* mapper_name,
int mapper_name_length,
int limit,
int target_bytes,
FDBStreamingMode mode,
int iteration,
fdb_bool_t snapshot,
fdb_bool_t reverse);
KeyValueAndMapArrayFuture get_range_and_flat_map(const uint8_t* begin_key_name,
int begin_key_name_length,
fdb_bool_t begin_or_equal,
int begin_offset,
const uint8_t* end_key_name,
int end_key_name_length,
fdb_bool_t end_or_equal,
int end_offset,
const uint8_t* mapper_name,
int mapper_name_length,
int limit,
int target_bytes,
FDBStreamingMode mode,
int iteration,
fdb_bool_t snapshot,
fdb_bool_t reverse);

// Wrapper around fdb_transaction_watch. Returns a future representing an
// empty value.
Expand Down
Loading

0 comments on commit 66f5f40

Please sign in to comment.