disable live in level indexes while reindexing is ongoing #360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
When running deleteFeeds-then-compact-then-reindex experiments in Manyverse, I noticed that the Activity tab highlighted as "new", which didn't make sense because there was no new content added (replication was turned off).
This happened consistently, regardless of what dataset I was using (production or ssb-fixtures).
See also #306 (comment)
Problem
It turned out the problem was with leveldb live. The way that
pull-level
andlevel-post
work is by adding listeners to the leveldb EventEmitter'put'
,'del
','batch'
: https://github.com/dominictarr/level-post/blob/9021f153f159aa1d13233908ebe616f650e78f22/index.js#L44-L46Obviously, during reindexing, we use
batch
to recreate the index, and this triggers the "live" side of pull-level, which then triggers fullMentions live stream. The Activity tab in Manyverse uses fullMentions. But I also think that any other leveldb index which uses live, such as aboutSelf, would be affected in a similar way.Solution
Not the cleanest solution, but I wanted to find a solution that is general for all our leveldb indexes AND contained to ssb-db2 repo to not require each index to be updated (which is error prone).
I figured that we can just rip out all the EventEmitter listeners when the leveldb index is "reset" (which so far ONLY happens after compaction), and then wait until the index catches up with the full log, and then put those listeners back in.
1st ❌ 2nd ✔️