fixed some gc issues (unfinished)
This commit is contained in:
parent
480dfdfb77
commit
93c23ddc09
@ -210,6 +210,8 @@ The promise returns an instance of Y. We denote it with a lower case `y`.
|
|||||||
* Returns a promise
|
* Returns a promise
|
||||||
* y.db.stopGarbageCollector()
|
* y.db.stopGarbageCollector()
|
||||||
* Stop the garbage collector. Call y.db.garbageCollect() to continue garbage collection
|
* 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)
|
* y.db.gcTimeout :: Number (defaults to 50000 ms)
|
||||||
* Time interval between two garbage collect cycles
|
* 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)
|
* It is required that all instances exchanged all messages after two garbage collect cycles (after 100000 ms per default)
|
||||||
|
2
dist
2
dist
@ -1 +1 @@
|
|||||||
Subproject commit 7744993dde4e1be525cccc24fd47318bfe9892f8
|
Subproject commit 549ab76b4215dab2299dbcbde271c810aae2ab51
|
@ -150,7 +150,10 @@ module.exports = function (Y/* :any */) {
|
|||||||
true otherwise
|
true otherwise
|
||||||
*/
|
*/
|
||||||
findNextSyncTarget () {
|
findNextSyncTarget () {
|
||||||
if (this.currentSyncTarget != null || this.isSynced) {
|
if (this.y == null) {
|
||||||
|
debugger
|
||||||
|
}
|
||||||
|
if (this.currentSyncTarget != null) {
|
||||||
return // "The current sync has not finished!"
|
return // "The current sync has not finished!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +75,18 @@ module.exports = function (Y /* :any */) {
|
|||||||
}
|
}
|
||||||
this.gc1 = [] // first stage
|
this.gc1 = [] // first stage
|
||||||
this.gc2 = [] // second stage -> after that, remove the op
|
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 () {
|
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.isConnected()) {
|
if (!os.y.isSynced) {
|
||||||
console.warn('gc should be empty when disconnected!')
|
console.warn('gc should be empty when not synced!')
|
||||||
}
|
}
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
os.requestTransaction(function * () {
|
os.requestTransaction(function * () {
|
||||||
@ -149,7 +155,7 @@ module.exports = function (Y /* :any */) {
|
|||||||
clearInterval(this.repairCheckIntervalHandler)
|
clearInterval(this.repairCheckIntervalHandler)
|
||||||
}
|
}
|
||||||
queueGarbageCollector (id) {
|
queueGarbageCollector (id) {
|
||||||
if (this.y.isConnected() && this.gcTimeout > 0) {
|
if (this.y.isSynced && this.gc) {
|
||||||
this.gc1.push(id)
|
this.gc1.push(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +210,7 @@ module.exports = function (Y /* :any */) {
|
|||||||
TODO: rename this function
|
TODO: rename this function
|
||||||
|
|
||||||
Rulez:
|
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.
|
* The most left element in a list must not be gc'd.
|
||||||
=> There is at least one element in the list
|
=> There is at least one element in the list
|
||||||
|
|
||||||
@ -214,8 +220,8 @@ module.exports = function (Y /* :any */) {
|
|||||||
if (
|
if (
|
||||||
op.gc == null &&
|
op.gc == null &&
|
||||||
op.deleted === true &&
|
op.deleted === true &&
|
||||||
this.store.gcTimeout > 0 &&
|
this.store.gc &&
|
||||||
this.y.isConnected()
|
this.store.y.isSynced
|
||||||
) {
|
) {
|
||||||
var gc = false
|
var gc = false
|
||||||
if (left != null && left.deleted === true) {
|
if (left != null && left.deleted === true) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user