implemented logTable method on data stores

This commit is contained in:
Kevin Jahns 2017-10-22 23:50:39 +02:00
parent 142a5ada60
commit 2b7d2ed1e6
15 changed files with 94 additions and 31 deletions

View File

@ -140,8 +140,8 @@ export default class AbstractConnector {
if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) { if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {
throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\'t use this method to send custom messages') throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\'t use this method to send custom messages')
} }
this.log('%s: Send \'%y\' to %s', y.userID, buffer, uid) this.log('User%s to User%s: Send \'%y\'', y.userID, uid, buffer)
this.logMessage('Message: %Y', [y, buffer]) this.logMessage('User%s to User%s: Send %Y', y.userID, uid, [y, buffer])
} }
broadcast (buffer) { broadcast (buffer) {
@ -149,8 +149,8 @@ export default class AbstractConnector {
if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) { if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {
throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\'t use this method to send custom messages') throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - don\'t use this method to send custom messages')
} }
this.log('%s: Broadcast \'%y\'', y.userID, buffer) this.log('User%s: Broadcast \'%y\'', y.userID, buffer)
this.logMessage('Message: %Y', [y, buffer]) this.logMessage('User%s: Broadcast: %Y', y.userID, [y, buffer])
} }
/* /*
@ -216,8 +216,8 @@ export default class AbstractConnector {
encoder.writeVarString(roomname) encoder.writeVarString(roomname)
let messageType = decoder.readVarString() let messageType = decoder.readVarString()
let senderConn = this.connections.get(sender) let senderConn = this.connections.get(sender)
this.log('%s: Receive \'%s\' from %s', userID, messageType, sender) this.log('User%s from User%s: Receive \'%s\'', userID, sender, messageType)
this.logMessage('Message: %Y', [y, buffer]) this.logMessage('User%s from User%s: Receive %Y', userID, sender, [y, buffer])
if (senderConn == null && !skipAuth) { if (senderConn == null && !skipAuth) {
throw new Error('Received message from unknown peer!') throw new Error('Received message from unknown peer!')
} }

View File

@ -1,6 +1,7 @@
import { getStruct } from '../Util/structReferences.js' import { getStruct } from '../Util/structReferences.js'
import BinaryDecoder from '../Binary/Decoder.js' import BinaryDecoder from '../Binary/Decoder.js'
import Delete from '../Struct/Delete.js' import Delete from '../Struct/Delete.js'
import { logID } from './messageToString.js'
class MissingEntry { class MissingEntry {
constructor (decoder, missing, struct) { constructor (decoder, missing, struct) {
@ -17,7 +18,7 @@ class MissingEntry {
*/ */
function _integrateRemoteStructHelper (y, struct) { function _integrateRemoteStructHelper (y, struct) {
struct._integrate(y) struct._integrate(y)
if (!(struct instanceof Delete)) { if (struct.constructor !== Delete) {
let msu = y._missingStructs.get(struct._id.user) let msu = y._missingStructs.get(struct._id.user)
if (msu != null) { if (msu != null) {
let len = struct._length let len = struct._length
@ -46,11 +47,10 @@ export function stringifyStructs (y, decoder, strBuilder) {
let Constr = getStruct(reference) let Constr = getStruct(reference)
let struct = new Constr() let struct = new Constr()
let missing = struct._fromBinary(y, decoder) let missing = struct._fromBinary(y, decoder)
let logMessage = struct._logString() let logMessage = ' ' + struct._logString()
if (missing.length > 0) { if (missing.length > 0) {
logMessage += missing.map(id => `ID (user: ${id.user}, clock: ${id.clock})`).join(', ') logMessage += ' .. missing: ' + missing.map(logID).join(', ')
} }
logMessage += '\n'
strBuilder.push(logMessage) strBuilder.push(logMessage)
} }
} }

View File

@ -2,13 +2,16 @@ import BinaryDecoder from '../Binary/Decoder.js'
import { stringifyStructs } from './integrateRemoteStructs.js' import { stringifyStructs } from './integrateRemoteStructs.js'
import { stringifySyncStep1 } from './syncStep1.js' import { stringifySyncStep1 } from './syncStep1.js'
import { stringifySyncStep2 } from './syncStep2.js' import { stringifySyncStep2 } from './syncStep2.js'
import ID from '../Util/ID.js'
import RootID from '../Util/RootID.js'
import Y from '../Y.js'
export function messageToString ([y, buffer]) { export function messageToString ([y, buffer]) {
let decoder = new BinaryDecoder(buffer) let decoder = new BinaryDecoder(buffer)
decoder.readVarString() // read roomname decoder.readVarString() // read roomname
let type = decoder.readVarString() let type = decoder.readVarString()
let strBuilder = [] let strBuilder = []
strBuilder.push('\n === ' + type + ' ===\n') strBuilder.push('\n === ' + type + ' ===')
if (type === 'update') { if (type === 'update') {
stringifyStructs(y, decoder, strBuilder) stringifyStructs(y, decoder, strBuilder)
} else if (type === 'sync step 1') { } else if (type === 'sync step 1') {
@ -26,3 +29,20 @@ export function messageToRoomname (buffer) {
decoder.readVarString() // roomname decoder.readVarString() // roomname
return decoder.readVarString() // messageType return decoder.readVarString() // messageType
} }
export function logID (id) {
if (id !== null && id._id != null) {
id = id._id
}
if (id === null) {
return '()'
} else if (id instanceof ID) {
return `(${id.user},${id.clock})`
} else if (id instanceof RootID) {
return `(${id.name},${id.type})`
} else if (id.constructor === Y) {
return `y`
} else {
throw new Error('This is not a valid ID!')
}
}

View File

@ -7,18 +7,17 @@ import { RootFakeUserID } from '../Util/RootID.js'
export function stringifySyncStep1 (y, decoder, strBuilder) { export function stringifySyncStep1 (y, decoder, strBuilder) {
let auth = decoder.readVarString() let auth = decoder.readVarString()
let protocolVersion = decoder.readVarUint() let protocolVersion = decoder.readVarUint()
strBuilder.push(` strBuilder.push(` - auth: "${auth}"`)
- auth: "${auth}" strBuilder.push(` - protocolVersion: ${protocolVersion}`)
- protocolVersion: ${protocolVersion}
`)
// write SS // write SS
strBuilder.push(' == SS: \n') let ssBuilder = []
let len = decoder.readUint32() let len = decoder.readUint32()
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
let user = decoder.readVarUint() let user = decoder.readVarUint()
let clock = decoder.readVarUint() let clock = decoder.readVarUint()
strBuilder.push(` ${user}: ${clock}\n`) ssBuilder.push(`(${user}:${clock})`)
} }
strBuilder.push(' == SS: ' + ssBuilder.join(','))
} }
export function sendSyncStep1 (connector, syncUser) { export function sendSyncStep1 (connector, syncUser) {

View File

@ -2,10 +2,9 @@ import { stringifyStructs, integrateRemoteStructs } from './integrateRemoteStruc
import { readDeleteSet } from './deleteSet.js' import { readDeleteSet } from './deleteSet.js'
export function stringifySyncStep2 (y, decoder, strBuilder) { export function stringifySyncStep2 (y, decoder, strBuilder) {
strBuilder.push(' - auth: ' + decoder.readVarString() + '\n') strBuilder.push(' - auth: ' + decoder.readVarString())
strBuilder.push(' == OS: \n')
// write DS to string // write DS to string
strBuilder.push(' == DS: \n') strBuilder.push(' == DS:')
let len = decoder.readUint32() let len = decoder.readUint32()
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
let user = decoder.readVarUint() let user = decoder.readVarUint()
@ -18,6 +17,7 @@ export function stringifySyncStep2 (y, decoder, strBuilder) {
strBuilder.push(`[${from}, ${to}, ${gc}]`) strBuilder.push(`[${from}, ${to}, ${gc}]`)
} }
} }
strBuilder.push(' == OS:')
stringifyStructs(y, decoder, strBuilder) stringifyStructs(y, decoder, strBuilder)
} }

View File

@ -13,6 +13,18 @@ class DSNode {
} }
export default class DeleteStore extends Tree { export default class DeleteStore extends Tree {
logTable () {
const deletes = []
this.iterate(null, null, function (n) {
deletes.push({
user: n._id.user,
clock: n._id.clock,
len: n.len,
gc: n.gc
})
})
console.table(deletes)
}
isDeleted (id) { isDeleted (id) {
var n = this.findWithUpperBound(id) var n = this.findWithUpperBound(id)
return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len return n !== null && n._id.user === id.user && id.clock < n._id.clock + n.len

View File

@ -1,12 +1,30 @@
import Tree from '../Util/Tree.js' import Tree from '../Util/Tree.js'
import RootID from '../Util/RootID.js' import RootID from '../Util/RootID.js'
import { getStruct } from '../Util/structReferences.js' import { getStruct } from '../Util/structReferences.js'
import { logID } from '../MessageHandler/messageToString.js'
export default class OperationStore extends Tree { export default class OperationStore extends Tree {
constructor (y) { constructor (y) {
super() super()
this.y = y this.y = y
} }
logTable () {
const items = []
this.iterate(null, null, function (item) {
items.push({
id: logID(item),
origin: logID(item._origin === null ? null : item._origin._lastId),
left: logID(item._left === null ? null : item._left._lastId),
right: logID(item._right),
right_origin: logID(item._right_origin),
parent: logID(item._parent),
parentSub: item._parentSub,
deleted: item._deleted,
content: JSON.stringify(item._content)
})
})
console.table(items)
}
get (id) { get (id) {
let struct = this.find(id) let struct = this.find(id)
if (struct === null && id instanceof RootID) { if (struct === null && id instanceof RootID) {

View File

@ -5,6 +5,15 @@ export default class StateStore {
this.y = y this.y = y
this.state = new Map() this.state = new Map()
} }
logTable () {
const entries = []
for (let [user, state] of this.state) {
entries.push({
user, state
})
}
console.table(entries)
}
getNextID (len) { getNextID (len) {
const user = this.y.userID const user = this.y.userID
const state = this.getState(user) const state = this.getState(user)

View File

@ -297,7 +297,4 @@ export default class Item {
} }
return missing return missing
} }
_logString () {
return `left: ${this._left}, origin: ${this._origin}, right: ${this._right}, parent: ${this._parent}, parentSub: ${this._parentSub}`
}
} }

View File

@ -1,4 +1,5 @@
import { splitHelper, default as Item } from './Item.js' import { splitHelper, default as Item } from './Item.js'
import { logID } from '../MessageHandler/messageToString.js'
export default class ItemJSON extends Item { export default class ItemJSON extends Item {
constructor () { constructor () {
@ -27,8 +28,7 @@ export default class ItemJSON extends Item {
} }
} }
_logString () { _logString () {
let s = super._logString() return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(this._left)},origin:${logID(this._origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${logID(this._parentSub)})`
return 'ItemJSON: ' + s
} }
_splitAt (y, diff) { _splitAt (y, diff) {
if (diff === 0) { if (diff === 0) {

View File

@ -1,4 +1,5 @@
import { splitHelper, default as Item } from './Item.js' import { splitHelper, default as Item } from './Item.js'
import { logID } from '../MessageHandler/messageToString.js'
export default class ItemString extends Item { export default class ItemString extends Item {
constructor () { constructor () {
@ -18,8 +19,7 @@ export default class ItemString extends Item {
encoder.writeVarString(this._content) encoder.writeVarString(this._content)
} }
_logString () { _logString () {
let s = super._logString() return `ItemJSON(id:${logID(this._id)},content:${JSON.stringify(this._content)},left:${logID(this._left)},origin:${logID(this._origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${logID(this._parentSub)})`
return 'ItemString: ' + s
} }
_splitAt (y, diff) { _splitAt (y, diff) {
if (diff === 0) { if (diff === 0) {

View File

@ -1,5 +1,6 @@
import Type from '../Struct/Type.js' import Type from '../Struct/Type.js'
import ItemJSON from '../Struct/ItemJSON.js' import ItemJSON from '../Struct/ItemJSON.js'
import { logID } from '../MessageHandler/messageToString.js'
class YArrayEvent { class YArrayEvent {
constructor (yarray, remote) { constructor (yarray, remote) {
@ -203,7 +204,6 @@ export default class YArray extends Type {
this.insertAfter(left, content) this.insertAfter(left, content)
} }
_logString () { _logString () {
let s = super._logString() return `YArray(id:${logID(this._id)},start:${logID(this._start)},left:${logID(this._left)},origin:${logID(this._origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${logID(this._parentSub)})`
return 'YArray: ' + s
} }
} }

View File

@ -1,6 +1,7 @@
import Type from '../Struct/Type.js' import Type from '../Struct/Type.js'
import Item from '../Struct/Item.js' import Item from '../Struct/Item.js'
import ItemJSON from '../Struct/ItemJSON.js' import ItemJSON from '../Struct/ItemJSON.js'
import { logID } from '../MessageHandler/messageToString.js'
class YMapEvent { class YMapEvent {
constructor (ymap, subs, remote) { constructor (ymap, subs, remote) {
@ -82,7 +83,6 @@ export default class YMap extends Type {
} }
} }
_logString () { _logString () {
let s = super._logString() return `YMap(id:${logID(this._id)},mapSize:${this._map.size},left:${logID(this._left)},origin:${logID(this._origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${logID(this._parentSub)})`
return 'YMap: ' + s
} }
} }

View File

@ -1,5 +1,6 @@
import ItemString from '../Struct/ItemString.js' import ItemString from '../Struct/ItemString.js'
import YArray from './YArray.js' import YArray from './YArray.js'
import { logID } from '../MessageHandler/messageToString.js'
export default class YText extends YArray { export default class YText extends YArray {
constructor (string) { constructor (string) {
@ -50,4 +51,7 @@ export default class YText extends YArray {
item._integrate(this._y) item._integrate(this._y)
}) })
} }
_logString () {
return `YText(id:${logID(this._id)},start:${logID(this._start)},left:${logID(this._left)},origin:${logID(this._origin)},right:${logID(this._right)},parent:${logID(this._parent)},parentSub:${logID(this._parentSub)})`
}
} }

View File

@ -5,6 +5,7 @@ import { defaultDomFilter, applyChangesFromDom, reflectChangesOnDom } from './ut
import YArray from '../YArray.js' import YArray from '../YArray.js'
import YXmlText from './YXmlText.js' import YXmlText from './YXmlText.js'
import YXmlEvent from './YXmlEvent.js' import YXmlEvent from './YXmlEvent.js'
import { logID } from '../../MessageHandler/messageToString.js'
function domToYXml (parent, doms) { function domToYXml (parent, doms) {
const types = [] const types = []
@ -151,4 +152,7 @@ export default class YXmlFragment extends YArray {
this._domObserverListener(this._domObserver.takeRecords()) this._domObserverListener(this._domObserver.takeRecords())
} }
} }
_logString () {
return `YXml(id:${logID(this._id)},parent:${logID(this._parent)},parentSub:${this._parentSub})`
}
} }