-
Notifications
You must be signed in to change notification settings - Fork 189
rocksdb: commit overwrites full state #587
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
Merged
Merged
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e3f5828
commit acquires lock directly
chm-diederichs e42acdb
check conditions after acquiring lock
chm-diederichs e3279a4
update dependency in place and delete blocks
chm-diederichs 081e489
memory overlay has head as dependency
chm-diederichs 5d2b300
support snapshots
chm-diederichs e07c718
update dependency on truncate and clear if necessary
chm-diederichs d3fd4bc
add memory overlay test
chm-diederichs c9f1329
fix put
chm-diederichs 48a392c
implement memory overlay block deletion
chm-diederichs be252c6
add memory overlay block deletion tests
chm-diederichs 6f1d030
move tip list to abstraction and add tests
chm-diederichs 8847def
treeNodes use tip list
chm-diederichs 8892730
move memory overlay to hypercore-on-the-rocks
chm-diederichs dfe556e
rename peak to peek
chm-diederichs 717fd18
use dependencies to compute flushed length
chm-diederichs a23a3ba
add overwrite option to commit
chm-diederichs 4d53643
bit-interlude supports multiple deletions
chm-diederichs b5effbf
make core compat with bit interlude changes
chm-diederichs 74db1ba
add explicit state overwrite method
chm-diederichs 26b771e
memory overlay always has flushedLength as -1
chm-diederichs d418634
core.js commit method uses overwrite
chm-diederichs 93d947f
commit writes data directly
chm-diederichs b92d09f
delete reconcile method
chm-diederichs 65a18e5
copyPrologue uses bitfield constants
chm-diederichs a166e37
signature is verified against committed tree
chm-diederichs 28afbcb
use flat-tree patch method
chm-diederichs c322b87
Merge branch 'rocksdb-commit-fill-tree' into rocksdb-commit-updates-d…
chm-diederichs fbe4a66
Merge branch 'rocksdb' into rocksdb-commit-updates-dependency
chm-diederichs 8646195
snapshotLength is -1 for default
chm-diederichs f0136d8
review from @mafintosh
chm-diederichs 0b154a4
only one call to splice
chm-diederichs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,16 @@ | ||
| const assert = require('nanoassert') | ||
| const b4a = require('b4a') | ||
| const quickbit = require('./compat').quickbit | ||
|
|
||
| module.exports = class BitInterlude { | ||
| constructor (bitfield) { | ||
| this.drop = false | ||
| this.bitfield = bitfield | ||
| this.ranges = [] | ||
| } | ||
|
|
||
| contiguousLength (from) { | ||
| if (this.drop && this.ranges.length > 0 && this.ranges[0].start < from) { | ||
| return this.ranges[0].start | ||
| for (const r of this.ranges) { | ||
| if (r.start > from) break | ||
| if (!r.value && r.start <= from) return r.start | ||
| } | ||
|
|
||
| // TODO: be smarter | ||
|
|
@@ -38,25 +37,35 @@ module.exports = class BitInterlude { | |
| continue | ||
| } | ||
|
|
||
| return this.drop === false | ||
| return r.value | ||
| } | ||
|
|
||
| return this.bitfield.get(index) | ||
| } | ||
|
|
||
| setRange (start, end, value) { | ||
| assert(this.drop !== value || this.ranges.length === 0) | ||
| assert(value === true || this.ranges.length === 0) | ||
|
|
||
| this.drop = value === false | ||
| if (start === end) return | ||
|
|
||
| let r = null | ||
|
|
||
| for (let i = 0; i < this.ranges.length; i++) { | ||
| r = this.ranges[i] | ||
|
|
||
| // if already inside, stop | ||
| if (r.start <= start && end <= r.end) return | ||
| if (r.start <= start && end <= r.end) { | ||
| if (value === r.value) return | ||
|
|
||
| const lower = { start: r.start, end: start, value: r.value } | ||
| const upper = { start: end, end: r.end, value: r.value } | ||
|
|
||
| let remove = 1 | ||
|
|
||
| if (lower.start < lower.end) this.ranges.splice(i++, remove--, lower) | ||
| this.ranges.splice(i++, remove, { start, end, value }) | ||
| if (upper.start < upper.end) this.ranges.splice(i, 0, upper) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| // we wanna overun the interval | ||
| if (start > r.end) { | ||
|
|
@@ -65,25 +74,32 @@ module.exports = class BitInterlude { | |
|
|
||
| // we overran but this interval is ending after us, move it back | ||
| if (end >= r.start && end <= r.end) { | ||
| r.start = start | ||
| r.start = r.value === value ? start : end | ||
| if (r.value !== value) this.ranges.splice(i, 0, { start, end, value }) | ||
| return | ||
| } | ||
|
|
||
| // we overran but our start is contained in this interval, move start back | ||
| if (start >= r.start && start <= r.end) { | ||
| if (r.value !== value) { | ||
| this.ranges.splice(++i, 0, { start, end, value }) | ||
| r.end = start | ||
| return | ||
| } | ||
|
|
||
| start = r.start | ||
| } | ||
|
|
||
| let remove = 0 | ||
|
|
||
| for (let j = i; j < this.ranges.length; j++) { | ||
| const n = this.ranges[j] | ||
| if (n.start > end) break | ||
| if (n.start > end || n.value !== value) break | ||
| if (n.start <= end && n.end > end) end = n.end | ||
| remove++ | ||
| } | ||
|
|
||
| this.ranges.splice(i, remove, { start, end }) | ||
| this.ranges.splice(i, remove, { start, end, value }) | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -97,41 +113,49 @@ module.exports = class BitInterlude { | |
| if (r.end > start) return | ||
| } | ||
|
|
||
| this.ranges.push({ start, end }) | ||
| this.ranges.push({ start, end, value }) | ||
| } | ||
|
|
||
| flush (writer, debug) { | ||
| if (!this.ranges.length) return { ranges: [], drop: this.drop } | ||
| if (!this.ranges.length) return [] | ||
|
|
||
| let index = this.ranges[0].start | ||
| const final = this.ranges[this.ranges.length - 1].end | ||
|
|
||
| let i = 0 | ||
|
|
||
| while (index < final) { | ||
| const page = this.bitfield.getPage(index, this.drop === false) | ||
| const buf = b4a.allocUnsafe(page.bitfield.byteLength) | ||
| const page = this.bitfield.getBitfield(index) // read only | ||
| const pageIndex = page ? page.index : this.bitfield.getPageIndex(index) | ||
|
|
||
| const buf = b4a.allocUnsafe(this.bitfield.getPageByteLength()) | ||
|
|
||
| const view = new DataView( | ||
| buf.buffer, | ||
| buf.byteOffset, | ||
| buf.byteLength | ||
| ) | ||
|
|
||
| for (let i = 0; i < page.bitfield.length; i++) { | ||
| view.setUint32(i * 4, page.bitfield[i], true) | ||
| if (page) { | ||
| for (let i = 0; i < page.bitfield.length; i++) { | ||
| view.setUint32(i * 4, page.bitfield[i], true) | ||
| } | ||
| } | ||
|
|
||
| const last = (page.index + 1) * (buf.byteLength << 3) | ||
| const offset = page.index * buf.byteLength << 3 | ||
| const last = (pageIndex + 1) * (buf.byteLength << 3) | ||
| const offset = pageIndex * buf.byteLength << 3 | ||
|
||
|
|
||
| let hasValue = false | ||
|
|
||
| while (i < this.ranges.length) { | ||
| const { start, end } = this.ranges[i] | ||
| const { start, end, value } = this.ranges[i] | ||
|
|
||
| if (!hasValue && value) hasValue = true | ||
|
|
||
| const from = start < index ? index : start | ||
| const to = end < last ? end : last | ||
|
|
||
| quickbit.fill(buf, this.drop === false, from - offset, to - offset) | ||
| quickbit.fill(buf, value, from - offset, to - offset) | ||
|
|
||
| index = to | ||
|
|
||
|
|
@@ -140,12 +164,9 @@ module.exports = class BitInterlude { | |
| i++ | ||
| } | ||
|
|
||
| writer.putBitfieldPage(page.index, buf) | ||
| if (page || hasValue) writer.putBitfieldPage(pageIndex, buf) | ||
| } | ||
|
|
||
| return { | ||
| ranges: this.ranges, | ||
| drop: this.drop | ||
| } | ||
| return this.ranges | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
the ++ is sus to me, we use i again below but normally you'd i-- it as you are removing from the array
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.
only one of them removes from the array, but they all add to it, so it ends up being: