Replace lockfile with reference lock

Updates content service to handle lock errors and return
them to the client. The client remote handler has been
updated to retry when a resource is locked until the
resource is unlocked or the expected resource exists.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-06-08 16:07:38 -07:00
parent a6314cad65
commit 1cdb010783
13 changed files with 69 additions and 394 deletions

View File

@@ -5,8 +5,6 @@ import (
"path/filepath"
"time"
"github.com/containerd/containerd/log"
"github.com/nightlyone/lockfile"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
)
@@ -15,9 +13,8 @@ import (
type writer struct {
s *store
fp *os.File // opened data file
lock lockfile.Lockfile
path string // path to writer dir
ref string // ref key
path string // path to writer dir
ref string // ref key
offset int64
total int64
digester digest.Digester
@@ -107,8 +104,9 @@ func (w *writer) Commit(size int64, expected digest.Digest) error {
return err
}
unlock(w.lock)
unlock(w.ref)
w.fp = nil
return nil
}
@@ -122,9 +120,7 @@ func (w *writer) Commit(size int64, expected digest.Digest) error {
// To abandon a transaction completely, first call close then `Store.Remove` to
// clean up the associated resources.
func (cw *writer) Close() (err error) {
if err := unlock(cw.lock); err != nil {
log.L.Debug("unlock failed: %v", err)
}
unlock(cw.ref)
if cw.fp != nil {
cw.fp.Sync()