This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 683
Fixes TypeError: Cannot read property 'pop' of undefined
#530
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 similar comment
nicholasjpaterno
approved these changes
Jan 14, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -3,6 +3,8 @@ var AbstractLevelDOWN = require("abstract-leveldown").AbstractLevelDOWN; | |||
var async = require("async"); | |||
var fs = require("fs"); | |||
var path = require("path"); | |||
var tmp = require("tmp"); | |||
tmp.setGracefulCleanup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Comment on lines
+20
to
+39
const accessQueue = { | ||
next: (lKey) => { | ||
const cont = accessQueue.cache[lKey].shift(); | ||
if (cont) { | ||
cont(); | ||
} else { | ||
delete accessQueue.cache[lKey]; | ||
} | ||
}, | ||
execute: (lKey, callback) => { | ||
let cache = accessQueue.cache[lKey]; | ||
if (cache) { | ||
cache.push(callback); | ||
} else { | ||
accessQueue.cache[lKey] = []; | ||
callback(); | ||
} | ||
}, | ||
cache: {} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on the abstraction. Much cleaner
davidmurdoch
added a commit
that referenced
this pull request
Jan 16, 2020
1 task
This was referenced Jun 6, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This fixes an issue caused by writing AND reading the same key multiple times simultaneously. Sometimes the read operation would end up reading the value as 0 bytes due to the way writes are performed in node. To fix this, we implemented a queue so only a single read or write operation can occur at a time for each key; basically an in-memory lock.
Additionally, during testing we found that it was possible for a write operation to fail due to program termination. This failure would sometimes cause the key to exist but contain 0 bytes (which is always invalid). To fix this we write to a temp file, and only if it works do we move this temp file to its correct key location. This prevents early termination from writing partial/empty values.
Of course, all this will eventually be for nothing as we are migrating the db to actual an leveldb implementation that doesn't use a separate file for every key Soon(TM).