Skip to content

Commit

Permalink
refactor(abi/fastly): config store buffer adapts as best it can
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-dub committed Jun 14, 2024
1 parent 1f82a09 commit 4eb199f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions internal/abi/fastly/hostcalls_guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2487,12 +2487,13 @@ alloc:
status := fastlyDictionaryGet(
d.h,
keyBuffer.Data, keyBuffer.Len,
prim.ToPointer(buf.Char8Pointer()),
buf.Cap(),
prim.ToPointer(buf.Char8Pointer()), buf.Cap(),
prim.ToPointer(buf.NPointer()),
)
if status == FastlyStatusBufLen && buf.NValue() > 0 {
n = int(buf.NValue())
// The Dictionary API cannot return the needed size with this error.
// Instead of perfectly adapting, we allocate the maximum length a value can have.
if status == FastlyStatusBufLen && n < dictionaryValueMaxLen {
n = dictionaryValueMaxLen
goto alloc // goto saves having to allocate a function closure and avoids having to duplicate the hostcall
}

Expand Down Expand Up @@ -2521,8 +2522,7 @@ func (d *Dictionary) Has(key string) (bool, error) {
if err := fastlyDictionaryGet(
d.h,
keyBuffer.Data, keyBuffer.Len,
prim.NullChar8Pointer(),
0,
prim.NullChar8Pointer(), 0,
prim.ToPointer(&npointer),
); err != FastlyStatusOK {
if err == FastlyStatusBufLen {
Expand Down
5 changes: 3 additions & 2 deletions internal/abi/fastly/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ func IsFastlyError(err error) (FastlyStatus, bool) {
}

const (
ipBufLen = 16 // known size for IP address buffers
dnsBufLen = 256 // known size for "DNS" values, enough to hold the longest possible hostname or domain name
ipBufLen = 16 // known size for IP address buffers
dnsBufLen = 256 // known size for "DNS" values, enough to hold the longest possible hostname or domain name
dictionaryValueMaxLen = 8192 // known size for maximum config store value https://docs.fastly.com/en/guides/about-edge-dictionaries#limitations-and-considerations

DefaultSmallBufLen = 128 // default size for "typically-small" values with variable sizes: HTTP methods, header names, tls protocol names, cipher suites
DefaultMediumBufLen = 1024 // default size for values between small and large with variable sizes
Expand Down

0 comments on commit 4eb199f

Please sign in to comment.