fixed several bugs in multi join/rejoin

This commit is contained in:
Kevin Jahns
2015-10-08 02:12:20 +02:00
parent 1ace3e3120
commit 6a13419c62
7 changed files with 142 additions and 71 deletions

View File

@@ -5,7 +5,8 @@ class DeleteStore extends Y.utils.RBTree {
constructor () {
super()
// TODO: debugggg
this.mem = []
this.mem = [];
this.memDS = [];
}
isDeleted (id) {
var n = this.findNodeWithUpperBound(id)
@@ -17,7 +18,7 @@ class DeleteStore extends Y.utils.RBTree {
returns the delete node
*/
markGarbageCollected (id) {
this.mem.push({"gc": id})
this.mem.push({"gc": id});
var n = this.markDeleted(id)
this.mem.pop()
if (!n.val.gc) {
@@ -64,7 +65,7 @@ class DeleteStore extends Y.utils.RBTree {
returns the delete node
*/
markDeleted (id) {
this.mem.push({"del": id})
this.mem.push({"del": id});
var n = this.findNodeWithUpperBound(id)
if (n != null && n.val.id[0] === id[0]) {
if (n.val.id[1] <= id[1] && id[1] < n.val.id[1] + n.val.len) {
@@ -124,6 +125,8 @@ Y.Memory = (function () {
this.ss = store.ss
this.os = store.os
this.ds = store.ds
this.memDS = store.ds.memDS; // TODO: remove
}
* checkDeleteStoreForState (state) {
var n = this.ds.findNodeWithUpperBound([state.user, state.clock])
@@ -145,6 +148,12 @@ Y.Memory = (function () {
deletions.push([user, c, gc])
}
}
var memAction = {
before: yield* this.getDeleteSet(),
applied: JSON.parse(JSON.stringify(ds))
};
for (var user in ds) {
var dv = ds[user]
var pos = 0
@@ -206,6 +215,8 @@ Y.Memory = (function () {
yield* this.deleteOperation(id)
}
}
memAction.after = yield* this.getDeleteSet();
this.memDS.push(memAction);
}
* isDeleted (id) {
return this.ds.isDeleted(id)

View File

@@ -46,7 +46,7 @@ describe('Memory', function () {
ds.markGarbageCollected(['291', 2])
expect(ds.toDeleteSet()).toEqual({'291': [[2, 1, true]], '293': [[0, 1, true], [1, 1, false]]})
})
it('Debug #2', function () {
it('Debug #3', function () {
ds.markDeleted(['581', 0])
ds.markDeleted(['581', 1])
ds.markDeleted(['580', 0])
@@ -62,7 +62,7 @@ describe('Memory', function () {
ds.markGarbageCollected(['580', 1])
expect(ds.toDeleteSet()).toEqual({'580': [[0, 1, false], [1, 1, true], [2, 1, false]], '581': [[0, 3, true]]})
})
it('Debug #2', function () {
it('Debug #4', function () {
ds.markDeleted(['544', 0])
ds.markDeleted(['543', 2])
ds.markDeleted(['544', 0])
@@ -81,5 +81,20 @@ describe('Memory', function () {
ds.markGarbageCollected(['543', 3])
expect(ds.toDeleteSet()).toEqual({'543': [[2, 3, true]], '544': [[0, 1, true], [1, 1, false], [2, 1, true]], '545': [[1, 1, false]]})
})
it('Debug #5', async(function * (done) {
var store = new Y.Memory(null, {
db: {
name: 'Memory',
gcTimeout: -1
}
})
store.requestTransaction(function * () {
yield* this.applyDeleteSet({'16': [[1, 2, false]], '17': [[0, 1, true], [1, 3, false]]})
expect(this.ds.toDeleteSet()).toEqual({'16': [[1, 2, false]], '17': [[0, 1, true], [1, 3, false]]})
yield* this.applyDeleteSet({'16': [[1, 2, false]], '17': [[0, 4, true]]})
expect(this.ds.toDeleteSet()).toEqual({'16': [[1, 2, false]], '17': [[0, 4, true]]})
done()
})
}))
})
})