diff --git a/db/collection.go b/db/collection.go index d394d91979..65b0fbaa22 100644 --- a/db/collection.go +++ b/db/collection.go @@ -1222,7 +1222,6 @@ func (c *collection) saveFieldToMerkleCRDT( return merkleCRDT.Set(ctx, bytes) default: - return nil, 0, client.ErrUnknownCRDT return nil, 0, client.NewErrUnknownCRDT(val.Type()) } } diff --git a/merkle/crdt/composite.go b/merkle/crdt/composite.go index ae7558a961..f837ac3ef7 100644 --- a/merkle/crdt/composite.go +++ b/merkle/crdt/composite.go @@ -18,7 +18,6 @@ import ( "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/core" corecrdt "github.com/sourcenetwork/defradb/core/crdt" - "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/merkle/clock" ) @@ -32,19 +31,19 @@ type MerkleCompositeDAG struct { // NewMerkleCompositeDAG creates a new instance (or loaded from DB) of a MerkleCRDT // backed by a CompositeDAG CRDT. func NewMerkleCompositeDAG( - txn datastore.Txn, + store Stores, schemaVersionKey core.CollectionSchemaVersionKey, key core.DataStoreKey, fieldName string, ) *MerkleCompositeDAG { compositeDag := corecrdt.NewCompositeDAG( - txn.Datastore(), + store.Datastore(), schemaVersionKey, key, fieldName, ) - clock := clock.NewMerkleClock(txn.Headstore(), txn.DAGstore(), key.ToHeadStoreKey(), compositeDag) + clock := clock.NewMerkleClock(store.Headstore(), store.DAGstore(), key.ToHeadStoreKey(), compositeDag) base := &baseMerkleCRDT{clock: clock, crdt: compositeDag} return &MerkleCompositeDAG{ diff --git a/merkle/crdt/lwwreg.go b/merkle/crdt/lwwreg.go index 0577ec76ff..8b47492b26 100644 --- a/merkle/crdt/lwwreg.go +++ b/merkle/crdt/lwwreg.go @@ -17,7 +17,6 @@ import ( "github.com/sourcenetwork/defradb/core" corecrdt "github.com/sourcenetwork/defradb/core/crdt" - "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/merkle/clock" ) @@ -31,13 +30,13 @@ type MerkleLWWRegister struct { // NewMerkleLWWRegister creates a new instance (or loaded from DB) of a MerkleCRDT // backed by a LWWRegister CRDT. func NewMerkleLWWRegister( - txn datastore.Txn, + store Stores, schemaVersionKey core.CollectionSchemaVersionKey, key core.DataStoreKey, fieldName string, ) *MerkleLWWRegister { - register := corecrdt.NewLWWRegister(txn.Datastore(), schemaVersionKey, key, fieldName) - clk := clock.NewMerkleClock(txn.Headstore(), txn.DAGstore(), key.ToHeadStoreKey(), register) + register := corecrdt.NewLWWRegister(store.Datastore(), schemaVersionKey, key, fieldName) + clk := clock.NewMerkleClock(store.Headstore(), store.DAGstore(), key.ToHeadStoreKey(), register) base := &baseMerkleCRDT{clock: clk, crdt: register} return &MerkleLWWRegister{ baseMerkleCRDT: base, diff --git a/merkle/crdt/merklecrdt.go b/merkle/crdt/merklecrdt.go index ce176b87b6..07fb83e436 100644 --- a/merkle/crdt/merklecrdt.go +++ b/merkle/crdt/merklecrdt.go @@ -28,6 +28,12 @@ var ( log = logging.MustNewLogger("merklecrdt") ) +type Stores interface { + Datastore() datastore.DSReaderWriter + DAGstore() datastore.DAGStore + Headstore() datastore.DSReaderWriter +} + // MerkleCRDT is the implementation of a Merkle Clock along with a // CRDT payload. It implements the ReplicatedData interface // so it can be merged with any given semantics. @@ -62,7 +68,7 @@ func (base *baseMerkleCRDT) Value(ctx context.Context) ([]byte, error) { } func InstanceWithStore( - txn datastore.Txn, + store Stores, schemaVersionKey core.CollectionSchemaVersionKey, ctype client.CType, key core.DataStoreKey, @@ -71,18 +77,18 @@ func InstanceWithStore( switch ctype { case client.LWW_REGISTER: return NewMerkleLWWRegister( - txn, + store, schemaVersionKey, key, fieldName, ), nil case client.COMPOSITE: return NewMerkleCompositeDAG( - txn, + store, schemaVersionKey, key, fieldName, ), nil } - return nil, client.ErrUnknownCRDT + return nil, client.NewErrUnknownCRDT(ctype) }