Skip to content

Commit

Permalink
Correctly replay rotated leaf logs.
Browse files Browse the repository at this point in the history
The loop was broken, it was not a loop. It is one now. The log player
will now shift ghosts from a page if a new segment's header indicates
that an exorcism has been performed.

Closes #444.
  • Loading branch information
flatheadmill committed Feb 5, 2015
1 parent cf38962 commit 4e1bc0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 9 additions & 1 deletion strata.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ Cursor.prototype.__defineGetter__('right', function () {
return this._page.right.address
})

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

Cursor.prototype.__defineGetter__('ghosts', function () {
return this._page.ghosts
})
Expand Down Expand Up @@ -1746,7 +1750,7 @@ prototype(Sheaf, 'readLeaf', cadence(function (async, page) {
}], function (fd, stat, read) {
page.rotation = rotation++
this.play(fd, stat, read, page, async())
})
})()
}))

prototype(Sheaf, 'play', cadence(function (async, fd, stat, read, page) {
Expand Down Expand Up @@ -1780,6 +1784,10 @@ prototype(Sheaf, 'play', cadence(function (async, fd, stat, read, page) {
address: entry.header[2],
key: entry.body || null
}
if (entry.header[3] == 0 && page.ghosts) {
this.splice(page, 0, 1)
page.ghosts = 0
}
page.entries++
} else {
ok(header.entry == ++page.entries, 'entry count is off')
Expand Down
15 changes: 14 additions & 1 deletion t/ghost/exorcise.t.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

require('./proof')(3, prove)
require('./proof')(5, prove)

function prove (async, assert) {
var strata = new Strata({ directory: tmp, leafSize: 3, branchSize: 3 })
Expand Down Expand Up @@ -30,5 +30,18 @@ function prove (async, assert) {
}, function (actual, expected) {
assert(actual, expected, 'after')
strata.close(async())
}, function () {
strata.open(async())
}, function () {
strata.iterator('a', async())
}, function (cursor) {
async(function () {
assert(cursor.right_, { key: 'd', address: 5 }, 'referring leaf updated')
cursor.next(async())
}, function () {
assert(cursor.get(0).key, 'd', 'key deleted')
}, function () {
cursor.unlock(async())
})
})
}

0 comments on commit 4e1bc0b

Please sign in to comment.