Browse code

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 <derek@mcgstyle.net>

Derek McGowan authored on 2018/03/06 08:46:21
Showing 7 changed files
... ...
@@ -37,10 +37,10 @@ type fileMetadataTransaction struct {
37 37
 	ws    *ioutils.AtomicWriteSet
38 38
 }
39 39
 
40
-// NewFSMetadataStore returns an instance of a metadata store
40
+// newFSMetadataStore returns an instance of a metadata store
41 41
 // which is backed by files on disk using the provided root
42 42
 // as the root of metadata files.
43
-func NewFSMetadataStore(root string) (MetadataStore, error) {
43
+func newFSMetadataStore(root string) (*fileMetadataStore, error) {
44 44
 	if err := os.MkdirAll(root, 0700); err != nil {
45 45
 		return nil, err
46 46
 	}
... ...
@@ -66,7 +66,7 @@ func (fms *fileMetadataStore) getMountFilename(mount, filename string) string {
66 66
 	return filepath.Join(fms.getMountDirectory(mount), filename)
67 67
 }
68 68
 
69
-func (fms *fileMetadataStore) StartTransaction() (MetadataTransaction, error) {
69
+func (fms *fileMetadataStore) StartTransaction() (*fileMetadataTransaction, error) {
70 70
 	tmpDir := filepath.Join(fms.root, "tmp")
71 71
 	if err := os.MkdirAll(tmpDir, 0755); err != nil {
72 72
 		return nil, err
... ...
@@ -24,12 +24,12 @@ func newFileMetadataStore(t *testing.T) (*fileMetadataStore, string, func()) {
24 24
 	if err != nil {
25 25
 		t.Fatal(err)
26 26
 	}
27
-	fms, err := NewFSMetadataStore(td)
27
+	fms, err := newFSMetadataStore(td)
28 28
 	if err != nil {
29 29
 		t.Fatal(err)
30 30
 	}
31 31
 
32
-	return fms.(*fileMetadataStore), td, func() {
32
+	return fms, td, func() {
33 33
 		if err := os.RemoveAll(td); err != nil {
34 34
 			t.Logf("Failed to cleanup %q: %s", td, err)
35 35
 		}
... ...
@@ -201,54 +201,6 @@ type DescribableStore interface {
201 201
 	RegisterWithDescriptor(io.Reader, ChainID, distribution.Descriptor) (Layer, error)
202 202
 }
203 203
 
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
-
252 204
 // CreateChainID returns ID for a layerDigest slice
253 205
 func CreateChainID(dgsts []DiffID) ChainID {
254 206
 	return createChainIDFromParent("", dgsts...)
... ...
@@ -27,7 +27,7 @@ import (
27 27
 const maxLayerDepth = 125
28 28
 
29 29
 type layerStore struct {
30
-	store       MetadataStore
30
+	store       *fileMetadataStore
31 31
 	driver      graphdriver.Driver
32 32
 	useTarSplit bool
33 33
 
... ...
@@ -65,18 +65,15 @@ func NewStoreFromOptions(options StoreOptions) (Store, error) {
65 65
 	}
66 66
 	logrus.Debugf("Initialized graph driver %s", driver)
67 67
 
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)
72 69
 
73
-	return NewStoreFromGraphDriver(fms, driver, options.OS)
70
+	return newStoreFromGraphDriver(root, driver, options.OS)
74 71
 }
75 72
 
76
-// NewStoreFromGraphDriver creates a new Store instance using the provided
73
+// newStoreFromGraphDriver creates a new Store instance using the provided
77 74
 // metadata store and graph driver. The metadata store will be used to restore
78 75
 // 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) {
80 77
 	if !system.IsOSSupported(os) {
81 78
 		return nil, fmt.Errorf("failed to initialize layer store as operating system '%s' is not supported", os)
82 79
 	}
... ...
@@ -85,8 +82,13 @@ func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver, os
85 85
 		caps = capDriver.Capabilities()
86 86
 	}
87 87
 
88
+	ms, err := newFSMetadataStore(root)
89
+	if err != nil {
90
+		return nil, err
91
+	}
92
+
88 93
 	ls := &layerStore{
89
-		store:       store,
94
+		store:       ms,
90 95
 		driver:      driver,
91 96
 		layerMap:    map[ChainID]*roLayer{},
92 97
 		mounts:      map[string]*mountedLayer{},
... ...
@@ -94,7 +96,7 @@ func NewStoreFromGraphDriver(store MetadataStore, driver graphdriver.Driver, os
94 94
 		os:          os,
95 95
 	}
96 96
 
97
-	ids, mounts, err := store.List()
97
+	ids, mounts, err := ms.List()
98 98
 	if err != nil {
99 99
 		return nil, err
100 100
 	}
... ...
@@ -225,7 +227,7 @@ func (ls *layerStore) loadMount(mount string) error {
225 225
 	return nil
226 226
 }
227 227
 
228
-func (ls *layerStore) applyTar(tx MetadataTransaction, ts io.Reader, parent string, layer *roLayer) error {
228
+func (ls *layerStore) applyTar(tx *fileMetadataTransaction, ts io.Reader, parent string, layer *roLayer) error {
229 229
 	digester := digest.Canonical.Digester()
230 230
 	tr := io.TeeReader(ts, digester.Hash())
231 231
 
... ...
@@ -69,11 +69,8 @@ func newTestStore(t *testing.T) (Store, string, func()) {
69 69
 	}
70 70
 
71 71
 	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)
77 74
 	if err != nil {
78 75
 		t.Fatal(err)
79 76
 	}
... ...
@@ -403,7 +400,7 @@ func TestStoreRestore(t *testing.T) {
403 403
 		t.Fatal(err)
404 404
 	}
405 405
 
406
-	ls2, err := NewStoreFromGraphDriver(ls.(*layerStore).store, ls.(*layerStore).driver, runtime.GOOS)
406
+	ls2, err := newStoreFromGraphDriver(ls.(*layerStore).store.root, ls.(*layerStore).driver, runtime.GOOS)
407 407
 	if err != nil {
408 408
 		t.Fatal(err)
409 409
 	}
... ...
@@ -90,11 +90,8 @@ func TestLayerMigration(t *testing.T) {
90 90
 		t.Fatal(err)
91 91
 	}
92 92
 
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)
98 95
 	if err != nil {
99 96
 		t.Fatal(err)
100 97
 	}
... ...
@@ -218,11 +215,8 @@ func TestLayerMigrationNoTarsplit(t *testing.T) {
218 218
 		t.Fatal(err)
219 219
 	}
220 220
 
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)
221
+	root := filepath.Join(td, "layers")
222
+	ls, err := newStoreFromGraphDriver(root, graph, runtime.GOOS)
226 223
 	if err != nil {
227 224
 		t.Fatal(err)
228 225
 	}
... ...
@@ -121,7 +121,7 @@ func (rl *roLayer) depth() int {
121 121
 	return rl.parent.depth() + 1
122 122
 }
123 123
 
124
-func storeLayer(tx MetadataTransaction, layer *roLayer) error {
124
+func storeLayer(tx *fileMetadataTransaction, layer *roLayer) error {
125 125
 	if err := tx.SetDiffID(layer.diffID); err != nil {
126 126
 		return err
127 127
 	}