From 5f1bda457ccf8753fe51581e5a58f92a0b35928d Mon Sep 17 00:00:00 2001 From: Ben Young Date: Mon, 9 Dec 2024 17:00:27 -0600 Subject: [PATCH] KVStore lookup fix for if-generation-match option (#1069) --- .github/workflows/main.yml | 4 ++-- runtime/fastly/host-api/fastly.h | 11 +++++++++-- runtime/fastly/host-api/host_api.cpp | 10 +++++----- runtime/fastly/host-api/host_api_fastly.h | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 54e5273cdb..62f05a212d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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 diff --git a/runtime/fastly/host-api/fastly.h b/runtime/fastly/host-api/fastly.h index 57a32fa3fc..ed2a772537 100644 --- a/runtime/fastly/host-api/fastly.h +++ b/runtime/fastly/host-api/fastly.h @@ -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 @@ -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) @@ -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, diff --git a/runtime/fastly/host-api/host_api.cpp b/runtime/fastly/host-api/host_api.cpp index 97a47b8189..45d1ba925f 100644 --- a/runtime/fastly/host-api/host_api.cpp +++ b/runtime/fastly/host-api/host_api.cpp @@ -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(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); @@ -3354,7 +3354,7 @@ FastlyAsyncTask::Handle KVStorePendingDelete::async_handle() const { Result KVStore::insert(std::string_view key, HttpBody body, std::optional mode, - std::optional if_generation_match, + std::optional if_generation_match, std::optional> metadata, std::optional ttl) { Result res; diff --git a/runtime/fastly/host-api/host_api_fastly.h b/runtime/fastly/host-api/host_api_fastly.h index 6462a81a02..68f6b4badc 100644 --- a/runtime/fastly/host-api/host_api_fastly.h +++ b/runtime/fastly/host-api/host_api_fastly.h @@ -1035,7 +1035,7 @@ class KVStore final { Result lookup(std::string_view key); Result insert(std::string_view key, HttpBody body, std::optional mode, - std::optional if_generation_match, + std::optional if_generation_match, std::optional> metadata, std::optional ttl); Result delete_(std::string_view key); // cursor is base64 encoding of the last key