def cleanup(self, epoch): try: death_row_node = self._keyValueStorage.get('deathrow:' + str(epoch)) except BaseException: death_row_node = rlp.encode([]) death_row_nodes = rlp.decode(death_row_node) pruned = 0 for nodekey in death_row_nodes: try: refcount, val = rlp.decode( self._keyValueStorage.get(b'r:' + nodekey)) if utils.decode_int(refcount) == DEATH_ROW_OFFSET + epoch: self._keyValueStorage.remove(b'r:' + nodekey) pruned += 1 except BaseException: pass sys.stderr.write('%d nodes successfully pruned\n' % pruned) # Delete the deathrow after processing it try: self._keyValueStorage.remove('deathrow:' + str(epoch)) except BaseException: pass # Delete journals that are too old try: self._keyValueStorage.remove('journal:' + str(epoch - self.ttl)) except BaseException: pass
def cleanup(self, epoch): try: death_row_node = self._keyValueStorage.get( 'deathrow:' + str(epoch)) except BaseException: death_row_node = rlp.encode([]) death_row_nodes = rlp.decode(death_row_node) pruned = 0 for nodekey in death_row_nodes: try: refcount, val = rlp.decode( self._keyValueStorage.get(b'r:' + nodekey)) if utils.decode_int(refcount) == DEATH_ROW_OFFSET + epoch: self._keyValueStorage.remove(b'r:' + nodekey) pruned += 1 except BaseException: pass sys.stderr.write('%d nodes successfully pruned\n' % pruned) # Delete the deathrow after processing it try: self._keyValueStorage.remove('deathrow:' + str(epoch)) except BaseException: pass # Delete journals that are too old try: self._keyValueStorage.remove('journal:' + str(epoch - self.ttl)) except BaseException: pass
def get_refcount(self, k): try: o = utils.decode_int(self._keyValueStorage.get(b'r:' + k))[0] if o >= DEATH_ROW_OFFSET: return 0 return o except BaseException: return 0
def dec_refcount(self, k): # raise Exception("WHY AM I CHANGING A REFCOUNT?!:?") node_object = rlp.decode(self._keyValueStorage.get(b'r:' + k)) refcount = utils.decode_int(node_object[0]) if self.logging: sys.stderr.write('decreasing %s to: %d\n' % (utils.encode_hex(k), refcount - 1)) assert refcount > 0 self.journal.append([node_object[0], k]) new_refcount = utils.encode_int(refcount - 1) self._keyValueStorage.put(b'r:' + k, rlp.encode([new_refcount, node_object[1]])) if new_refcount == ZERO_ENCODED: self.death_row.append(k)
def dec_refcount(self, k): # raise Exception("WHY AM I CHANGING A REFCOUNT?!:?") node_object = rlp.decode(self._keyValueStorage.get(b'r:' + k)) refcount = utils.decode_int(node_object[0]) if self.logging: sys.stderr.write('decreasing %s to: %d\n' % (utils.encode_hex(k), refcount - 1)) if not refcount > 0: raise ValueError("node object for key {} has {} number " "of references, expected > 0".format(k, refcount)) self.journal.append([node_object[0], k]) new_refcount = utils.encode_int(refcount - 1) self._keyValueStorage.put(b'r:' + k, rlp.encode([new_refcount, node_object[1]])) if new_refcount == ZERO_ENCODED: self.death_row.append(k)
def dec_refcount(self, k): # raise Exception("WHY AM I CHANGING A REFCOUNT?!:?") node_object = rlp.decode(self._keyValueStorage.get(b'r:' + k)) refcount = utils.decode_int(node_object[0]) if self.logging: sys.stderr.write('decreasing %s to: %d\n' % ( utils.encode_hex(k), refcount - 1)) if not refcount > 0: raise ValueError( "node object for key {} has {} number " "of references, expected > 0" .format(k, refcount) ) self.journal.append([node_object[0], k]) new_refcount = utils.encode_int(refcount - 1) self._keyValueStorage.put( b'r:' + k, rlp.encode([new_refcount, node_object[1]])) if new_refcount == ZERO_ENCODED: self.death_row.append(k)
def inc_refcount(self, k, v): # raise Exception("WHY AM I CHANGING A REFCOUNT?!:?") try: node_object = rlp.decode(self._keyValueStorage.get(b'r:' + k)) refcount = utils.decode_int(node_object[0]) self.journal.append([node_object[0], k]) if refcount >= DEATH_ROW_OFFSET: refcount = 0 new_refcount = utils.encode_int(refcount + 1) self._keyValueStorage.put(b'r:' + k, rlp.encode([new_refcount, v])) if self.logging: sys.stderr.write('increasing %s %r to: %d\n' % ( utils.encode_hex(k), v, refcount + 1)) except BaseException: self._keyValueStorage.put(b'r:' + k, rlp.encode([ONE_ENCODED, v])) self.journal.append([ZERO_ENCODED, k]) if self.logging: sys.stderr.write('increasing %s %r to: %d\n' % ( utils.encode_hex(k), v, 1))
def inc_refcount(self, k, v): # raise Exception("WHY AM I CHANGING A REFCOUNT?!:?") try: node_object = rlp.decode(self._keyValueStorage.get(b'r:' + k)) refcount = utils.decode_int(node_object[0]) self.journal.append([node_object[0], k]) if refcount >= DEATH_ROW_OFFSET: refcount = 0 new_refcount = utils.encode_int(refcount + 1) self._keyValueStorage.put(b'r:' + k, rlp.encode([new_refcount, v])) if self.logging: sys.stderr.write('increasing %s %r to: %d\n' % (utils.encode_hex(k), v, refcount + 1)) except BaseException: self._keyValueStorage.put(b'r:' + k, rlp.encode([ONE_ENCODED, v])) self.journal.append([ZERO_ENCODED, k]) if self.logging: sys.stderr.write('increasing %s %r to: %d\n' % (utils.encode_hex(k), v, 1))