Remove distinction between RootTracker and ChunkStore in DataStore

This commit is contained in:
Aaron Boodman
2015-07-05 23:05:51 -07:00
parent 2cea5d0340
commit cb1fb984b3
4 changed files with 11 additions and 11 deletions
+1
View File
@@ -9,6 +9,7 @@ import (
type ChunkStore interface {
ChunkSource
ChunkSink
RootTracker
}
type RootTracker interface {
+1 -1
View File
@@ -17,7 +17,7 @@ func main() {
flag.Usage()
return
}
ds := datastore.NewDataStore(cs, cs.(chunks.RootTracker))
ds := datastore.NewDataStore(cs)
lastVal := uint64(0)
roots := ds.Roots()
+8 -9
View File
@@ -13,18 +13,17 @@ import (
type DataStore struct {
chunks.ChunkStore
rt chunks.RootTracker
rc *rootCache
roots RootSet
}
func NewDataStore(cs chunks.ChunkStore, rt chunks.RootTracker) DataStore {
return NewDataStoreWithCache(cs, rt, NewRootCache(cs))
func NewDataStore(cs chunks.ChunkStore) DataStore {
return newDataStoreInternal(cs, NewRootCache(cs))
}
func NewDataStoreWithCache(cs chunks.ChunkStore, rt chunks.RootTracker, rc *rootCache) DataStore {
func newDataStoreInternal(cs chunks.ChunkStore, rc *rootCache) DataStore {
var roots RootSet
rootRef := rt.Root()
rootRef := cs.Root()
if (rootRef == ref.Ref{}) {
roots = NewRootSet()
} else {
@@ -32,7 +31,7 @@ func NewDataStoreWithCache(cs chunks.ChunkStore, rt chunks.RootTracker, rc *root
roots = RootSetFromVal(enc.MustReadValue(rootRef, cs).(types.Set))
}
return DataStore{
cs, rt, rc, roots,
cs, rc, roots,
}
}
@@ -55,11 +54,11 @@ func (ds *DataStore) Commit(newRoots RootSet) DataStore {
for !ds.doCommit(newRoots, RootSet{superceded}) {
}
return NewDataStoreWithCache(ds.ChunkStore, ds.rt, ds.rc)
return newDataStoreInternal(ds.ChunkStore, ds.rc)
}
func (ds *DataStore) doCommit(add, remove RootSet) bool {
oldRootRef := ds.rt.Root()
oldRootRef := ds.Root()
oldRoots := ds.Roots()
prexisting := make([]Root, 0)
@@ -81,5 +80,5 @@ func (ds *DataStore) doCommit(add, remove RootSet) bool {
newRootRef, err := enc.WriteValue(newRoots.NomsValue(), ds)
Chk.NoError(err)
return ds.rt.UpdateRoot(newRootRef, oldRootRef)
return ds.UpdateRoot(newRootRef, oldRootRef)
}
+1 -1
View File
@@ -18,7 +18,7 @@ func TestDataStoreCommit(t *testing.T) {
assert.NoError(err)
chunks := chunks.NewFileStore(dir, "root")
ds := NewDataStore(chunks, chunks)
ds := NewDataStore(chunks)
roots := ds.Roots()
assert.Equal(uint64(0), roots.Len())