From 750f782d5d4aeaf6ff2671487e270bd6c62a2c9f Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Mon, 28 Oct 2024 13:42:42 -0400 Subject: [PATCH] WIP - Remove unused Value function It only ever references itself --- internal/core/crdt/composite.go | 5 --- internal/core/crdt/counter.go | 10 ----- internal/core/crdt/lwwreg.go | 11 ----- internal/core/crdt/lwwreg_test.go | 70 ------------------------------ internal/core/replicated.go | 1 - internal/merkle/crdt/merklecrdt.go | 4 -- 6 files changed, 101 deletions(-) diff --git a/internal/core/crdt/composite.go b/internal/core/crdt/composite.go index d1be34d64a..1cdaa6b76a 100644 --- a/internal/core/crdt/composite.go +++ b/internal/core/crdt/composite.go @@ -89,11 +89,6 @@ func NewCompositeDAG( return CompositeDAG{newBaseCRDT(store, key, schemaVersionKey, "")} } -// Value is a no-op for a CompositeDAG. -func (c CompositeDAG) Value(ctx context.Context) ([]byte, error) { - return nil, nil -} - // Set returns a new composite DAG delta CRDT with the given status. func (c CompositeDAG) Set(status client.DocumentStatus) *CompositeDAGDelta { return &CompositeDAGDelta{ diff --git a/internal/core/crdt/counter.go b/internal/core/crdt/counter.go index 4aa9a40793..64e6a19e16 100644 --- a/internal/core/crdt/counter.go +++ b/internal/core/crdt/counter.go @@ -96,16 +96,6 @@ func NewCounter( return Counter{newBaseCRDT(store, key, schemaVersionKey, fieldName), allowDecrement, kind} } -// Value gets the current counter value -func (c Counter) Value(ctx context.Context) ([]byte, error) { - valueK := c.key.WithValueFlag() - buf, err := c.store.Get(ctx, valueK.ToDS()) - if err != nil { - return nil, err - } - return buf, nil -} - // Set generates a new delta with the supplied value. // // WARNING: Incrementing an integer and causing it to overflow the int64 max value diff --git a/internal/core/crdt/lwwreg.go b/internal/core/crdt/lwwreg.go index e27a4c5ace..0c5aef4361 100644 --- a/internal/core/crdt/lwwreg.go +++ b/internal/core/crdt/lwwreg.go @@ -80,17 +80,6 @@ func NewLWWRegister( return LWWRegister{newBaseCRDT(store, key, schemaVersionKey, fieldName)} } -// Value gets the current register value -// RETURN STATE -func (reg LWWRegister) Value(ctx context.Context) ([]byte, error) { - valueK := reg.key.WithValueFlag() - buf, err := reg.store.Get(ctx, valueK.ToDS()) - if err != nil { - return nil, err - } - return buf, nil -} - // Set generates a new delta with the supplied value // RETURN DELTA func (reg LWWRegister) Set(value []byte) *LWWRegDelta { diff --git a/internal/core/crdt/lwwreg_test.go b/internal/core/crdt/lwwreg_test.go index 5b56df7636..087adecb70 100644 --- a/internal/core/crdt/lwwreg_test.go +++ b/internal/core/crdt/lwwreg_test.go @@ -11,12 +11,10 @@ package crdt import ( - "context" "reflect" "testing" ds "github.com/ipfs/go-datastore" - "github.com/stretchr/testify/require" "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/internal/core" @@ -32,15 +30,6 @@ func setupLWWRegister() LWWRegister { return NewLWWRegister(store, core.CollectionSchemaVersionKey{}, key, "") } -func setupLoadedLWWRegister(t *testing.T, ctx context.Context) LWWRegister { - lww := setupLWWRegister() - addDelta := lww.Set([]byte("test")) - addDelta.SetPriority(1) - err := lww.Merge(ctx, addDelta) - require.NoError(t, err) - return lww -} - func TestLWWRegisterAddDelta(t *testing.T) { lww := setupLWWRegister() addDelta := lww.Set([]byte("test")) @@ -50,65 +39,6 @@ func TestLWWRegisterAddDelta(t *testing.T) { } } -func TestLWWRegisterInitialMerge(t *testing.T) { - ctx := context.Background() - lww := setupLWWRegister() - addDelta := lww.Set([]byte("test")) - addDelta.SetPriority(1) - err := lww.Merge(ctx, addDelta) - if err != nil { - t.Errorf("Unexpected error: %s\n", err) - return - } - - val, err := lww.Value(ctx) - if err != nil { - t.Errorf("Unexpected error: %s", err) - return - } - - expectedVal := []byte("test") - if string(val) != string(expectedVal) { - t.Errorf("Mismatch value for LWWRegister, was %s want %s", val, expectedVal) - } -} - -func TestLWWRegisterFollowupMerge(t *testing.T) { - ctx := context.Background() - lww := setupLoadedLWWRegister(t, ctx) - addDelta := lww.Set([]byte("test2")) - addDelta.SetPriority(2) - err := lww.Merge(ctx, addDelta) - require.NoError(t, err) - - val, err := lww.Value(ctx) - if err != nil { - t.Error(err) - } - - if string(val) != string([]byte("test2")) { - t.Errorf("Incorrect merge state, want %s, have %s", []byte("test2"), val) - } -} - -func TestLWWRegisterOldMerge(t *testing.T) { - ctx := context.Background() - lww := setupLoadedLWWRegister(t, ctx) - addDelta := lww.Set([]byte("test-1")) - addDelta.SetPriority(0) - err := lww.Merge(ctx, addDelta) - require.NoError(t, err) - - val, err := lww.Value(ctx) - if err != nil { - t.Error(err) - } - - if string(val) != string([]byte("test")) { - t.Errorf("Incorrect merge state, want %s, have %s", []byte("test"), val) - } -} - func TestLWWRegisterDeltaInit(t *testing.T) { delta := &LWWRegDelta{} diff --git a/internal/core/replicated.go b/internal/core/replicated.go index d885b37fc8..d833244b78 100644 --- a/internal/core/replicated.go +++ b/internal/core/replicated.go @@ -18,5 +18,4 @@ import ( // replicated data so as to converge on the same state. type ReplicatedData interface { Merge(ctx context.Context, other Delta) error - Value(ctx context.Context) ([]byte, error) } diff --git a/internal/merkle/crdt/merklecrdt.go b/internal/merkle/crdt/merklecrdt.go index d6e73208d5..14b75cc7d7 100644 --- a/internal/merkle/crdt/merklecrdt.go +++ b/internal/merkle/crdt/merklecrdt.go @@ -69,10 +69,6 @@ func (base *baseMerkleCRDT) Merge(ctx context.Context, other core.Delta) error { return base.crdt.Merge(ctx, other) } -func (base *baseMerkleCRDT) Value(ctx context.Context) ([]byte, error) { - return base.crdt.Value(ctx) -} - func InstanceWithStore( store Stores, schemaVersionKey core.CollectionSchemaVersionKey,