Commit 805c4b8f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 65803eb1
...@@ -166,7 +166,7 @@ class DFile: ...@@ -166,7 +166,7 @@ class DFile:
# #
# The primary way to access wcfs is by opening BigFiles and Watches. # The primary way to access wcfs is by opening BigFiles and Watches.
# A BigFile opened under tDB is represented as tFile - see .open for details. # A BigFile opened under tDB is represented as tFile - see .open for details.
# A Watche opened under tDB is represented as tWatchLink - see .openwatch for details. # A Watch opened under tDB is represented as tWatchLink - see .openwatch for details.
# #
# The database can be mutated (via !wcfs path) with .change + .commit . # The database can be mutated (via !wcfs path) with .change + .commit .
# Current database head is represented by .head . # Current database head is represented by .head .
...@@ -175,7 +175,7 @@ class DFile: ...@@ -175,7 +175,7 @@ class DFile:
# #
# tDB must be explicitly closed once no longer used. # tDB must be explicitly closed once no longer used.
# #
# XXX .path/.read/.stat/._open # Raw files on wcfs can be accessed with ._path/._read/._stat/._open
# #
# XXX print -> t.trace/debug() + t.verbose depending on py.test -v -v ? # XXX print -> t.trace/debug() + t.verbose depending on py.test -v -v ?
class tDB: class tDB:
...@@ -293,62 +293,58 @@ class tDB: ...@@ -293,62 +293,58 @@ class tDB:
t._wc_zheadv.append(wchead) t._wc_zheadv.append(wchead)
# head/at = last txn of whole db # head/at = last txn of whole db
assert t.read("head/at") == h(t.head) assert t._read("head/at") == h(t.head)
# _blkaccess marks head/zf[blk] accessed. # _blkaccess marks head/zf[blk] accessed.
# XXX place=? # XXX place=? -> history query
def _blkaccess(t, zf, blk): def _blkaccess(t, zf, blk):
# XXX locking? # XXX locking?
zfAccessed = t._accessed.setdefault(zf, {}) zfAccessed = t._accessed.setdefault(zf, {})
zfAccessed[blk] = t.head zfAccessed[blk] = t.head
# XXX vvv -> not what we need, think again
# _blkHeadAccessed returns whether block state corresponding to zf[blk] at
# current head was accessed.
#
# for example - if head/<zf>[blk] was accessed and later changed, the answer is "no".
# buf if head/<zf>[blk] was accessed again after change, and was no longer
# changed, the answer is "yes"
# XXX text
# XXX -> _blkLastRevAccessed ? _blkRevLastAccessed ? _blkHeadRevAccessed ?
"""
def _blkHeadAccessed(t, zf, blk):
zfAccessed = t._accessed.get(zf, {})
zfAccessed.get(blk) vs t._blkRev(zf, blk, t.head)
"""
# path returns path for object on wcfs. # _path returns path for object on wcfs.
# - str: wcfs root + obj; # - str: wcfs root + obj;
# - Persistent: wcfs root + (head|@<at>)/bigfile/obj # - Persistent: wcfs root + (head|@<at>)/bigfile/obj
def path(t, obj, at=None): def _path(t, obj, at=None):
if isinstance(obj, Persistent): if isinstance(obj, Persistent):
head = "head/" if at is None else ("@%s/" % h(at)) head = "head/" if at is None else ("@%s/" % h(at))
obj = "%s/bigfile/%s" % (head, h(obj._p_oid)) obj = "%s/bigfile/%s" % (head, h(obj._p_oid))
at = None at = None
assert isinstance(obj, str) assert isinstance(obj, str)
assert at is None # must not be used with str assert at is None # must not be used with str
return os.path.join(t.wc.mountpoint, obj) return os.path.join(t.wc.mountpoint, obj)
# read reads file corresponding to obj on wcfs. # _read reads file corresponding to obj on wcfs.
def read(t, obj, at=None): def _read(t, obj, at=None):
path = t.path(obj, at=at) path = t._path(obj, at=at)
return readfile(path) return readfile(path)
# stat stats file corresponding to obj on wcfs. # _stat stats file corresponding to obj on wcfs.
def stat(t, obj, at=None): def _stat(t, obj, at=None):
path = t.path(obj, at=at) path = t._path(obj, at=at)
return os.stat(path) return os.stat(path)
# _open opens file corresponding to obj on wcfs. # _open opens file corresponding to obj on wcfs.
def _open(t, obj, mode='rb', at=None): def _open(t, obj, mode='rb', at=None):
path = t.path(obj, at=at) path = t._path(obj, at=at)
return open(path, mode, 0) # unbuffered return open(path, mode, 0) # unbuffered
# XXX vvv -> not what we need, think again
# _blkHeadAccessed returns whether block state corresponding to zf[blk] at
# current head was accessed.
#
# for example - if head/<zf>[blk] was accessed and later changed, the answer is "no".
# buf if head/<zf>[blk] was accessed again after change, and was no longer
# changed, the answer is "yes"
# XXX text
# XXX -> _blkLastRevAccessed ? _blkRevLastAccessed ? _blkHeadRevAccessed ?
"""
def _blkHeadAccessed(t, zf, blk):
zfAccessed = t._accessed.get(zf, {})
zfAccessed.get(blk) vs t._blkRev(zf, blk, t.head)
"""
# tFile provides testing environment for one bigfile on wcfs. # tFile provides testing environment for one bigfile on wcfs.
# #
# ._blk() provides access to data of a block. .cached() gives state of which # ._blk() provides access to data of a block. .cached() gives state of which
...@@ -627,7 +623,7 @@ class tWatchLink: ...@@ -627,7 +623,7 @@ class tWatchLink:
# #
# fdopen takes ownership of file descriptor and closes it when file # fdopen takes ownership of file descriptor and closes it when file
# object is closed -> dup fd so that each file object has its own fd. # object is closed -> dup fd so that each file object has its own fd.
wh = os.open(tdb.path("head/watch"), os.O_RDWR) wh = os.open(tdb._path("head/watch"), os.O_RDWR)
wh2 = os.dup(wh) wh2 = os.dup(wh)
t._wrx = os.fdopen(wh, 'rb') t._wrx = os.fdopen(wh, 'rb')
t._wtx = os.fdopen(wh2, 'wb') t._wtx = os.fdopen(wh2, 'wb')
...@@ -1163,7 +1159,7 @@ def test_wcfs(): ...@@ -1163,7 +1159,7 @@ def test_wcfs():
# >>> lookup non-BigFile -> must be rejected # >>> lookup non-BigFile -> must be rejected
with raises(OSError) as exc: with raises(OSError) as exc:
t.stat(nonfile) t._stat(nonfile)
assert exc.value.errno == EINVAL assert exc.value.errno == EINVAL
# >>> file initially empty # >>> file initially empty
......
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