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

.

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