Skip to content

Commit

Permalink
KVStore lookup fix for if-generation-match option (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth authored Dec 9, 2024
1 parent 857f6fa commit 5f1bda4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defaults:
shell: bash
env:
# Note: when updated, also update version in ensure-cargo-installs
viceroy_version: 0.12.1
viceroy_version: 0.12.2
# Note: when updated, also update version in ensure-cargo-installs ! AND ! release-please.yml
wasm-tools_version: 1.216.0
fastly-cli_version: 10.13.3
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
matrix:
include:
- crate: viceroy
version: 0.12.1 # Note: workflow-level env vars can't be used in matrix definitions
version: 0.12.2 # Note: workflow-level env vars can't be used in matrix definitions
options: ""
- crate: wasm-tools
version: 1.216.0 # Note: workflow-level env vars can't be used in matrix definitions
Expand Down
11 changes: 9 additions & 2 deletions runtime/fastly/host-api/fastly.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,10 @@ typedef struct __attribute__((aligned(4))) KVLookupOptions {

#define KV_INSERT_CONFIG_RESERVED (1u << 0)
#define KV_INSERT_CONFIG_BACKGROUND_FETCH (1u << 1)
#define KV_INSERT_CONFIG_IF_GENERATION_MATCH (1u << 2)
#define KV_INSERT_CONFIG_RESERVED_2 (1u << 2)
#define KV_INSERT_CONFIG_METADATA (1u << 3)
#define KV_INSERT_CONFIG_TIME_TO_LIVE_SEC (1u << 4)
#define KV_INSERT_CONFIG_IF_GENERATION_MATCH (1u << 5)

#define KV_INSERT_MODE_OVERWRITE 0u
#define KV_INSERT_MODE_ADD 1u
Expand All @@ -570,10 +571,11 @@ typedef struct __attribute__((aligned(4))) KVLookupOptions {

typedef struct __attribute__((aligned(4))) KVInsertOptions {
uint32_t mode;
uint32_t if_generation_match;
uint32_t reserved;
const uint8_t *metadata;
uint32_t metadata_len;
uint32_t time_to_live_sec;
uint64_t if_generation_match;
} KVInsertOptions;

#define KV_DELETE_CONFIG_RESERVED (1u << 0)
Expand Down Expand Up @@ -621,6 +623,11 @@ int kv_store_lookup_wait(uint32_t kv_store_handle_lookup_handle, uint32_t *body_
uint8_t *metadata_buf_out, size_t metadata_buf_len, size_t *nwritten_out,
uint32_t *generation_out, uint32_t *kv_error_out);

WASM_IMPORT("fastly_kv_store", "lookup_wait_v2")
int kv_store_lookup_wait_v2(uint32_t kv_store_handle_lookup_handle, uint32_t *body_handle_out,
uint8_t *metadata_buf_out, size_t metadata_buf_len,
size_t *nwritten_out, uint64_t *generation_out, uint32_t *kv_error_out);

WASM_IMPORT("fastly_kv_store", "insert")
int kv_store_insert(uint32_t kv_store_handle, const char *key, size_t key_len, uint32_t body_handle,
uint32_t insert_options_mask, KVInsertOptions *insert_options,
Expand Down
10 changes: 5 additions & 5 deletions runtime/fastly/host-api/host_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3290,14 +3290,14 @@ KVStorePendingLookup::wait() {
fastly::fastly_host_error err;
HttpBody body{};

uint32_t gen_out;
uint64_t gen_out;
fastly::fastly_kv_error kv_err = 0;
uint8_t *metadata_buf = reinterpret_cast<uint8_t *>(cabi_malloc(HOSTCALL_BUFFER_LEN, 1));
size_t metadata_nwritten;

if (!convert_result(fastly::kv_store_lookup_wait(this->handle, &body.handle, metadata_buf,
HOSTCALL_BUFFER_LEN, &metadata_nwritten,
&gen_out, &kv_err),
if (!convert_result(fastly::kv_store_lookup_wait_v2(this->handle, &body.handle, metadata_buf,
HOSTCALL_BUFFER_LEN, &metadata_nwritten,
&gen_out, &kv_err),
&err) ||
((kv_err != KV_ERROR_OK || body.handle == INVALID_HANDLE) && kv_err != KV_ERROR_NOT_FOUND)) {
cabi_free(metadata_buf);
Expand Down Expand Up @@ -3354,7 +3354,7 @@ FastlyAsyncTask::Handle KVStorePendingDelete::async_handle() const {

Result<KVStorePendingInsert::Handle>
KVStore::insert(std::string_view key, HttpBody body, std::optional<InsertMode> mode,
std::optional<uint32_t> if_generation_match,
std::optional<uint64_t> if_generation_match,
std::optional<std::tuple<const uint8_t *, size_t>> metadata,
std::optional<uint32_t> ttl) {
Result<KVStorePendingInsert::Handle> res;
Expand Down
2 changes: 1 addition & 1 deletion runtime/fastly/host-api/host_api_fastly.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ class KVStore final {
Result<KVStorePendingLookup::Handle> lookup(std::string_view key);
Result<KVStorePendingInsert::Handle>
insert(std::string_view key, HttpBody body, std::optional<InsertMode> mode,
std::optional<uint32_t> if_generation_match,
std::optional<uint64_t> if_generation_match,
std::optional<std::tuple<const uint8_t *, size_t>> metadata, std::optional<uint32_t> ttl);
Result<KVStorePendingDelete::Handle> delete_(std::string_view key);
// cursor is base64 encoding of the last key
Expand Down

0 comments on commit 5f1bda4

Please sign in to comment.