Skip to content
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

new API ensureLoaded() #48

Merged
merged 1 commit into from
Sep 16, 2021
Merged

new API ensureLoaded() #48

merged 1 commit into from
Sep 16, 2021

Conversation

staltz
Copy link
Member

@staltz staltz commented Sep 16, 2021

Context

ssb-meta-feeds findByIdSync is used in the new ssb-ebt ssbc/ssb-ebt#52 which in turn is used in ssbc/ssb-replication-scheduler#5 .

Problem

We bumped into a race condition where there are two pull.drains on meta feed messages: (A) one in ssb-meta-feeds feeds-lookup.js (to keep track of the "details" object associated which each (foreign or local) subfeed ID) and (B) another one in ssb-replication-scheduler to trigger the replication of a subfeed. We realized that the processing in (A) for a specific subfeed ID must happen before the respective processing in (B) because information calculated in (A) will be needed by ssb-ebt once (B) calls into ssb-ebt APIs.

Solution

New API ensureLoaded(feedId, cb) similar to loadState(cb), but for a specific feedId.

While loadState(cb) just kicks off the pull.drain for all possible meta feed msgs, ensureLoaded() will wait until the specific feedId has been processed by the next updateLookup().

This should be one of the pieces of the puzzle to solve the Problem described above, we will also need a few changes in ssb-ebt to fully solve it.

@staltz staltz requested a review from arj03 September 16, 2021 13:49
@@ -136,7 +153,14 @@ exports.init = function (sbot, config) {
loadStateRequested = true
loadState()
}
stateLoadedP.promise.then(cb)
if (cb) stateLoadedP.promise.then(cb)
Copy link
Member

Choose a reason for hiding this comment

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

nice catch

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah there was that

Copy link
Member

@arj03 arj03 left a comment

Choose a reason for hiding this comment

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

Looks good. The only thing I was wondering is if stateLoadedP.promise.then in flush would be better int he beginning, but I think it should be ok where it is.

@staltz
Copy link
Member Author

staltz commented Sep 16, 2021

That one is for the case that we call ensureLoaded before loadState is done, we don't want the cbs to be called

@staltz staltz merged commit e6d385e into master Sep 16, 2021
@staltz staltz deleted the ensure-loaded branch September 16, 2021 14:20
@arj03
Copy link
Member

arj03 commented Sep 16, 2021

Right, should work either way I think

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.

2 participants