Commit c8e2aed7 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b57e6ec0
...@@ -892,8 +892,8 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch ...@@ -892,8 +892,8 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch
at_from = '(%s ->) ' % t.hat(at_prev) at_from = '(%s ->) ' % t.hat(at_prev)
print('\nC: setup watch f<%s> %s%s' % (h(zf._p_oid), at_from, t.hat(at))) print('\nC: setup watch f<%s> %s%s' % (h(zf._p_oid), at_from, t.hat(at)))
headOfAccess = t._headOfAccess(zf) headOfAccess = t._headOfAccess(zf) # XXX we only use keys
blkRevAt = lambda blk, at: t._blkRevAt(zf, blk, at) lastRevOf = lambda blk: t._blkRevAt(zf, blk, t.head)
pin_prev = {} pin_prev = {}
if at_prev is not None: if at_prev is not None:
...@@ -915,36 +915,28 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch ...@@ -915,36 +915,28 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch
if at_prev is not None: if at_prev is not None:
assert False, '#%d pinned %s; not pinned %s' % (t.hat(at_prev), t.hat(at)) assert False, '#%d pinned %s; not pinned %s' % (t.hat(at_prev), t.hat(at))
# blk ∈ pin -> blk was already accessed with rev > at # blk ∈ pin -> blk is tracked; has rev > at
# (see criteria in _pinnedAt) # (see criteria in _pinnedAt)
assert blk in headOfAccess assert blk in headOfAccess
assert at < blkRevAt(blk, headOfAccess[blk]) assert at < lastRevOf(blk)
# blk ∈ pin_prev, blk ∉ pin -> unpin to head # blk ∈ pin_prev, blk ∉ pin -> unpin to head
#
# FIXME
#
# δ accessed δ not-accessed
# ----x-------x--------x-----o-----------]-----
# at_prev at head
#
# -> must pin to at? (not unpin @head)
elif blk in pin_prev and blk not in pin: elif blk in pin_prev and blk not in pin:
# blk ∈ pin_prev -> blk was already accessed with rev > at_prev # blk ∈ pin_prev -> blk is tracked; has rev > at_prev
assert blk in headOfAccess assert blk in headOfAccess
assert at_prev < blkRevAt(blk, headOfAccess[blk]) assert at_prev < lastRevOf(blk)
# blk ∉ pin -> blk revision as of last access is ≤ at # blk ∉ pin -> last blk revision is ≤ at
assert blkRevAt(blk, headOfAccess[blk]) <= at assert lastRevOf(blk) <= at
pin[blk] = None # @head pin[blk] = None # @head
# blk ∈ pin_prev, blk ∈ pin -> if rev different: use pin # blk ∈ pin_prev, blk ∈ pin -> if rev different: use pin
elif blk in pin_prev and blk in pin: elif blk in pin_prev and blk in pin:
# blk ∈ pin_prev, pin -> blk was already accessed with rev > at_prev, at # blk ∈ pin_prev, pin -> blk is tracked; has rev > at_prev, at
assert blk in headOfAccess assert blk in headOfAccess
assert at_prev < blkRevAt(blk, headOfAccess[blk]) assert at_prev < lastRevOf(blk)
assert at < blkRevAt(blk, headOfAccess[blk]) assert at < lastRevOf(blk)
assert pin_prev[blk] <= pin[blk] assert pin_prev[blk] <= pin[blk]
if pin_prev[blk] == pin[blk]: if pin_prev[blk] == pin[blk]:
...@@ -953,14 +945,13 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch ...@@ -953,14 +945,13 @@ def watch(twlink, zf, at, pinok=None): # -> tWatch
#print('-> %s' % t.hpin(pin)) #print('-> %s' % t.hpin(pin))
# {} blk -> at that have to be pinned. # {} blk -> at that have to be pinned.
# XXX also check that head/file[blk] is in cache - else no need to pin
if pinok is not None: if pinok is not None:
assert pin == pinok, "computed vs explicit pinok" assert pin == pinok, "computed vs explicit pinok"
pinok = pin pinok = pin
print('# pinok: %s' % t.hpin(pinok)) print('# pinok: %s' % t.hpin(pinok))
# send watch request and check that we receive pins for in-cache blocks # send watch request and check that we receive pins for tracked (previously
# changed > at. FIXME "in-cache" is currently not handled # accessed at least once) blocks changed > at.
twlink._watch(zf, at, pinok, "ok") twlink._watch(zf, at, pinok, "ok")
w.at = at w.at = at
...@@ -1145,9 +1136,9 @@ def _blkRevAt(t, zf, blk, at): # -> rev ...@@ -1145,9 +1136,9 @@ def _blkRevAt(t, zf, blk, at): # -> rev
# #
# Criteria for when blk must be pinned as of @at view: # Criteria for when blk must be pinned as of @at view:
# #
# blk ∈ pinned(at) <=> ∃ r = rev(blk): # blk ∈ pinned(at) <=> 1) ∃ r = rev(blk): at < r ; blk was changed after at
# 1) at < r ; blk was changed after at # 2) blk ∈ tracked ; blk was accessed at least once
# 2) r ≤ headOfAccess(blk) ; blk revision changed after at was accessed # ; (and so is tracked by wcfs)
@func(tDB) @func(tDB)
def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev
# XXX dup in _blkDataAt # XXX dup in _blkDataAt
...@@ -1168,7 +1159,7 @@ def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev ...@@ -1168,7 +1159,7 @@ def _pinnedAt(t, zf, at): # -> pin = {} blk -> rev
else: else:
pinrev = blkhistoryat[-1] pinrev = blkhistoryat[-1]
assert pinrev <= at assert pinrev <= at
if t._headOfAccess(zf).get(blk, z64) >= at: if blk in t._headOfAccess(zf):
pin[blk] = pinrev pin[blk] = pinrev
return pin return pin
...@@ -1366,8 +1357,8 @@ def test_wcfs_watch_setup(): ...@@ -1366,8 +1357,8 @@ def test_wcfs_watch_setup():
wl.close() wl.close()
assertNewWatch(at1, {2:at1, 3:at0, 5:at0}) assertNewWatch(at1, {2:at1, 3:at0, 5:at0})
assertNewWatch(at2, {2:at2, 3:at2, 5:at2}) assertNewWatch(at2, {2:at2, 3:at2, 5:at2})
assertNewWatch(at3, {2:at3, 3:at2, 5:at3}) # XXX recheck 5 assertNewWatch(at3, {2:at3, 3:at2, 5:at3}) # f(5) is pinned, even though it was not
assertNewWatch(at4, { 3:at2 }) # XXX 5 not accessed - right? assertNewWatch(at4, { 3:at2, 5:at4}) # accessed after at3
assertNewWatch(at5, { }) assertNewWatch(at5, { })
# new watch + update at_i -> at_j # new watch + update at_i -> at_j
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment