Commit 9b5b068c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6a1e4f53
......@@ -455,14 +455,6 @@ type ZConn struct {
// read-only transaction under which we access zodb.Connection data.
txnCtx context.Context // XXX -> better directly store txn
/* XXX redecided to purge files and @<rev>/ on atime timeout
// for historic @<rev> access the connection can be shared between several bigfiles.
// since we want to free such connections when no longer needed we
// return zodb.Connection back to zodb.DB when refcnt drops to 0.
refcnt int32
*/
}
// zopen opens new connection to ZODB database + associated read-only transaction.
......@@ -487,109 +479,9 @@ func zopen(ctx context.Context, zdb *zodb.DB, zopt *zodb.ConnOptions) (_ *ZConn,
return &ZConn{
Connection: zconn,
txnCtx: txnCtx,
// refcnt: 1,
}, nil
}
/*
// Release decrements reference count and releases connection back to zodb.DB
// if it is no longer used.
func (zc *ZConn) Release() {
rc := atomic.AddInt32(&zc.refcnt, -1)
if rc < 0 {
panic("ZConn.Release: refcnt < 0")
}
if rc > 0 {
return
}
txn := transaction.Current(zc.txnCtx)
txn.Abort()
zc.Connection = nil
zc.txnCtx = nil
}
// Incref increments connection's reference counter by 1.
func (zc *ZConn) Incref() {
rc := atomic.AddInt32(&zc.refcnt, +1)
if rc <= 1 {
panic("Zconn.Incref: refcnt was < 1")
}
}
// zopenAt opens historic connection @<rev>.
//
// if the connection for this @<rev> was already opened - it is shared.
func (r *Root) zopenAt(ctx context.Context, rev zodb.Tid) (_ *ZConn, err error) {
// check if zconn for @<rev> is already there
r.revMu.Lock()
zconn := r.revTab[rev]
if zconn != nil {
if atomic.LoadInt32(&zconn.refcnt) > 0 {
zconn.Incref()
} else {
zconn = nil // in-progress destruction
}
}
r.revMu.Unlock()
if zconn != nil {
return zconn, nil
}
// not there - without revMu lock proceed to open it
zconn, err = zopen(ctx, r.zdb, &zodb.ConnOptions{At: rev})
if err != nil {
return nil, err
}
// relock revTab and either register zconn, or return another zconn2,
// that might have been opened while we were not holding revMu.
r.revMu.Lock()
defer r.revMu.Unlock()
zconn2 := r.revTab[rev]
if zconn2 != nil {
if atomic.LoadInt32(&zconn2.refcnt) > 0 {
zconn.Release() // FIXME aborts txn -> just drop zconn
zconn2.Incref()
return zconn2, nil
}
// else it was another in-progress destruction
}
r.revTab[rev] = zconn
// schedule del revTab[rev] on zconn destroy
txn := transaction.Current(zconn.txnCtx)
txn.RegisterSync(&zrevTabUnregister{r, zconn})
return zconn, nil
}
// zrevTabUnregister unregisters zconn from root.revTab on zconn's transaction abort.
type zrevTabUnregister struct {
root *Root
zconn *ZConn
}
func (u *zrevTabUnregister) BeforeCompletion(txn transaction.Transaction) {}
func (u *zrevTabUnregister) AfterCompletion(txn transaction.Transaction) {
rev := u.zconn.At()
u.root.revMu.Lock()
defer u.root.revMu.Unlock()
// delete only if zconn is still registered - as another zconn2 might have
// been already registered instead while zconn was in revTab with refcnt=0.
if u.root.revTab[rev] == u.zconn {
delete(u.root.revTab, rev)
}
}
*/
// tidmax returns latest revision.
func tidmax(a, b zodb.Tid) zodb.Tid {
if a > b {
......
......@@ -2040,6 +2040,7 @@ func (root *Root) lookup(name string, fctx *fuse.Context) (_ *Head, err error) {
root.revMu.Unlock()
if already {
// XXX race wrt simlutaneous "FORGET @<rev>" ?
return revDir, nil
}
......@@ -2065,7 +2066,7 @@ func (root *Root) lookup(name string, fctx *fuse.Context) (_ *Head, err error) {
revDir = &Head{
fsNode: newFSNode(&fsOptions{Sticky: false}), // XXX + Head.OnForget() -> del root.revTab[]
rev: rev,
zconn: zconnRev,
zconn: zconnRev, // XXX + Head.OnForget() -> release zconn (= abort zconn.txnCtx)
}
bfdir := &BigFileDir{
......
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