Skip to content

Attempt to better determine target.loadedFromSource#294

Merged
heskew merged 4 commits intomainfrom
fix/280
Apr 1, 2026
Merged

Attempt to better determine target.loadedFromSource#294
heskew merged 4 commits intomainfrom
fix/280

Conversation

@heskew
Copy link
Copy Markdown
Member

@heskew heskew commented Mar 27, 2026

Intended to resolve #280

@heskew heskew requested a review from a team as a code owner March 27, 2026 23:35
Copy link
Copy Markdown
Contributor

@cb1kenobi cb1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little hacky, but I do love a good hack :)

Comment thread unitTests/apiTests/basicREST-test.mjs Outdated
Co-authored-by: Chris Barber <chris@harperdb.io>
@heskew
Copy link
Copy Markdown
Member Author

heskew commented Mar 28, 2026

Seems a little hacky, but I do love a good hack :)

Totally. :) Seemed correct enough for this specific test.

Comment thread unitTests/apiTests/basicREST-test.mjs Outdated
assert.equal(response.status, 200);
assert(!response.headers['server-timing'].includes('miss'));
assert.equal(response.data.name, 'name3');
// loadAsInstance cache write commits in the background after the response
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does write commits in the background, but it retains a lock on the cache resolution until the write commits: https://github.com/HarperFast/harper/blob/main/resources/Table.ts#L4185
And the subsequent cache request should hit that lock here: https://github.com/HarperFast/harper/blob/main/resources/Table.ts#L3950
Which should force the second request to wait for the cached data to be written before checking the record again, at which point it should find a cached entry: https://github.com/HarperFast/harper/blob/main/resources/Table.ts#L3948 . So another miss immediately proceeding would indicate some problem (so polling would mask the problem). However...
I think maybe the problem is that it goes into the ensureLoadedFromSource/getFromSource code, which, even though it finds it in the cache, is still treated as a miss because it used
ensureLoadedFromSource to load it, and then marks it was loaded from source (a miss) here:
https://github.com/HarperFast/harper/blob/main/resources/Table.ts#L586
I think the right resolution is to pass the target through to the getFromSource so it can determine if we really ended up resolving from origin/source.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kriszyp not 100% sure on this one but it feels like it's in the right direction...

@heskew heskew marked this pull request as draft March 31, 2026 13:32
@heskew heskew changed the title Briefly poll for expected result Attempt to better determine target.loadedFromSource Apr 1, 2026
Copy link
Copy Markdown
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@heskew heskew marked this pull request as ready for review April 1, 2026 11:35
@heskew heskew merged commit 6538412 into main Apr 1, 2026
22 checks passed
@heskew heskew deleted the fix/280 branch April 1, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: 'invalidate and get from cache and check headers with loadAsInstance' in basicREST-test

3 participants