fixed several sync issues

This commit is contained in:
Kevin Jahns 2016-11-04 11:42:50 +01:00
parent 93c23ddc09
commit cd0cddaf35
3 changed files with 19 additions and 20 deletions

View File

@ -144,11 +144,6 @@ module.exports = function (Y/* :any */) {
this.whenSyncedListeners.push(f) this.whenSyncedListeners.push(f)
} }
} }
/*
returns false, if there is no sync target
true otherwise
*/
findNextSyncTarget () { findNextSyncTarget () {
if (this.y == null) { if (this.y == null) {
debugger debugger
@ -179,16 +174,20 @@ module.exports = function (Y/* :any */) {
}) })
}) })
} else { } else {
this.y.db.requestTransaction(function *() { if (!conn.isSynced) {
// it is crucial that isSynced is set at the time garbageCollectAfterSync is called this.y.db.requestTransaction(function *() {
conn.isSynced = true if (!conn.isSynced) {
yield* this.garbageCollectAfterSync() // it is crucial that isSynced is set at the time garbageCollectAfterSync is called
// call whensynced listeners conn.isSynced = true
for (var f of conn.whenSyncedListeners) { yield* this.garbageCollectAfterSync()
f() // call whensynced listeners
} for (var f of conn.whenSyncedListeners) {
conn.whenSyncedListeners = [] f()
}) }
conn.whenSyncedListeners = []
}
})
}
} }
} }
send (uid, message) { send (uid, message) {

View File

@ -85,7 +85,7 @@ module.exports = function (Y /* :any */) {
function garbageCollect () { function garbageCollect () {
return os.whenTransactionsFinished().then(function () { return os.whenTransactionsFinished().then(function () {
if (os.gc1.length > 0 || os.gc2.length > 0) { if (os.gc1.length > 0 || os.gc2.length > 0) {
if (!os.y.isSynced) { if (!os.y.connector.isSynced) {
console.warn('gc should be empty when not synced!') console.warn('gc should be empty when not synced!')
} }
return new Promise((resolve) => { return new Promise((resolve) => {
@ -155,7 +155,7 @@ module.exports = function (Y /* :any */) {
clearInterval(this.repairCheckIntervalHandler) clearInterval(this.repairCheckIntervalHandler)
} }
queueGarbageCollector (id) { queueGarbageCollector (id) {
if (this.y.isSynced && this.gc) { if (this.y.connector.isSynced && this.gc) {
this.gc1.push(id) this.gc1.push(id)
} }
} }
@ -221,7 +221,7 @@ module.exports = function (Y /* :any */) {
op.gc == null && op.gc == null &&
op.deleted === true && op.deleted === true &&
this.store.gc && this.store.gc &&
this.store.y.isSynced this.store.y.connector.isSynced
) { ) {
var gc = false var gc = false
if (left != null && left.deleted === true) { if (left != null && left.deleted === true) {

View File

@ -96,7 +96,7 @@ module.exports = function (Y/* :any */) {
send.push(Y.Struct[op.struct].encode(op)) send.push(Y.Struct[op.struct].encode(op))
} }
} }
if (!this.store.y.connector.isDisconnected() && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops) if (this.store.y.connector.isSynced && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
// is connected, and this is not going to be send in addOperation // is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcastOps(send) this.store.y.connector.broadcastOps(send)
} }
@ -714,7 +714,7 @@ module.exports = function (Y/* :any */) {
} }
* addOperation (op) { * addOperation (op) {
yield* this.os.put(op) yield* this.os.put(op)
if (!this.store.y.connector.isDisconnected() && this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') { if (this.store.y.connector.isSynced && this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') {
// is connected, and this is not going to be send in addOperation // is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcastOps([op]) this.store.y.connector.broadcastOps([op])
} }