fix the "gc state" warning

This commit is contained in:
Kevin Jahns 2017-06-27 02:07:03 +02:00
parent 24facaab09
commit 409a9414f1
3 changed files with 26 additions and 13 deletions

View File

@ -202,7 +202,8 @@ export default function extendConnector (Y/* :any */) {
if (!conn.isSynced) {
// it is crucial that isSynced is set at the time garbageCollectAfterSync is called
conn.isSynced = true
yield * this.garbageCollectAfterSync()
// It is safer to remove this!
// TODO: remove: yield * this.garbageCollectAfterSync()
// call whensynced listeners
for (var f of conn.whenSyncedListeners) {
f()
@ -343,7 +344,8 @@ export default function extendConnector (Y/* :any */) {
}
defer.resolve()
})
/* then apply ds
/*
then apply ds
db.whenTransactionsFinished().then(() => {
db.requestTransaction(function * () {
yield * this.applyDeleteSet(m.deleteSet)

View File

@ -39,6 +39,7 @@ export default function extendDatabase (Y /* :any */) {
*/
constructor (y, opts) {
this.y = y
opts.gc = opts.gc === true
this.dbOpts = opts
var os = this
this.userId = null
@ -121,7 +122,7 @@ export default function extendDatabase (Y /* :any */) {
this.startRepairCheck()
}
startGarbageCollector () {
this.gc = this.dbOpts.gc == null || this.dbOpts.gc
this.gc = this.dbOpts.gc
if (this.gc) {
this.gcTimeout = !this.dbOpts.gcTimeout ? 50000 : this.dbOpts.gcTimeout
} else {

View File

@ -17,7 +17,25 @@ export async function garbageCollectUsers (t, users) {
await Promise.all(users.map(u => u.db.emptyGarbageCollector()))
}
/*
* 1. reconnect and flush all
* 2. user 0 gc
* 3. get type content
* 4. disconnect & reconnect all (so gc is propagated)
* 5. compare os, ds, ss
*/
export async function compareUsers (t, users) {
await Promise.all(users.map(u => u.reconnect()))
if (users[0].connector.testRoom == null) {
await wait(100)
}
await flushAll(t, users)
await users[0].db.garbageCollect()
await users[0].db.garbageCollect()
var userTypeContents = users.map(u => u.share.array._content.map(c => c.val || JSON.stringify(c.type)))
// disconnect all except user 0
await Promise.all(users.slice(1).map(async u =>
u.disconnect()
@ -27,9 +45,6 @@ export async function compareUsers (t, users) {
}
// reconnect all
await Promise.all(users.map(u => u.reconnect()))
if (users[0].connector.testRoom != null) {
// flush for sync if test-connector
}
if (users[0].connector.testRoom == null) {
await wait(100)
}
@ -40,13 +55,8 @@ export async function compareUsers (t, users) {
})
))
await flushAll(t, users)
// types must be equal before garbage collect
var userTypeContents = users.map(u => u.share.array._content.map(c => c.val || JSON.stringify(c.type)))
var data = await Promise.all(users.map(async (u) => {
var data = {}
await u.db.garbageCollect()
await u.db.garbageCollect()
u.db.requestTransaction(function * () {
var os = yield * this.getOperationsUntransformed()
data.os = {}
@ -85,7 +95,7 @@ export async function initArrays (t, opts) {
for (let i = 0; i < opts.users; i++) {
let y = await Y({
connector: connector,
db: opts.db,
db: Object.assign({ gc: i === 0 }, opts.db), // Only one instance can gc!
share: share
})
result.users.push(y)
@ -108,7 +118,7 @@ export async function initArrays (t, opts) {
}
export async function flushAll (t, users) {
users = users.filter(u => u.connector.isSynced)
// users = users.filter(u => u.connector.isSynced)
if (users.length === 0) {
return
}