diff --git a/internal/db/fetcher/dag.go b/internal/db/fetcher/dag.go index 9c4d5281da..e637d83358 100644 --- a/internal/db/fetcher/dag.go +++ b/internal/db/fetcher/dag.go @@ -88,7 +88,7 @@ func (hf *HeadFetcher) FetchNext() (*cid.Cid, error) { return nil, nil } - headStoreKey, err := keys.NewHeadStoreKey(res.Key) + headStoreKey, err := keys.NewHeadstoreDocKey(res.Key) if err != nil { return nil, err } diff --git a/internal/db/p2p_replicator.go b/internal/db/p2p_replicator.go index 61c082d210..05fb88b948 100644 --- a/internal/db/p2p_replicator.go +++ b/internal/db/p2p_replicator.go @@ -646,7 +646,7 @@ func (db *db) retryDoc(ctx context.Context, docID string) error { return err } defer txn.Discard(ctx) - headStoreKey := keys.HeadStoreKey{ + headStoreKey := keys.HeadstoreDocKey{ DocID: docID, FieldID: core.COMPOSITE_NAMESPACE, } diff --git a/internal/keys/datastore_doc.go b/internal/keys/datastore_doc.go index cd8ac60917..258357de83 100644 --- a/internal/keys/datastore_doc.go +++ b/internal/keys/datastore_doc.go @@ -112,8 +112,8 @@ func (k DataStoreKey) WithFieldID(fieldID string) DataStoreKey { return newKey } -func (k DataStoreKey) ToHeadStoreKey() HeadStoreKey { - return HeadStoreKey{ +func (k DataStoreKey) ToHeadStoreKey() HeadstoreDocKey { + return HeadstoreDocKey{ DocID: k.DocID, FieldID: k.FieldID, } diff --git a/internal/keys/headstore_doc.go b/internal/keys/headstore_doc.go index 5b2bb280d3..ad40984663 100644 --- a/internal/keys/headstore_doc.go +++ b/internal/keys/headstore_doc.go @@ -17,33 +17,33 @@ import ( ds "github.com/ipfs/go-datastore" ) -type HeadStoreKey struct { +type HeadstoreDocKey struct { DocID string FieldID string //can be 'C' Cid cid.Cid } -var _ Key = (*HeadStoreKey)(nil) +var _ Key = (*HeadstoreDocKey)(nil) -// Creates a new HeadStoreKey from a string as best as it can, +// Creates a new HeadstoreDocKey from a string as best as it can, // splitting the input using '/' as a field deliminator. It assumes // that the input string is in the following format: // // /[DocID]/[FieldId]/[Cid] // // Any properties before the above are ignored -func NewHeadStoreKey(key string) (HeadStoreKey, error) { +func NewHeadstoreDocKey(key string) (HeadstoreDocKey, error) { elements := strings.Split(key, "/") if len(elements) != 5 { - return HeadStoreKey{}, ErrInvalidKey + return HeadstoreDocKey{}, ErrInvalidKey } cid, err := cid.Decode(elements[4]) if err != nil { - return HeadStoreKey{}, err + return HeadstoreDocKey{}, err } - return HeadStoreKey{ + return HeadstoreDocKey{ // elements[0] is empty (key has leading '/') DocID: elements[2], FieldID: elements[3], @@ -51,25 +51,25 @@ func NewHeadStoreKey(key string) (HeadStoreKey, error) { }, nil } -func (k HeadStoreKey) WithDocID(docID string) HeadStoreKey { +func (k HeadstoreDocKey) WithDocID(docID string) HeadstoreDocKey { newKey := k newKey.DocID = docID return newKey } -func (k HeadStoreKey) WithCid(c cid.Cid) HeadStoreKey { +func (k HeadstoreDocKey) WithCid(c cid.Cid) HeadstoreDocKey { newKey := k newKey.Cid = c return newKey } -func (k HeadStoreKey) WithFieldID(fieldID string) HeadStoreKey { +func (k HeadstoreDocKey) WithFieldID(fieldID string) HeadstoreDocKey { newKey := k newKey.FieldID = fieldID return newKey } -func (k HeadStoreKey) ToString() string { +func (k HeadstoreDocKey) ToString() string { result := HEADSTORE_DOC if k.DocID != "" { @@ -85,10 +85,10 @@ func (k HeadStoreKey) ToString() string { return result } -func (k HeadStoreKey) Bytes() []byte { +func (k HeadstoreDocKey) Bytes() []byte { return []byte(k.ToString()) } -func (k HeadStoreKey) ToDS() ds.Key { +func (k HeadstoreDocKey) ToDS() ds.Key { return ds.NewKey(k.ToString()) } diff --git a/internal/merkle/clock/clock.go b/internal/merkle/clock/clock.go index 94180f2144..e7682f1912 100644 --- a/internal/merkle/clock/clock.go +++ b/internal/merkle/clock/clock.go @@ -48,7 +48,7 @@ func NewMerkleClock( headstore datastore.DSReaderWriter, blockstore datastore.Blockstore, encstore datastore.Blockstore, - namespace keys.HeadStoreKey, + namespace keys.HeadstoreDocKey, crdt core.ReplicatedData, ) *MerkleClock { return &MerkleClock{ diff --git a/internal/merkle/clock/clock_test.go b/internal/merkle/clock/clock_test.go index c0f169c0a5..0a5aa34454 100644 --- a/internal/merkle/clock/clock_test.go +++ b/internal/merkle/clock/clock_test.go @@ -38,7 +38,7 @@ func newTestMerkleClock() *MerkleClock { multistore.Headstore(), multistore.Blockstore(), multistore.Encstore(), - keys.HeadStoreKey{DocID: request.DocIDArgName, FieldID: "1"}, + keys.HeadstoreDocKey{DocID: request.DocIDArgName, FieldID: "1"}, reg, ) } @@ -47,7 +47,7 @@ func TestNewMerkleClock(t *testing.T) { s := newDS() multistore := datastore.MultiStoreFrom(s) reg := crdt.NewLWWRegister(multistore.Rootstore(), keys.CollectionSchemaVersionKey{}, keys.DataStoreKey{}, "") - clk := NewMerkleClock(multistore.Headstore(), multistore.Blockstore(), multistore.Encstore(), keys.HeadStoreKey{}, reg) + clk := NewMerkleClock(multistore.Headstore(), multistore.Blockstore(), multistore.Encstore(), keys.HeadstoreDocKey{}, reg) if clk.headstore != multistore.Headstore() { t.Error("MerkleClock store not correctly set") diff --git a/internal/merkle/clock/heads.go b/internal/merkle/clock/heads.go index 0dcf2a8f99..c0afa21636 100644 --- a/internal/merkle/clock/heads.go +++ b/internal/merkle/clock/heads.go @@ -27,17 +27,17 @@ import ( // heads manages the current Merkle-CRDT heads. type heads struct { store datastore.DSReaderWriter - namespace keys.HeadStoreKey + namespace keys.HeadstoreDocKey } -func NewHeadSet(store datastore.DSReaderWriter, namespace keys.HeadStoreKey) *heads { +func NewHeadSet(store datastore.DSReaderWriter, namespace keys.HeadstoreDocKey) *heads { return &heads{ store: store, namespace: namespace, } } -func (hh *heads) key(c cid.Cid) keys.HeadStoreKey { +func (hh *heads) key(c cid.Cid) keys.HeadstoreDocKey { return hh.namespace.WithCid(c) } @@ -102,7 +102,7 @@ func (hh *heads) List(ctx context.Context) ([]cid.Cid, uint64, error) { return nil, 0, NewErrFailedToGetNextQResult(r.Error) } - headKey, err := keys.NewHeadStoreKey(r.Key) + headKey, err := keys.NewHeadstoreDocKey(r.Key) if err != nil { return nil, 0, err } diff --git a/internal/merkle/clock/heads_test.go b/internal/merkle/clock/heads_test.go index cb8e1d1014..cbf153874c 100644 --- a/internal/merkle/clock/heads_test.go +++ b/internal/merkle/clock/heads_test.go @@ -45,7 +45,7 @@ func newHeadSet() *heads { return NewHeadSet( datastore.AsDSReaderWriter(s), - keys.HeadStoreKey{}.WithDocID("myDocID").WithFieldID("1"), + keys.HeadstoreDocKey{}.WithDocID("myDocID").WithFieldID("1"), ) } diff --git a/net/server_test.go b/net/server_test.go index a2cda4c76b..a29952d2b8 100644 --- a/net/server_test.go +++ b/net/server_test.go @@ -86,7 +86,7 @@ func getHead(ctx context.Context, db client.DB, docID client.DocID) (cid.Cid, er } if len(entries) > 0 { - hsKey, err := keys.NewHeadStoreKey(entries[0].Key) + hsKey, err := keys.NewHeadstoreDocKey(entries[0].Key) if err != nil { return cid.Undef, err }