diff --git a/layer/filestore.go b/layer/filestore.go index a7454b5e9f..b1cbb80166 100644 --- a/layer/filestore.go +++ b/layer/filestore.go @@ -37,10 +37,10 @@ type fileMetadataTransaction struct { ws *ioutils.AtomicWriteSet } -// NewFSMetadataStore returns an instance of a metadata store +// newFSMetadataStore returns an instance of a metadata store // which is backed by files on disk using the provided root // as the root of metadata files. -func NewFSMetadataStore(root string) (MetadataStore, error) { +func newFSMetadataStore(root string) (*fileMetadataStore, error) { if err := os.MkdirAll(root, 0700); err != nil { return nil, err } @@ -66,7 +66,7 @@ func (fms *fileMetadataStore) getMountFilename(mount, filename string) string { return filepath.Join(fms.getMountDirectory(mount), filename) } -func (fms *fileMetadataStore) StartTransaction() (MetadataTransaction, error) { +func (fms *fileMetadataStore) StartTransaction() (*fileMetadataTransaction, error) { tmpDir := filepath.Join(fms.root, "tmp") if err := os.MkdirAll(tmpDir, 0755); err != nil { return nil, err diff --git a/layer/filestore_test.go b/layer/filestore_test.go index 8e6dd27f94..498379e37f 100644 --- a/layer/filestore_test.go +++ b/layer/filestore_test.go @@ -24,12 +24,12 @@ func newFileMetadataStore(t *testing.T) (*fileMetadataStore, string, func()) { if err != nil { t.Fatal(err) } - fms, err := NewFSMetadataStore(td) + fms, err := newFSMetadataStore(td) if err != nil { t.Fatal(err) } - return fms.(*fileMetadataStore), td, func() { + return fms, td, func() { if err := os.RemoveAll(td); err != nil { t.Logf("Failed to cleanup %q: %s", td, err) } diff --git a/layer/layer.go b/layer/layer.go index 48fa7cf3c4..d0c7fa8608 100644 --- a/layer/layer.go +++ b/layer/layer.go @@ -201,54 +201,6 @@ type DescribableStore interface { RegisterWithDescriptor(io.Reader, ChainID, distribution.Descriptor) (Layer, error) } -// MetadataTransaction represents functions for setting layer metadata -// with a single transaction. -type MetadataTransaction interface { - SetSize(int64) error - SetParent(parent ChainID) error - SetDiffID(DiffID) error - SetCacheID(string) error - SetDescriptor(distribution.Descriptor) error - setOS(string) error - TarSplitWriter(compressInput bool) (io.WriteCloser, error) - - Commit(ChainID) error - Cancel() error - String() string -} - -// MetadataStore represents a backend for persisting -// metadata about layers and providing the metadata -// for restoring a Store. -type MetadataStore interface { - // StartTransaction starts an update for new metadata - // which will be used to represent an ID on commit. - StartTransaction() (MetadataTransaction, error) - - GetSize(ChainID) (int64, error) - GetParent(ChainID) (ChainID, error) - GetDiffID(ChainID) (DiffID, error) - GetCacheID(ChainID) (string, error) - GetDescriptor(ChainID) (distribution.Descriptor, error) - getOS(ChainID) (string, error) - TarSplitReader(ChainID) (io.ReadCloser, error) - - SetMountID(string, string) error - SetInitID(string, string) error - SetMountParent(string, ChainID) error - - GetMountID(string) (string, error) - GetInitID(string) (string, error) - GetMountParent(string) (ChainID, error) - - // List returns the full list of referenced - // read-only and read-write layers - List() ([]ChainID, []string, error) - - Remove(ChainID) error - RemoveMount(string) error -} - // CreateChainID returns ID for a layerDigest slice func CreateChainID(dgsts []DiffID) ChainID { return createChainIDFromParent("", dgsts...) diff --git a/layer/layer_store.go b/layer/layer_store.go index ec8ecd6c17..bf0705afc5 100644 --- a/layer/layer_store.go +++ b/layer/layer_store.go @@ -27,7 +27,7 @@ import ( const maxLayerDepth = 125 type layerStore struct { - store MetadataStore + store *fileMetadataStore driver graphdriver.Driver useTarSplit bool @@ -65,18 +65,15 @@ func NewStoreFromOptions(options StoreOptions) (Store, error) { } logrus.Debugf("Initialized graph driver %s", driver) - fms, err := NewFSMetadataStore(fmt.Sprintf(options.MetadataStorePathTemplate, driver)) - if err != nil { - return nil, err - } + root := fmt.Sprintf(options.MetadataStorePathTemplate, driver) - return NewStoreFromGraphDriver(fms, driver, options.OS) + return newStoreFromGraphDriver(root, driver, options.OS) } -// NewStoreFromGraphDriver creates a new Store instance using the provided +// newStoreFromGraphDriver creates a new Store instance using the provided // metadata store and graph driver. The metadata store will be used to restore // the Store. -func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver, os string) (Store, error) { +func newStoreFromGraphDriver(root string, driver graphdriver.Driver, os string) (Store, error) { if !system.IsOSSupported(os) { return nil, fmt.Errorf("failed to initialize layer store as operating system '%s' is not supported", os) } @@ -85,8 +82,13 @@ func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver, os caps = capDriver.Capabilities() } + ms, err := newFSMetadataStore(root) + if err != nil { + return nil, err + } + ls := &layerStore{ - store: store, + store: ms, driver: driver, layerMap: map[ChainID]*roLayer{}, mounts: map[string]*mountedLayer{}, @@ -94,7 +96,7 @@ func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver, os os: os, } - ids, mounts, err := store.List() + ids, mounts, err := ms.List() if err != nil { return nil, err } @@ -225,7 +227,7 @@ func (ls *layerStore) loadMount(mount string) error { return nil } -func (ls *layerStore) applyTar(tx MetadataTransaction, ts io.Reader, parent string, layer *roLayer) error { +func (ls *layerStore) applyTar(tx *fileMetadataTransaction, ts io.Reader, parent string, layer *roLayer) error { digester := digest.Canonical.Digester() tr := io.TeeReader(ts, digester.Hash()) diff --git a/layer/layer_test.go b/layer/layer_test.go index 0bf25bc72b..5c4e8fab19 100644 --- a/layer/layer_test.go +++ b/layer/layer_test.go @@ -69,11 +69,8 @@ func newTestStore(t *testing.T) (Store, string, func()) { } graph, graphcleanup := newTestGraphDriver(t) - fms, err := NewFSMetadataStore(td) - if err != nil { - t.Fatal(err) - } - ls, err := NewStoreFromGraphDriver(fms, graph, runtime.GOOS) + + ls, err := newStoreFromGraphDriver(td, graph, runtime.GOOS) if err != nil { t.Fatal(err) } @@ -403,7 +400,7 @@ func TestStoreRestore(t *testing.T) { t.Fatal(err) } - ls2, err := NewStoreFromGraphDriver(ls.(*layerStore).store, ls.(*layerStore).driver, runtime.GOOS) + ls2, err := newStoreFromGraphDriver(ls.(*layerStore).store.root, ls.(*layerStore).driver, runtime.GOOS) if err != nil { t.Fatal(err) } diff --git a/layer/migration_test.go b/layer/migration_test.go index 2c6800f151..923166371c 100644 --- a/layer/migration_test.go +++ b/layer/migration_test.go @@ -90,11 +90,8 @@ func TestLayerMigration(t *testing.T) { t.Fatal(err) } - fms, err := NewFSMetadataStore(filepath.Join(td, "layers")) - if err != nil { - t.Fatal(err) - } - ls, err := NewStoreFromGraphDriver(fms, graph, runtime.GOOS) + root := filepath.Join(td, "layers") + ls, err := newStoreFromGraphDriver(root, graph, runtime.GOOS) if err != nil { t.Fatal(err) } @@ -218,11 +215,8 @@ func TestLayerMigrationNoTarsplit(t *testing.T) { t.Fatal(err) } - fms, err := NewFSMetadataStore(filepath.Join(td, "layers")) - if err != nil { - t.Fatal(err) - } - ls, err := NewStoreFromGraphDriver(fms, graph, runtime.GOOS) + root := filepath.Join(td, "layers") + ls, err := newStoreFromGraphDriver(root, graph, runtime.GOOS) if err != nil { t.Fatal(err) } diff --git a/layer/ro_layer.go b/layer/ro_layer.go index e1f1b407c2..bc0fe1dddf 100644 --- a/layer/ro_layer.go +++ b/layer/ro_layer.go @@ -121,7 +121,7 @@ func (rl *roLayer) depth() int { return rl.parent.depth() + 1 } -func storeLayer(tx MetadataTransaction, layer *roLayer) error { +func storeLayer(tx *fileMetadataTransaction, layer *roLayer) error { if err := tx.SetDiffID(layer.diffID); err != nil { return err }