Skip to content

Commit

Permalink
Write keys to leaf page.
Browse files Browse the repository at this point in the history
Still not maintaining them correctly, so they cannot really be trusted.

See #413.
  • Loading branch information
flatheadmill committed Feb 5, 2015
1 parent 010f571 commit 2eccd81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
29 changes: 19 additions & 10 deletions strata.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ prototype(Cursor, 'next', cadence(function (async) {
}

async(function () {
this._locker.lock(this._page.right, this.exclusive, async())
this._locker.lock(this._page.right.address, this.exclusive, async())
}, function (next) {
this._locker.unlock(this._page)

Expand All @@ -204,11 +204,11 @@ prototype(Cursor, 'indexOf', cadence(function (async, key) {
var unambiguous
unambiguous = -1 < index
|| ~ index < this._page.items.length
|| ! this._page.right
|| ! this._page.right.address
|| this._searchKey.length && this._sheaf.comparator(this._searchKey[0], key) == 0
if (!unambiguous) async(function () {
if (!this._rightLeafKey) async(function () {
this._locker.lock(this._page.right, false, async())
this._locker.lock(this._page.right.address, false, async())
}, function (rightLeafPage) {
async([function () {
this._locker.unlock(rightLeafPage)
Expand Down Expand Up @@ -258,7 +258,7 @@ Cursor.prototype.__defineGetter__('address', function () {
})

Cursor.prototype.__defineGetter__('right', function () {
return this._page.right
return this._page.right.address
})

Cursor.prototype.__defineGetter__('ghosts', function () {
Expand Down Expand Up @@ -494,7 +494,7 @@ prototype(Sheaf, '_node', cadence(function (async, locker, page) {
var node = {
key: entry.key,
address: page.address,
rightAddress: page.right,
rightAddress: page.right.address,
length: page.items.length - page.ghosts
}
this.ordered[node.address] = node
Expand Down Expand Up @@ -738,7 +738,6 @@ prototype(Sheaf, 'splitLeafAndUnlock', cadence(function (async, address, key, gh
encached.push(page)

page.right = right
right = page.address

length = remainder-- > 0 ? records + 1 : records
offset = split.items.length - length
Expand All @@ -759,6 +758,11 @@ prototype(Sheaf, 'splitLeafAndUnlock', cadence(function (async, address, key, gh

index++
}

right = {
address: page.address,
key: page.items[0].key
}
}, function () {
this.splice(split, offset, length)

Expand Down Expand Up @@ -1439,7 +1443,7 @@ Sheaf.prototype.createLeaf = function (override) {
entries: 0,
ghosts: 0,
items: [],
right: 0,
right: { address: 0, key: null },
queue: this.sequester.createQueue()
}, override, 0)
}
Expand Down Expand Up @@ -1498,8 +1502,10 @@ Sheaf.prototype.writeDelete = function (queue, page, index, callback) {
}

Sheaf.prototype.writeHeader = function (queue, page) {
var header = [ ++page.entries, 0, page.right ]
return this.writeEntry({ queue: queue, page: page, header: header, type: 'header' })
var header = [ ++page.entries, 0, page.right.address ]
return this.writeEntry({
queue: queue, page: page, header: header, isKey: true, body: page.right.key
})
}

prototype(Sheaf, 'io', cadence(function (async, direction, filename) {
Expand Down Expand Up @@ -1595,7 +1601,10 @@ prototype(Sheaf, 'replay', cadence(function (async, fd, stat, read, page, positi
var entry = this.readEntry(slice.slice(offset, offset + length), !leaf)
var header = this.readHeader(entry)
if (entry.header[1] == 0) {
page.right = entry.header[2]
page.right = {
address: entry.header[2],
key: entry.body || null
}
page.entries++
} else {
ok(header.entry == ++page.entries, 'entry count is off')
Expand Down
5 changes: 4 additions & 1 deletion t/proof.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ function directivize (json) {
position += length
return record
})
directory[address].unshift({ header: [ 1, 0, object.right || 0 ]})
directory[address].unshift({
header: [ 1, 0, object.right || 0 ],
body: object.right ? key(object.right) : null
})
}
}

Expand Down

0 comments on commit 2eccd81

Please sign in to comment.