Add target serialization to first state

This commit is contained in:
lash 2022-03-19 00:59:55 +00:00
parent 5f2809c394
commit 7ff4e8faa0
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 7 additions and 13 deletions

View File

@ -32,8 +32,8 @@ class SyncFsItem:
logg.debug('get key {}'.format(self.state_key)) logg.debug('get key {}'.format(self.state_key))
v = self.sync_state.get(self.state_key) v = self.sync_state.get(self.state_key)
self.cursor = int.from_bytes(v[:4], 'big')
self.tx_cursor = int.from_bytes(v[4:], 'big') (self.cursor, self.tx_cursor, self.target) = sync_state_deserialize(v)
if self.filter_state.state(self.state_key) & self.filter_state.from_name('LOCK') and not ignore_invalid: if self.filter_state.state(self.state_key) & self.filter_state.from_name('LOCK') and not ignore_invalid:
raise LockError(s) raise LockError(s)
@ -244,17 +244,13 @@ class SyncFsStore:
self.__load(target) self.__load(target)
if self.first: if self.first:
block_number = offset state_bytes = sync_state_serialize(offset, 0, target)
state_bytes = block_number.to_bytes(4, 'big') block_number_str = str(offset)
tx_index = 0
state_bytes += tx_index.to_bytes(4, 'big')
block_number_str = str(block_number)
self.state.put(block_number_str, state_bytes) self.state.put(block_number_str, state_bytes)
self.filter_state.put(block_number_str) self.filter_state.put(block_number_str)
o = SyncFsItem(block_number, target, self.state, self.filter_state) o = SyncFsItem(offset, target, self.state, self.filter_state)
self.items[block_number] = o self.items[offset] = o
self.item_keys.append(block_number) self.item_keys.append(offset)
logg.debug('added first {}'.format(o))
elif offset > 0: elif offset > 0:
logg.warning('block number argument {} for start ignored for already initiated sync {}'.format(offset, self.session_id)) logg.warning('block number argument {} for start ignored for already initiated sync {}'.format(offset, self.session_id))
self.started = True self.started = True

View File

@ -193,13 +193,11 @@ class TestFs(unittest.TestCase):
session = SyncSession(store) session = SyncSession(store)
session.start() session.start()
logg.debug('list {} {} {}'.format(store.state.list(store.state.SYNC), store.state.list(store.state.DONE), store.state.list(store.state.NEW)))
o = session.get(0) o = session.get(0)
o.next(advance_block=True) o.next(advance_block=True)
o.next(advance_block=True) o.next(advance_block=True)
session.stop(o) session.stop(o)
logg.debug('list {} {} {}'.format(store.state.list(store.state.SYNC), store.state.list(store.state.DONE), store.state.list(store.state.NEW)))
store = SyncFsStore(self.path, session_id='foo') store = SyncFsStore(self.path, session_id='foo')
store.start() store.start()
o = store.get(2) o = store.get(2)