started to remove everything RBTree related from the Transaction.js
This commit is contained in:
		
							parent
							
								
									aff10fa4db
								
							
						
					
					
						commit
						cf365b8902
					
				@ -22,17 +22,26 @@ Y.Memory = (function () {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    logTable () {
 | 
					    logTable () {
 | 
				
			||||||
      var self = this
 | 
					      var self = this
 | 
				
			||||||
      return new Promise(function (resolve) {
 | 
					      self.requestTransaction(function * () {
 | 
				
			||||||
        self.requestTransaction(function * () {
 | 
					        console.log('User: ', this.store.y.connector.userId, "==============================") // eslint-disable-line
 | 
				
			||||||
          console.log('User: ', this.store.y.connector.userId, "==============================") // eslint-disable-line
 | 
					        console.log("State Set (SS):", yield* this.getStateSet()) // eslint-disable-line
 | 
				
			||||||
          console.log("State Set (SS):", this.ss) // eslint-disable-line
 | 
					        console.log("Operation Store (OS):") // eslint-disable-line
 | 
				
			||||||
          console.log("Operation Store (OS):") // eslint-disable-line
 | 
					        yield* this.os.logTable() // eslint-disable-line
 | 
				
			||||||
          yield* this.os.logTable() // eslint-disable-line
 | 
					        console.log("Deletion Store (DS):") //eslint-disable-line
 | 
				
			||||||
          console.log("Deletion Store (DS):") //eslint-disable-line
 | 
					        yield* this.ds.logTable() // eslint-disable-line
 | 
				
			||||||
          yield* this.ds.logTable() // eslint-disable-line
 | 
					        if (this.store.gc1.length > 0 || this.store.gc2.length > 0) {
 | 
				
			||||||
          resolve()
 | 
					          console.warn('GC1|2 not empty!', this.store.gc1, this.store.gc2)
 | 
				
			||||||
        }, true)
 | 
					        }
 | 
				
			||||||
      })
 | 
					        if (JSON.stringify(this.store.listenersById) !== '{}') {
 | 
				
			||||||
 | 
					          console.warn('listenersById not empty!')
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (JSON.stringify(this.store.listenersByIdExecuteNow) !== '[]') {
 | 
				
			||||||
 | 
					          console.warn('listenersByIdExecuteNow not empty!')
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (this.store.transactionInProgress) {
 | 
				
			||||||
 | 
					          console.warn('Transaction still in progress!')
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }, true)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    transact (makeGen) {
 | 
					    transact (makeGen) {
 | 
				
			||||||
      var t = new Transaction(this)
 | 
					      var t = new Transaction(this)
 | 
				
			||||||
 | 
				
			|||||||
@ -131,10 +131,12 @@ class RBTree {
 | 
				
			|||||||
    this.length = 0
 | 
					    this.length = 0
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  * findNext (id) {
 | 
					  * findNext (id) {
 | 
				
			||||||
    return yield* this.findNodeWithLowerBound([id[0], id[1] + 1])
 | 
					    var n = yield* this.findNodeWithLowerBound([id[0], id[1] + 1])
 | 
				
			||||||
 | 
					    return n == null ? null : n.val
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  * findPrev (id) {
 | 
					  * findPrev (id) {
 | 
				
			||||||
    return yield* this.findNodeWithUpperBound([id[0], id[1] - 1])
 | 
					    var n = yield* this.findNodeWithUpperBound([id[0], id[1] - 1])
 | 
				
			||||||
 | 
					    return n == null ? null : n.val
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  * findNodeWithLowerBound (from) {
 | 
					  * findNodeWithLowerBound (from) {
 | 
				
			||||||
    if (from === void 0) {
 | 
					    if (from === void 0) {
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@ g.g = g
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
g.YConcurrency_TestingMode = true
 | 
					g.YConcurrency_TestingMode = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
 | 
					jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
g.describeManyTimes = function describeManyTimes (times, name, f) {
 | 
					g.describeManyTimes = function describeManyTimes (times, name, f) {
 | 
				
			||||||
  for (var i = 0; i < times; i++) {
 | 
					  for (var i = 0; i < times; i++) {
 | 
				
			||||||
@ -154,6 +154,7 @@ g.compareAllUsers = async(function * compareAllUsers (users) {
 | 
				
			|||||||
    })
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  yield users[0].connector.flushAll()
 | 
					  yield users[0].connector.flushAll()
 | 
				
			||||||
 | 
					  yield wait()
 | 
				
			||||||
  yield g.garbageCollectAllUsers(users)
 | 
					  yield g.garbageCollectAllUsers(users)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (var uid = 0; uid < users.length; uid++) {
 | 
					  for (var uid = 0; uid < users.length; uid++) {
 | 
				
			||||||
 | 
				
			|||||||
@ -195,42 +195,47 @@ class Transaction {
 | 
				
			|||||||
  * markGarbageCollected (id) {
 | 
					  * markGarbageCollected (id) {
 | 
				
			||||||
    // this.mem.push(["gc", id]);
 | 
					    // this.mem.push(["gc", id]);
 | 
				
			||||||
    var n = yield* this.markDeleted(id)
 | 
					    var n = yield* this.markDeleted(id)
 | 
				
			||||||
    if (!n.val.gc) {
 | 
					    if (!n.gc) {
 | 
				
			||||||
      if (n.val.id[1] < id[1]) {
 | 
					      if (n.id[1] < id[1]) {
 | 
				
			||||||
        // un-extend left
 | 
					        // un-extend left
 | 
				
			||||||
        var newlen = n.val.len - (id[1] - n.val.id[1])
 | 
					        var newlen = n.len - (id[1] - n.id[1])
 | 
				
			||||||
        n.val.len -= newlen
 | 
					        n.len -= newlen
 | 
				
			||||||
 | 
					        yield* this.ds.put(n)
 | 
				
			||||||
        n = yield* this.ds.put({id: id, len: newlen, gc: false})
 | 
					        n = yield* this.ds.put({id: id, len: newlen, gc: false})
 | 
				
			||||||
 | 
					        n = n.val
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      // get prev&next before adding a new operation
 | 
					      // get prev&next before adding a new operation
 | 
				
			||||||
      var prev = n.prev()
 | 
					      var prev = yield* this.ds.findPrev(id)
 | 
				
			||||||
      var next = n.next()
 | 
					      var next = yield* this.ds.findNext(id)
 | 
				
			||||||
      if (id[1] < n.val.id[1] + n.val.len - 1) {
 | 
					
 | 
				
			||||||
 | 
					      if (id[1] < n.id[1] + n.len - 1) {
 | 
				
			||||||
        // un-extend right
 | 
					        // un-extend right
 | 
				
			||||||
        yield* this.ds.put({id: [id[0], id[1] + 1], len: n.val.len - 1, gc: false})
 | 
					        yield* this.ds.put({id: [id[0], id[1] + 1], len: n.len - 1, gc: false})
 | 
				
			||||||
        n.val.len = 1
 | 
					        n.len = 1
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      // set gc'd
 | 
					      // set gc'd
 | 
				
			||||||
      n.val.gc = true
 | 
					      n.gc = true
 | 
				
			||||||
      // can extend left?
 | 
					      // can extend left?
 | 
				
			||||||
      if (
 | 
					      if (
 | 
				
			||||||
        prev != null &&
 | 
					        prev != null &&
 | 
				
			||||||
        prev.val.gc &&
 | 
					        prev.gc &&
 | 
				
			||||||
        Y.utils.compareIds([prev.val.id[0], prev.val.id[1] + prev.val.len], n.val.id)
 | 
					        Y.utils.compareIds([prev.id[0], prev.id[1] + prev.len], n.id)
 | 
				
			||||||
      ) {
 | 
					      ) {
 | 
				
			||||||
        prev.val.len += n.val.len
 | 
					        prev.len += n.len
 | 
				
			||||||
        yield* this.ds.delete(n.val.id)
 | 
					        yield* this.ds.delete(n.id)
 | 
				
			||||||
        n = prev
 | 
					        n = prev
 | 
				
			||||||
 | 
					        // ds.put n here?
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      // can extend right?
 | 
					      // can extend right?
 | 
				
			||||||
      if (
 | 
					      if (
 | 
				
			||||||
        next != null &&
 | 
					        next != null &&
 | 
				
			||||||
        next.val.gc &&
 | 
					        next.gc &&
 | 
				
			||||||
        Y.utils.compareIds([n.val.id[0], n.val.id[1] + n.val.len], next.val.id)
 | 
					        Y.utils.compareIds([n.id[0], n.id[1] + n.len], next.id)
 | 
				
			||||||
      ) {
 | 
					      ) {
 | 
				
			||||||
        n.val.len += next.val.len
 | 
					        n.len += next.len
 | 
				
			||||||
        yield* this.ds.delete(next.val.id)
 | 
					        yield* this.ds.delete(next.id)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      yield* this.ds.put(n)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  /*
 | 
					  /*
 | 
				
			||||||
@ -241,34 +246,36 @@ class Transaction {
 | 
				
			|||||||
  * markDeleted (id) {
 | 
					  * markDeleted (id) {
 | 
				
			||||||
    // this.mem.push(["del", id]);
 | 
					    // this.mem.push(["del", id]);
 | 
				
			||||||
    var n = yield* this.ds.findNodeWithUpperBound(id)
 | 
					    var n = yield* this.ds.findNodeWithUpperBound(id)
 | 
				
			||||||
    if (n != null && n.val.id[0] === id[0]) {
 | 
					    n = n == null ? n : n.val
 | 
				
			||||||
      if (n.val.id[1] <= id[1] && id[1] < n.val.id[1] + n.val.len) {
 | 
					    if (n != null && n.id[0] === id[0]) {
 | 
				
			||||||
 | 
					      if (n.id[1] <= id[1] && id[1] < n.id[1] + n.len) {
 | 
				
			||||||
        // already deleted
 | 
					        // already deleted
 | 
				
			||||||
        return n
 | 
					        return n
 | 
				
			||||||
      } else if (n.val.id[1] + n.val.len === id[1] && !n.val.gc) {
 | 
					      } else if (n.id[1] + n.len === id[1] && !n.gc) {
 | 
				
			||||||
        // can extend existing deletion
 | 
					        // can extend existing deletion
 | 
				
			||||||
        n.val.len++
 | 
					        n.len++
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        // cannot extend left
 | 
					        // cannot extend left
 | 
				
			||||||
        n = yield* this.ds.put({id: id, len: 1, gc: false})
 | 
					        n = yield* this.ds.put({id: id, len: 1, gc: false})
 | 
				
			||||||
 | 
					        n = n.val
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      // cannot extend left
 | 
					      // cannot extend left
 | 
				
			||||||
      n = yield* this.ds.put({id: id, len: 1, gc: false})
 | 
					      n = yield* this.ds.put({id: id, len: 1, gc: false})
 | 
				
			||||||
 | 
					      n = n.val
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    // can extend right?
 | 
					    // can extend right?
 | 
				
			||||||
    var next = n.next()
 | 
					    var next = yield* this.ds.findNext(n.id)
 | 
				
			||||||
    if (
 | 
					    if (
 | 
				
			||||||
      next !== null &&
 | 
					      next != null &&
 | 
				
			||||||
      Y.utils.compareIds([n.val.id[0], n.val.id[1] + n.val.len], next.val.id) &&
 | 
					      Y.utils.compareIds([n.id[0], n.id[1] + n.len], next.id) &&
 | 
				
			||||||
      !next.val.gc
 | 
					      !next.gc
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
      n.val.len = n.val.len + next.val.len
 | 
					      n.len = n.len + next.len
 | 
				
			||||||
      yield* this.ds.delete(next.val.id)
 | 
					      yield* this.ds.delete(next.id)
 | 
				
			||||||
      return this.ds.findNode(n.val.id)
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      return n
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    yield* this.ds.put(n)
 | 
				
			||||||
 | 
					    return n
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  /*
 | 
					  /*
 | 
				
			||||||
    Call this method when the client is connected&synced with the
 | 
					    Call this method when the client is connected&synced with the
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
/* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactionsAllRejoinNoGC, applyRandomTransactionsWithGC, async, garbageCollectAllUsers, describeManyTimes */
 | 
					/* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactionsAllRejoinNoGC, applyRandomTransactionsWithGC, async, garbageCollectAllUsers, describeManyTimes */
 | 
				
			||||||
/* eslint-env browser,jasmine */
 | 
					/* eslint-env browser,jasmine */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var numberOfYArrayTests = 200
 | 
					var numberOfYArrayTests = 40
 | 
				
			||||||
var repeatArrayTests = 1
 | 
					var repeatArrayTests = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('Array Type', function () {
 | 
					describe('Array Type', function () {
 | 
				
			||||||
@ -187,7 +187,6 @@ describe('Array Type', function () {
 | 
				
			|||||||
      l3 = yield y3.get('Array')
 | 
					      l3 = yield y3.get('Array')
 | 
				
			||||||
      yield flushAll()
 | 
					      yield flushAll()
 | 
				
			||||||
      yield garbageCollectAllUsers(this.users)
 | 
					      yield garbageCollectAllUsers(this.users)
 | 
				
			||||||
      yconfig1.db.logTable()
 | 
					 | 
				
			||||||
      expect(l1.toArray()).toEqual(l2.toArray())
 | 
					      expect(l1.toArray()).toEqual(l2.toArray())
 | 
				
			||||||
      expect(l2.toArray()).toEqual(l3.toArray())
 | 
					      expect(l2.toArray()).toEqual(l3.toArray())
 | 
				
			||||||
      expect(l2.toArray()).toEqual([])
 | 
					      expect(l2.toArray()).toEqual([])
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
/* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactionsAllRejoinNoGC, applyRandomTransactionsWithGC, async, describeManyTimes */
 | 
					/* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactionsAllRejoinNoGC, applyRandomTransactionsWithGC, async, describeManyTimes */
 | 
				
			||||||
/* eslint-env browser,jasmine */
 | 
					/* eslint-env browser,jasmine */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var numberOfYMapTests = 10
 | 
					var numberOfYMapTests = 40
 | 
				
			||||||
var repeatMapTeasts = 1
 | 
					var repeatMapTeasts = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('Map Type', function () {
 | 
					describe('Map Type', function () {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user