metadata: add content lease on existing content

When a writer is requested for an object that already
exists, add that object to the provided any lease to prevent
other operations from affecting the current lease's use of
that content.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2018-01-05 10:56:31 -08:00
parent ab7150f0ff
commit 0d8b093361
3 changed files with 134 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"runtime/pprof"
"strings"
"testing"
"time"
@@ -29,6 +30,44 @@ import (
"github.com/pkg/errors"
)
func testDB(t *testing.T) (context.Context, *DB, func()) {
ctx, cancel := context.WithCancel(context.Background())
ctx = namespaces.WithNamespace(ctx, "testing")
dirname, err := ioutil.TempDir("", strings.Replace(t.Name(), "/", "_", -1)+"-")
if err != nil {
t.Fatal(err)
}
snapshotter, err := naive.NewSnapshotter(filepath.Join(dirname, "naive"))
if err != nil {
t.Fatal(err)
}
cs, err := local.NewStore(filepath.Join(dirname, "content"))
if err != nil {
t.Fatal(err)
}
bdb, err := bolt.Open(filepath.Join(dirname, "metadata.db"), 0644, nil)
if err != nil {
t.Fatal(err)
}
db := NewDB(bdb, cs, map[string]snapshots.Snapshotter{"naive": snapshotter})
if err := db.Init(ctx); err != nil {
t.Fatal(err)
}
return ctx, db, func() {
bdb.Close()
if err := os.RemoveAll(dirname); err != nil {
t.Log("failed removing temp dir", err)
}
cancel()
}
}
func TestInit(t *testing.T) {
ctx, db, cancel := testEnv(t)
defer cancel()