Skip to content

Commit 0aebcbc

Browse files
committed
Remove metadata store interface
Layer metadata storage has not been implemented outside of the layer store and will be deprecated by containerd metadata storage. To prepare for this and freeze the current metadata storage, remove the exported interface and make it internal to the layer store. Signed-off-by: Derek McGowan <[email protected]>
1 parent 78efc2f commit 0aebcbc

File tree

7 files changed

+26
-81
lines changed

7 files changed

+26
-81
lines changed

layer/filestore.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ type fileMetadataTransaction struct {
3737
ws *ioutils.AtomicWriteSet
3838
}
3939

40-
// NewFSMetadataStore returns an instance of a metadata store
40+
// newFSMetadataStore returns an instance of a metadata store
4141
// which is backed by files on disk using the provided root
4242
// as the root of metadata files.
43-
func NewFSMetadataStore(root string) (MetadataStore, error) {
43+
func newFSMetadataStore(root string) (*fileMetadataStore, error) {
4444
if err := os.MkdirAll(root, 0700); err != nil {
4545
return nil, err
4646
}
@@ -66,7 +66,7 @@ func (fms *fileMetadataStore) getMountFilename(mount, filename string) string {
6666
return filepath.Join(fms.getMountDirectory(mount), filename)
6767
}
6868

69-
func (fms *fileMetadataStore) StartTransaction() (MetadataTransaction, error) {
69+
func (fms *fileMetadataStore) StartTransaction() (*fileMetadataTransaction, error) {
7070
tmpDir := filepath.Join(fms.root, "tmp")
7171
if err := os.MkdirAll(tmpDir, 0755); err != nil {
7272
return nil, err

layer/filestore_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ func newFileMetadataStore(t *testing.T) (*fileMetadataStore, string, func()) {
2424
if err != nil {
2525
t.Fatal(err)
2626
}
27-
fms, err := NewFSMetadataStore(td)
27+
fms, err := newFSMetadataStore(td)
2828
if err != nil {
2929
t.Fatal(err)
3030
}
3131

32-
return fms.(*fileMetadataStore), td, func() {
32+
return fms, td, func() {
3333
if err := os.RemoveAll(td); err != nil {
3434
t.Logf("Failed to cleanup %q: %s", td, err)
3535
}

layer/layer.go

-48
Original file line numberDiff line numberDiff line change
@@ -201,54 +201,6 @@ type DescribableStore interface {
201201
RegisterWithDescriptor(io.Reader, ChainID, distribution.Descriptor) (Layer, error)
202202
}
203203

204-
// MetadataTransaction represents functions for setting layer metadata
205-
// with a single transaction.
206-
type MetadataTransaction interface {
207-
SetSize(int64) error
208-
SetParent(parent ChainID) error
209-
SetDiffID(DiffID) error
210-
SetCacheID(string) error
211-
SetDescriptor(distribution.Descriptor) error
212-
setOS(string) error
213-
TarSplitWriter(compressInput bool) (io.WriteCloser, error)
214-
215-
Commit(ChainID) error
216-
Cancel() error
217-
String() string
218-
}
219-
220-
// MetadataStore represents a backend for persisting
221-
// metadata about layers and providing the metadata
222-
// for restoring a Store.
223-
type MetadataStore interface {
224-
// StartTransaction starts an update for new metadata
225-
// which will be used to represent an ID on commit.
226-
StartTransaction() (MetadataTransaction, error)
227-
228-
GetSize(ChainID) (int64, error)
229-
GetParent(ChainID) (ChainID, error)
230-
GetDiffID(ChainID) (DiffID, error)
231-
GetCacheID(ChainID) (string, error)
232-
GetDescriptor(ChainID) (distribution.Descriptor, error)
233-
getOS(ChainID) (string, error)
234-
TarSplitReader(ChainID) (io.ReadCloser, error)
235-
236-
SetMountID(string, string) error
237-
SetInitID(string, string) error
238-
SetMountParent(string, ChainID) error
239-
240-
GetMountID(string) (string, error)
241-
GetInitID(string) (string, error)
242-
GetMountParent(string) (ChainID, error)
243-
244-
// List returns the full list of referenced
245-
// read-only and read-write layers
246-
List() ([]ChainID, []string, error)
247-
248-
Remove(ChainID) error
249-
RemoveMount(string) error
250-
}
251-
252204
// CreateChainID returns ID for a layerDigest slice
253205
func CreateChainID(dgsts []DiffID) ChainID {
254206
return createChainIDFromParent("", dgsts...)

layer/layer_store.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
const maxLayerDepth = 125
2828

2929
type layerStore struct {
30-
store MetadataStore
30+
store *fileMetadataStore
3131
driver graphdriver.Driver
3232
useTarSplit bool
3333

@@ -65,18 +65,15 @@ func NewStoreFromOptions(options StoreOptions) (Store, error) {
6565
}
6666
logrus.Debugf("Initialized graph driver %s", driver)
6767

68-
fms, err := NewFSMetadataStore(fmt.Sprintf(options.MetadataStorePathTemplate, driver))
69-
if err != nil {
70-
return nil, err
71-
}
68+
root := fmt.Sprintf(options.MetadataStorePathTemplate, driver)
7269

73-
return NewStoreFromGraphDriver(fms, driver, options.OS)
70+
return newStoreFromGraphDriver(root, driver, options.OS)
7471
}
7572

76-
// NewStoreFromGraphDriver creates a new Store instance using the provided
73+
// newStoreFromGraphDriver creates a new Store instance using the provided
7774
// metadata store and graph driver. The metadata store will be used to restore
7875
// the Store.
79-
func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver, os string) (Store, error) {
76+
func newStoreFromGraphDriver(root string, driver graphdriver.Driver, os string) (Store, error) {
8077
if !system.IsOSSupported(os) {
8178
return nil, fmt.Errorf("failed to initialize layer store as operating system '%s' is not supported", os)
8279
}
@@ -85,16 +82,21 @@ func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver, os
8582
caps = capDriver.Capabilities()
8683
}
8784

85+
ms, err := newFSMetadataStore(root)
86+
if err != nil {
87+
return nil, err
88+
}
89+
8890
ls := &layerStore{
89-
store: store,
91+
store: ms,
9092
driver: driver,
9193
layerMap: map[ChainID]*roLayer{},
9294
mounts: map[string]*mountedLayer{},
9395
useTarSplit: !caps.ReproducesExactDiffs,
9496
os: os,
9597
}
9698

97-
ids, mounts, err := store.List()
99+
ids, mounts, err := ms.List()
98100
if err != nil {
99101
return nil, err
100102
}
@@ -225,7 +227,7 @@ func (ls *layerStore) loadMount(mount string) error {
225227
return nil
226228
}
227229

228-
func (ls *layerStore) applyTar(tx MetadataTransaction, ts io.Reader, parent string, layer *roLayer) error {
230+
func (ls *layerStore) applyTar(tx *fileMetadataTransaction, ts io.Reader, parent string, layer *roLayer) error {
229231
digester := digest.Canonical.Digester()
230232
tr := io.TeeReader(ts, digester.Hash())
231233

layer/layer_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,8 @@ func newTestStore(t *testing.T) (Store, string, func()) {
6969
}
7070

7171
graph, graphcleanup := newTestGraphDriver(t)
72-
fms, err := NewFSMetadataStore(td)
73-
if err != nil {
74-
t.Fatal(err)
75-
}
76-
ls, err := NewStoreFromGraphDriver(fms, graph, runtime.GOOS)
72+
73+
ls, err := newStoreFromGraphDriver(td, graph, runtime.GOOS)
7774
if err != nil {
7875
t.Fatal(err)
7976
}
@@ -403,7 +400,7 @@ func TestStoreRestore(t *testing.T) {
403400
t.Fatal(err)
404401
}
405402

406-
ls2, err := NewStoreFromGraphDriver(ls.(*layerStore).store, ls.(*layerStore).driver, runtime.GOOS)
403+
ls2, err := newStoreFromGraphDriver(ls.(*layerStore).store.root, ls.(*layerStore).driver, runtime.GOOS)
407404
if err != nil {
408405
t.Fatal(err)
409406
}

layer/migration_test.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ func TestLayerMigration(t *testing.T) {
9090
t.Fatal(err)
9191
}
9292

93-
fms, err := NewFSMetadataStore(filepath.Join(td, "layers"))
94-
if err != nil {
95-
t.Fatal(err)
96-
}
97-
ls, err := NewStoreFromGraphDriver(fms, graph, runtime.GOOS)
93+
root := filepath.Join(td, "layers")
94+
ls, err := newStoreFromGraphDriver(root, graph, runtime.GOOS)
9895
if err != nil {
9996
t.Fatal(err)
10097
}
@@ -218,11 +215,8 @@ func TestLayerMigrationNoTarsplit(t *testing.T) {
218215
t.Fatal(err)
219216
}
220217

221-
fms, err := NewFSMetadataStore(filepath.Join(td, "layers"))
222-
if err != nil {
223-
t.Fatal(err)
224-
}
225-
ls, err := NewStoreFromGraphDriver(fms, graph, runtime.GOOS)
218+
root := filepath.Join(td, "layers")
219+
ls, err := newStoreFromGraphDriver(root, graph, runtime.GOOS)
226220
if err != nil {
227221
t.Fatal(err)
228222
}

layer/ro_layer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (rl *roLayer) depth() int {
121121
return rl.parent.depth() + 1
122122
}
123123

124-
func storeLayer(tx MetadataTransaction, layer *roLayer) error {
124+
func storeLayer(tx *fileMetadataTransaction, layer *roLayer) error {
125125
if err := tx.SetDiffID(layer.diffID); err != nil {
126126
return err
127127
}

0 commit comments

Comments
 (0)