Commit 991d1453 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b720f172
......@@ -410,6 +410,7 @@ type Root struct {
// ZODB DB handle for zstor.
// keeps cache of connections for both head/ and @<rev>/ accesses.
// XXX head won't be kept here and will be .Resync()'ed explicitly?
//
// only one connection is used for head/ and only one for each @<rev>.
zdb *zodb.DB
......@@ -426,12 +427,15 @@ type Root struct {
type Head struct {
nodefs.Node
rev zodb.Tid // 0 for head/, !0 for @<rev>/
bfdir *BigFileDir
// at, watch, etc - all implicitly linked to by fs
bfdir *BigFileDir // bigfile/
// at - served by .readAt
// watch - implicitly linked to by fs
// ZODB connection for everything under this head
zconnMu sync.RWMutex // protects access to zconn & live _objects_ associated with it
zconn *ZConn // for head/ zwatcher resyncs head.zconn; others only read zconn objects.
// XXX move zconn's current transaction to Head here?
}
// /head/watch - served by Watch.
......@@ -447,15 +451,15 @@ type BigFileDir struct {
head *Head // parent head/ or @<rev>/
// {} oid -> <bigfileX>
mu sync.Mutex
tab map[zodb.Oid]*BigFile
mu sync.Mutex
fileTab map[zodb.Oid]*BigFile
}
// /(head|<rev>)/bigfile/<bigfileX> - served by BigFile.
type BigFile struct {
nodefs.Node
// this BigFile is under head; it views ZODB via head.zconn
// this BigFile is under .head/bigfile/; it views ZODB via .head.zconn
// parent's BigFileDir.head is the same.
head *Head
......@@ -465,8 +469,8 @@ type BigFile struct {
// zbf.Size(). It is constant during liftime of current transaction.
zbfSize int64
// change history of this file.
δFtail *ΔTailI64 // [](rev, []#blk)
// tail change history of this file.
δFtail *ΔTailI64 // [](rev, []#blk)
// TODO -> δFtail
// lastChange zodb.Tid // last change to whole bigfile as of .zconn.At view
......@@ -578,7 +582,7 @@ func (r *Root) zhandle1(zevent zodb.WatchEvent) {
// bfdir locking: similarly not needed, since we are
// exclusively holding head lock.
for zfile, objBlk := range obj.blkBoundTo() {
file, ok := bfdir.tab[zfile.POid()]
file, ok := bfdir.fileTab[zfile.POid()]
if !ok {
// even though zfile is in ZODB cache, the
// filesystem already forgot about this file.
......@@ -690,6 +694,14 @@ func (root *Root) mkrevfile(rev zodb.Tid, fid zodb.Oid) (_ *BigFile, err error)
// ----------------------------------------
// /(head|<rev>)/at -> readAt serves read.
func (h *Head) readAt() []byte {
h.zconnMu.RLock()
defer h.zconnMu.RUnlock()
return []byte(h.zconn.At().String())
}
// /(head|<rev>)/bigfile/ -> Lookup receives client request to create /(head|<rev>)/bigfile/<bigfileX>.
func (bfdir *BigFileDir) Lookup(out *fuse.Attr, name string, fctx *fuse.Context) (*nodefs.Inode, fuse.Status) {
f, err := bfdir.lookup(out, name, fctx)
......@@ -720,7 +732,7 @@ func (bfdir *BigFileDir) lookup(out *fuse.Attr, name string, fctx *fuse.Context)
// check to see if dir(oid) is already there
bfdir.mu.Lock()
f, already := bfdir.tab[oid]
f, already := bfdir.fileTab[oid]
bfdir.mu.Unlock()
if already {
......@@ -736,14 +748,14 @@ func (bfdir *BigFileDir) lookup(out *fuse.Attr, name string, fctx *fuse.Context)
// relock bfdir and either register f or, if the file was maybe
// simultanously created while we were not holding bfdir.mu, return that.
bfdir.mu.Lock()
f2, already := bfdir.tab[oid]
f2, already := bfdir.fileTab[oid]
if already {
bfdir.mu.Unlock()
f.Close()
return f2, nil
}
bfdir.tab[oid] = f
bfdir.fileTab[oid] = f
bfdir.mu.Unlock()
// mkfile takes filesystem treeLock - do it outside bfdir.mu
......@@ -813,9 +825,9 @@ func (root *Root) mkdir(name string, fctx *fuse.Context) (_ *nodefs.Inode, err e
}
bfdir := &BigFileDir{
Node: nodefs.NewDefaultNode(),
head: revDir,
tab: make(map[zodb.Oid]*BigFile),
Node: nodefs.NewDefaultNode(),
head: revDir,
fileTab: make(map[zodb.Oid]*BigFile),
}
revDir.bfdir = bfdir
......@@ -1097,14 +1109,6 @@ func (f *BigFile) readBlk(ctx context.Context, blk int64, dest []byte) error {
}
// /(head|<rev>)/at -> readAt serves read.
func (h *Head) readAt() []byte {
h.zconnMu.RLock()
defer h.zconnMu.RUnlock()
return []byte(h.zconn.At().String())
}
......@@ -1170,9 +1174,9 @@ func main() {
zconn: zhead,
}
bfdir := &BigFileDir{
Node: nodefs.NewDefaultNode(),
head: head,
tab: make(map[zodb.Oid]*BigFile),
Node: nodefs.NewDefaultNode(),
head: head,
fileTab: make(map[zodb.Oid]*BigFile),
}
head.bfdir = bfdir
......
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