apple / foundationdb

FoundationDB - the open source, distributed, transactional key-value store
https://apple.github.io/foundationdb/
Apache License 2.0
14.33k stars 1.3k forks source link

Why can’t get the key-value with usage of fdb_transaction_get_range (C Programming) #6059

Closed JiangXiNJU closed 2 years ago

JiangXiNJU commented 2 years ago

Hi. I have already set a kv
(‘\x00\x05\x00\x00\x00\x00\x00\x00movie’ ,’\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00’)
into the fdb. And I can search this with fdbcli tools : getrange \x00\x05 \x00\xff.

But when I use C API (version 630), something strange happened.

Situation A When the code is : uint8_t startUint[2] = {0x0, 0x5}; uint8_t endUnit[2] = {254, 254};
FDBFuture *future = fdb_transaction_get_range(tr, startUint, 2, 0, 1, endUnit, 2, 1, 0, 0, 0, FDB_STREAMING_MODE_LARGE, 0, 0, 0);
I can get the kv.

Situation B When the code is : uint8_t startUint[2] = {0x0, 0x5}; uint8_t endUnit[2] = {0x0, 254}; FDBFuture *future = fdb_transaction_get_range(tr, startUint, 2, 0, 1, endUnit, 2, 1, 0, 0, 0, FDB_STREAMING_MODE_LARGE, 0, 0, 0); I got Nothing !

Situation C Then I change the begin_or_equal/begin_offset/end_or_equal/end_offset uint8_t startUint[2] = {0x0, 0x5}; uint8_t endUnit[2] = {0x0, 254}; FDBFuture *future = fdb_transaction_get_range(tr, startUint, 2, 1, 0, endUnit, 2, 0, 1, 0, 0, FDB_STREAMING_MODE_LARGE, 0, 0, 0); I get the Kv agian.

Situation D But when I change the startKey as belowed: uint8_t startUint[3] = {0x0, 0x5, 0x1}; uint8_t endUnit[2] = {0x0, 254}; FDBFuture *future = fdb_transaction_get_range(tr, startUint, 3, 1, 0, endUnit, 2, 0, 1, 0, 0, FDB_STREAMING_MODE_LARGE, 0, 0, 0); I still get the KV!!!

Now I'm totally confused...

I thought I can get the kv in Situation A and B,but I can't. I thought I can't get the kv in Situation D, but I can. Can anyone tell me where the mistake was? Or can anyone explain how the begin_or_equal/begin_offset/end_or_equal/end_offset are used?

sfc-gh-abeamon commented 2 years ago

This type of question is best asked in the forums, as we generally track actual work items in GitHub issues.

The use of key selectors in range reads tends to be a little bit confusing, but have a look at this comment on a previous forum post to see if it helps clear things up. If you still have questions, feel free to ask them in the forums.

JiangXiNJU commented 2 years ago

Well,Thanks for answering. I have already posted this quesion in the forums ( https://forums.foundationdb.org/t/why-cant-get-the-key-value-i-need-for-using-fdb-transaction-get-range/3038), but got no response yet.