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

[DONT_MERGE] Rocksdb storage #527

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
daa4766
wip
mafintosh May 31, 2024
5f42215
`rocksdb` : add byte helpers and use atomic batches (#526)
chm-diederichs Jun 21, 2024
6067dd5
force latest for now
mafintosh Jun 21, 2024
45e471d
addTreeNode renamed to putTreeNode
chm-diederichs Jun 21, 2024
f2d6765
remove batch id from api (#530)
chm-diederichs Jun 26, 2024
b94ce17
rocksdb: move bitfield to db (#529)
chm-diederichs Jun 26, 2024
e4ea11a
teardown storage in test helpers
chm-diederichs Jun 26, 2024
0134961
rocksdb: remove oplog and add block store API (#531)
chm-diederichs Jun 27, 2024
8c006e4
rocksdb: update index.js (#533)
chm-diederichs Jun 28, 2024
b6f4396
teardown cores implicitly in tests
mafintosh Jun 28, 2024
822c56f
keep core.header.tree around for compat (#532)
chm-diederichs Jun 28, 2024
452e604
rocksdb: implement full API apart from batches (#537)
chm-diederichs Jul 30, 2024
2016ec0
fixup typos
chm-diederichs Jul 30, 2024
596b0db
Merge branch 'main' into rocksdb
chm-diederichs Jul 30, 2024
342c1df
rocksdb: copy prologue (#549)
chm-diederichs Aug 2, 2024
8c5feb9
rocksdb: add named sessions (#539)
chm-diederichs Sep 5, 2024
3cfc609
Get skips bitfield check (#559)
mafintosh Sep 6, 2024
cade0cd
rocksdb: add db snapshots (#562)
chm-diederichs Sep 7, 2024
16d2d26
remove the cache, we do not use anymore (#560)
mafintosh Sep 7, 2024
6c213d7
add test for reopening writable core
chm-diederichs Sep 10, 2024
5516503
`rocksdb`: merge main (#564)
chm-diederichs Sep 11, 2024
79e9236
always close state first
chm-diederichs Sep 11, 2024
6a6ae78
pass opts to default storage
chm-diederichs Sep 17, 2024
8e22446
Fix activity count (#568)
mafintosh Sep 16, 2024
0e49149
`rocksdb`: avoid duplicate block download (#569)
chm-diederichs Sep 17, 2024
32b6b13
get user data from state storage
chm-diederichs Sep 17, 2024
af0e7dc
tree may have been updated beneath us
chm-diederichs Sep 17, 2024
0e555c9
fix reorg and teardown active batches
mafintosh Sep 23, 2024
cb077a8
initial support for memory overlays (#563)
mafintosh Sep 23, 2024
d9de824
dont use storage helpers
mafintosh Sep 23, 2024
edd504c
use latest storage
mafintosh Sep 24, 2024
27e28dd
internalise snapshots
mafintosh Sep 24, 2024
d8a78e9
remove all memory view branches
mafintosh Sep 24, 2024
f946075
rocksdb: add force close option (#570)
chm-diederichs Sep 25, 2024
1f1aef8
peer checks replicator state before any db reads
chm-diederichs Sep 27, 2024
f9e95b1
revert previous commit
chm-diederichs Sep 27, 2024
e41ffbc
do not process any data after destroy
chm-diederichs Oct 1, 2024
b0b0e10
upstream fix from main
chm-diederichs Oct 1, 2024
f794da1
missing core update on upgrade
chm-diederichs Oct 2, 2024
2d68418
Merge branch 'main' into rocksdb
chm-diederichs Oct 7, 2024
0ddab83
use storage idle helper
chm-diederichs Oct 7, 2024
f4047e5
rocksdb: only create single read batch in bg call (#578)
chm-diederichs Oct 7, 2024
1dd49ed
use minimum shared length (#577)
chm-diederichs Oct 7, 2024
338cb58
rocksdb: commit acquires lock (#576)
chm-diederichs Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 137 additions & 112 deletions index.js

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions lib/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const b4a = require('b4a')
// this is optimised for speed over mem atm
// can be tweaked in the future

module.exports = async function auditCore (core) {
module.exports = async function auditCore (core, update) {
const corrections = {
tree: 0,
blocks: 0
Expand Down Expand Up @@ -48,10 +48,6 @@ module.exports = async function auditCore (core) {
if (rightNode.size) clearNode(rightNode)
}

if (corrections.tree) {
core.tree.cache.clear()
}

let i = 0
let nextOffset = -1
while (i < length) {
Expand All @@ -69,7 +65,7 @@ module.exports = async function auditCore (core) {
try {
nextOffset = await core.tree.byteOffset(i * 2)
} catch {
core._setBitfield(i, false)
update.bitfield.set(i, false)
corrections.blocks++
i++
continue
Expand All @@ -83,7 +79,7 @@ module.exports = async function auditCore (core) {
nextOffset += blk.byteLength

if (!b4a.equals(hash, node.hash)) {
core._setBitfield(i, false)
update.bitfield.set(i, false)
corrections.blocks++
}

Expand Down
151 changes: 151 additions & 0 deletions lib/bit-interlude.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
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
}

// TODO: be smarter
while (this.get(from) === true) from++
return from
}

get (index) {
let start = 0
let end = this.ranges.length

while (start < end) {
const mid = (start + end) >> 1
const r = this.ranges[mid]

if (index < r.start) {
end = mid
continue
}

if (index >= r.end) {
if (mid === start) break
start = mid
continue
}

return this.drop === false
}

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

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

// we wanna overun the interval
if (start > r.end) {
continue
}

// we overran but this interval is ending after us, move it back
if (end >= r.start && end <= r.end) {
r.start = start
return
}

// we overran but our start is contained in this interval, move start back
if (start >= r.start && start <= r.end) {
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.end > end) end = n.end
remove++
}

this.ranges.splice(i, remove, { start, end })
return
}

if (r !== null) {
if (start <= r.end && end > r.end) {
r.end = end
return
}

// we never
if (r.end > start) return
}

this.ranges.push({ start, end })
}

flush (writer, debug) {
if (!this.ranges.length) return { ranges: [], drop: this.drop }

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 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)
}

const last = (page.index + 1) * (buf.byteLength << 3)
const offset = page.index * buf.byteLength << 3

while (i < this.ranges.length) {
const { start, end } = this.ranges[i]

const from = start < index ? index : start
const to = end < last ? end : last

quickbit.fill(buf, this.drop === false, from - offset, to - offset)

index = to

if (to === last) break

i++
}

writer.putBitfieldPage(page.index, buf)
}

return {
ranges: this.ranges,
drop: this.drop
}
}
}
Loading
Loading