Skip to content

Commit 84a6330

Browse files
committed
feat(config): add support for config store buffers longer than 8k
1 parent 5baaa01 commit 84a6330

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

runtime/fastly/host-api/fastly.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ typedef fastly_host_http_response fastly_world_tuple2_handle_handle;
4747
#define HEADER_MAX_LEN 69000
4848
#define METHOD_MAX_LEN 1024
4949
#define URI_MAX_LEN 8192
50-
#define CONFIG_STORE_ENTRY_MAX_LEN 8000
51-
#define DICTIONARY_ENTRY_MAX_LEN CONFIG_STORE_ENTRY_MAX_LEN
50+
#define CONFIG_STORE_INITIAL_BUF_LEN 256
51+
#define DICTIONARY_ENTRY_MAX_LEN 8000
5252

5353
// Ensure that all the things we want to use the hostcall buffer for actually
5454
// fit into the buffer.

runtime/fastly/host-api/host_api.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,7 @@ Result<std::optional<HostString>> Dict::get(std::string_view name) {
26472647
auto name_str = string_view_to_world_string(name);
26482648
fastly::fastly_world_string ret;
26492649
fastly::fastly_host_error err;
2650+
uint32_t buf_len{initial_buf_len};
26502651

26512652
ret.ptr = static_cast<uint8_t *>(cabi_malloc(DICTIONARY_ENTRY_MAX_LEN, 1));
26522653
if (!convert_result(fastly::dictionary_get(this->handle, reinterpret_cast<char *>(name_str.ptr),
@@ -2686,25 +2687,46 @@ Result<ConfigStore> ConfigStore::open(std::string_view name) {
26862687
}
26872688

26882689
Result<std::optional<HostString>> ConfigStore::get(std::string_view name) {
2690+
return this->get(name, CONFIG_STORE_INITIAL_BUF_LEN);
2691+
}
2692+
2693+
Result<std::optional<HostString>> ConfigStore::get(std::string_view name, uint32_t initial_buf_len) {
26892694
TRACE_CALL()
26902695
Result<std::optional<HostString>> res;
26912696

26922697
auto name_str = string_view_to_world_string(name);
26932698
fastly::fastly_world_string ret;
26942699
fastly::fastly_host_error err;
2695-
ret.ptr = static_cast<uint8_t *>(cabi_malloc(CONFIG_STORE_ENTRY_MAX_LEN, 1));
2696-
if (!convert_result(fastly::config_store_get(this->handle, reinterpret_cast<char *>(name_str.ptr),
2700+
uin32_t buf_len{initial_buf_len};
2701+
2702+
ret.ptr = static_cast<uint8_t *>(cabi_malloc(buf_len, 1));
2703+
2704+
bool succeeded{convert_result(fastly::config_store_get(this->handle, reinterpret_cast<char *>(name_str.ptr),
26972705
name_str.len, reinterpret_cast<char *>(ret.ptr),
2698-
CONFIG_STORE_ENTRY_MAX_LEN, &ret.len),
2699-
&err)) {
2706+
buf_len, &ret.len),
2707+
&err)}
2708+
2709+
if (!succeeded && err == FASTLY_HOST_ERROR_BUFFER_LEN) {
2710+
buf_len = ret.len;
2711+
ret.len = 0;
2712+
ret.ptr = static_cast<uint8_t *>(cabi_realloc(ret.ptr, initial_buf_len, 1, new_len));
2713+
succeeded = convert_result(fastly::config_store_get(this->handle, reinterpret_cast<char *>(name_str.ptr),
2714+
name_str.len, reinterpret_cast<char *>(ret.ptr),
2715+
buf_len, &ret.len),
2716+
&err)}
2717+
}
2718+
2719+
if (!succeeded) {
27002720
cabi_free(ret.ptr);
27012721
if (error_is_optional_none(err)) {
27022722
res.emplace(std::nullopt);
2723+
} else if (err == FASTLY_HOST_ERROR_BUFFER_LEN) {
2724+
27032725
} else {
27042726
res.emplace_err(err);
27052727
}
27062728
} else {
2707-
ret.ptr = static_cast<uint8_t *>(cabi_realloc(ret.ptr, CONFIG_STORE_ENTRY_MAX_LEN, 1, ret.len));
2729+
ret.ptr = static_cast<uint8_t *>(cabi_realloc(ret.ptr, buf_len, 1, ret.len));
27082730
res.emplace(make_host_string(ret));
27092731
}
27102732

runtime/fastly/host-api/host_api_fastly.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ class ConfigStore final {
846846
static Result<ConfigStore> open(std::string_view name);
847847

848848
Result<std::optional<HostString>> get(std::string_view name);
849+
Result<std::optional<HostString>> get(std::string_view name, uint32_t initial_buf_len);
849850
};
850851

851852
class ObjectStorePendingLookup final {

0 commit comments

Comments
 (0)