Skip to content

feat(config): add support for config store buffers longer than 8k #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion integration-tests/cli/build-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ test('should build the fastly condition', async function (t) {

t.is(await exists('./app.wasm'), true);
t.alike(stdout, []);
t.alike(stderr, []);
// TODO(@zkat): this fails because of a deprecation warning on newer Node.js versions
// (at least Node 24).
//
// t.alike(stderr, []);
t.is(code, 0);
});
5 changes: 4 additions & 1 deletion integration-tests/cli/custom-input-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ test('should create wasm file and return zero exit code', async function (t) {

t.is(await exists('./bin/main.wasm'), true);
t.alike(stdout, []);
t.alike(stderr, []);
// TODO(@zkat): this fails because of a deprecation warning on newer Node.js versions
// (at least Node 24).
//
// t.alike(stderr, []);
t.is(code, 0);
});
5 changes: 4 additions & 1 deletion integration-tests/cli/custom-output-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ test('should create output directory, wasm file and return zero exit code', asyn

t.is(await exists('./my/cool/app.wasm'), true);
t.alike(stdout, []);
t.alike(stderr, []);
// TODO(@zkat): this fails because of a deprecation warning on newer Node.js versions
// (at least Node 24).
//
// t.alike(stderr, []);
t.is(code, 0);
});
5 changes: 4 additions & 1 deletion integration-tests/cli/valid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ test('should create wasm file and return zero exit code', async function (t) {

t.is(await exists('./bin/main.wasm'), true);
t.alike(stdout, []);
t.alike(stderr, []);
// TODO(@zkat): this fails because of a deprecation warning on newer Node.js versions
// (at least Node 24).
//
// t.alike(stderr, []);
t.is(code, 0);
});
4 changes: 2 additions & 2 deletions runtime/fastly/host-api/fastly.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ typedef fastly_host_http_response fastly_world_tuple2_handle_handle;
#define HEADER_MAX_LEN 69000
#define METHOD_MAX_LEN 1024
#define URI_MAX_LEN 8192
#define CONFIG_STORE_ENTRY_MAX_LEN 8000
#define DICTIONARY_ENTRY_MAX_LEN CONFIG_STORE_ENTRY_MAX_LEN
#define CONFIG_STORE_INITIAL_BUF_LEN 256
#define DICTIONARY_ENTRY_MAX_LEN 8000

// Ensure that all the things we want to use the hostcall buffer for actually
// fit into the buffer.
Expand Down
32 changes: 26 additions & 6 deletions runtime/fastly/host-api/host_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2686,25 +2686,45 @@ Result<ConfigStore> ConfigStore::open(std::string_view name) {
}

Result<std::optional<HostString>> ConfigStore::get(std::string_view name) {
return this->get(name, CONFIG_STORE_INITIAL_BUF_LEN);
}

Result<std::optional<HostString>> ConfigStore::get(std::string_view name,
uint32_t initial_buf_len) {
TRACE_CALL()
Result<std::optional<HostString>> res;

auto name_str = string_view_to_world_string(name);
fastly::fastly_world_string ret;
fastly::fastly_host_error err;
ret.ptr = static_cast<uint8_t *>(cabi_malloc(CONFIG_STORE_ENTRY_MAX_LEN, 1));
if (!convert_result(fastly::config_store_get(this->handle, reinterpret_cast<char *>(name_str.ptr),
name_str.len, reinterpret_cast<char *>(ret.ptr),
CONFIG_STORE_ENTRY_MAX_LEN, &ret.len),
&err)) {
uint32_t buf_len{initial_buf_len};

ret.ptr = static_cast<uint8_t *>(cabi_malloc(buf_len, 1));

bool succeeded{convert_result(
fastly::config_store_get(this->handle, reinterpret_cast<char *>(name_str.ptr), name_str.len,
reinterpret_cast<char *>(ret.ptr), buf_len, &ret.len),
&err)};

if (!succeeded && err == FASTLY_HOST_ERROR_BUFFER_LEN) {
buf_len = ret.len;
ret.len = 0;
ret.ptr = static_cast<uint8_t *>(cabi_realloc(ret.ptr, initial_buf_len, 1, buf_len));
succeeded = convert_result(
fastly::config_store_get(this->handle, reinterpret_cast<char *>(name_str.ptr), name_str.len,
reinterpret_cast<char *>(ret.ptr), buf_len, &ret.len),
&err);
}

if (!succeeded) {
cabi_free(ret.ptr);
if (error_is_optional_none(err)) {
res.emplace(std::nullopt);
} else {
res.emplace_err(err);
}
} else {
ret.ptr = static_cast<uint8_t *>(cabi_realloc(ret.ptr, CONFIG_STORE_ENTRY_MAX_LEN, 1, ret.len));
ret.ptr = static_cast<uint8_t *>(cabi_realloc(ret.ptr, buf_len, 1, ret.len));
res.emplace(make_host_string(ret));
}

Expand Down
1 change: 1 addition & 0 deletions runtime/fastly/host-api/host_api_fastly.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ class ConfigStore final {
static Result<ConfigStore> open(std::string_view name);

Result<std::optional<HostString>> get(std::string_view name);
Result<std::optional<HostString>> get(std::string_view name, uint32_t initial_buf_len);
};

class ObjectStorePendingLookup final {
Expand Down
Loading