From 93c23ddc09b186c080188ae24b6d2b94078ed472 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Thu, 3 Nov 2016 16:28:48 +0100 Subject: [PATCH] fixed some gc issues (unfinished) --- README.md | 2 ++ dist | 2 +- src/Connector.js | 5 ++++- src/Database.js | 20 +++++++++++++------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d45a44ea..84986e40 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,8 @@ The promise returns an instance of Y. We denote it with a lower case `y`. * Returns a promise * y.db.stopGarbageCollector() * Stop the garbage collector. Call y.db.garbageCollect() to continue garbage collection +* y.db.gc :: Boolean + * Whether gc is turned on * y.db.gcTimeout :: Number (defaults to 50000 ms) * Time interval between two garbage collect cycles * It is required that all instances exchanged all messages after two garbage collect cycles (after 100000 ms per default) diff --git a/dist b/dist index 7744993d..549ab76b 160000 --- a/dist +++ b/dist @@ -1 +1 @@ -Subproject commit 7744993dde4e1be525cccc24fd47318bfe9892f8 +Subproject commit 549ab76b4215dab2299dbcbde271c810aae2ab51 diff --git a/src/Connector.js b/src/Connector.js index f3ea1174..a93d115e 100644 --- a/src/Connector.js +++ b/src/Connector.js @@ -150,7 +150,10 @@ module.exports = function (Y/* :any */) { true otherwise */ findNextSyncTarget () { - if (this.currentSyncTarget != null || this.isSynced) { + if (this.y == null) { + debugger + } + if (this.currentSyncTarget != null) { return // "The current sync has not finished!" } diff --git a/src/Database.js b/src/Database.js index faa27c5f..bbce6ae5 100644 --- a/src/Database.js +++ b/src/Database.js @@ -75,12 +75,18 @@ module.exports = function (Y /* :any */) { } this.gc1 = [] // first stage this.gc2 = [] // second stage -> after that, remove the op - this.gcTimeout = !opts.gcTimeout ? 50000 : opts.gcTimeouts + this.gc = opts.gc == null || opts.gc + if (this.gc) { + this.gcTimeout = !opts.gcTimeout ? 50000 : opts.gcTimeout + } else { + this.gcTimeout = -1 + } + function garbageCollect () { return os.whenTransactionsFinished().then(function () { if (os.gc1.length > 0 || os.gc2.length > 0) { - if (!os.y.isConnected()) { - console.warn('gc should be empty when disconnected!') + if (!os.y.isSynced) { + console.warn('gc should be empty when not synced!') } return new Promise((resolve) => { os.requestTransaction(function * () { @@ -149,7 +155,7 @@ module.exports = function (Y /* :any */) { clearInterval(this.repairCheckIntervalHandler) } queueGarbageCollector (id) { - if (this.y.isConnected() && this.gcTimeout > 0) { + if (this.y.isSynced && this.gc) { this.gc1.push(id) } } @@ -204,7 +210,7 @@ module.exports = function (Y /* :any */) { TODO: rename this function Rulez: - * Only gc if this user is online & gcTimeout > 0 + * Only gc if this user is online & gc turned on * The most left element in a list must not be gc'd. => There is at least one element in the list @@ -214,8 +220,8 @@ module.exports = function (Y /* :any */) { if ( op.gc == null && op.deleted === true && - this.store.gcTimeout > 0 && - this.y.isConnected() + this.store.gc && + this.store.y.isSynced ) { var gc = false if (left != null && left.deleted === true) {