diff --git a/internal/db/p2p_replicator.go b/internal/db/p2p_replicator.go index 61c082d210..7a4aa96bfc 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 1665fb7ea3..73a62ab84a 100644 --- a/internal/keys/datastore_doc.go +++ b/internal/keys/datastore_doc.go @@ -106,8 +106,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..66b1f56003 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 NewHeadStoreKey(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..cc2f7f58ec 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..a7c13da858 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..7b1d4e45e2 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) } diff --git a/internal/merkle/clock/heads_test.go b/internal/merkle/clock/heads_test.go index cb8e1d1014..62a163d3e9 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"), ) }