diff --git a/internal/db/fetcher/dag.go b/internal/db/fetcher/dag.go index 723b821a97..897a18c434 100644 --- a/internal/db/fetcher/dag.go +++ b/internal/db/fetcher/dag.go @@ -31,7 +31,7 @@ type HeadFetcher struct { func (hf *HeadFetcher) Start( ctx context.Context, txn datastore.Txn, - prefix keys.HeadStoreKey, + prefix keys.HeadstoreDocKey, fieldId immutable.Option[string], ) error { hf.fieldId = fieldId @@ -64,7 +64,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/fetcher/versioned.go b/internal/db/fetcher/versioned.go index baa3acfcfb..24f3ab8467 100644 --- a/internal/db/fetcher/versioned.go +++ b/internal/db/fetcher/versioned.go @@ -163,7 +163,7 @@ func (vf *VersionedFetcher) Start(ctx context.Context, spans ...core.Span) error // VersionedFetcher only ever recieves a headstore key //nolint:forcetypeassert - prefix := spans[0].Start.(keys.HeadStoreKey) + prefix := spans[0].Start.(keys.HeadstoreDocKey) dk := prefix.DocID cid := prefix.Cid if dk == "" { 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 cffa99f6fc..cf3cb3ea59 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 1046239c62..fc65e2f157 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 _ Walkable = (*HeadStoreKey)(nil) +var _ Walkable = (*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,15 +85,15 @@ 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()) } -func (k HeadStoreKey) PrefixEnd() Walkable { +func (k HeadstoreDocKey) PrefixEnd() Walkable { newKey := k if k.FieldID != "" { 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/internal/planner/commit.go b/internal/planner/commit.go index ceecfc46cd..d53ddbd581 100644 --- a/internal/planner/commit.go +++ b/internal/planner/commit.go @@ -36,7 +36,7 @@ type dagScanNode struct { queuedCids []*cid.Cid fetcher fetcher.HeadFetcher - prefix keys.HeadStoreKey + prefix keys.HeadstoreDocKey commitSelect *mapper.CommitSelect execInfo dagScanExecInfo @@ -67,10 +67,10 @@ func (n *dagScanNode) Kind() string { } func (n *dagScanNode) Init() error { - undefined := keys.HeadStoreKey{} + undefined := keys.HeadstoreDocKey{} if n.prefix == undefined { if n.commitSelect.DocID.HasValue() { - key := keys.HeadStoreKey{}.WithDocID(n.commitSelect.DocID.Value()) + key := keys.HeadstoreDocKey{}.WithDocID(n.commitSelect.DocID.Value()) if n.commitSelect.FieldID.HasValue() { field := n.commitSelect.FieldID.Value() @@ -106,11 +106,11 @@ func (n *dagScanNode) Spans(spans []core.Span) { } for _, span := range spans { - var start keys.HeadStoreKey + var start keys.HeadstoreDocKey switch s := span.Start.(type) { case keys.DataStoreKey: start = s.ToHeadStoreKey() - case keys.HeadStoreKey: + case keys.HeadstoreDocKey: start = s } @@ -144,7 +144,7 @@ func (n *dagScanNode) simpleExplain() (map[string]any, error) { // Build the explanation of the spans attribute. spansExplainer := []map[string]any{} - undefinedHsKey := keys.HeadStoreKey{} + undefinedHsKey := keys.HeadstoreDocKey{} // Note: n.headset is `nil` for single commit selection query, so must check for it. if n.prefix != undefinedHsKey { spansExplainer = append( diff --git a/internal/planner/select.go b/internal/planner/select.go index e5b53cd997..f1b3d05867 100644 --- a/internal/planner/select.go +++ b/internal/planner/select.go @@ -266,11 +266,11 @@ func (n *selectNode) initSource() ([]aggregateNode, error) { origScan.Spans( []core.Span{ core.NewSpan( - keys.HeadStoreKey{ + keys.HeadstoreDocKey{ DocID: n.selectReq.DocIDs.Value()[0], Cid: c, }, - keys.HeadStoreKey{}, + keys.HeadstoreDocKey{}, ), }, ) 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 }