Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove GetSequencedLeafCount from the storage interface. #2439

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions storage/cloudspanner/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,6 @@ func (tx *logTX) UpdateSequencedLeaves(ctx context.Context, leaves []*trillian.L
return nil
}

// GetSequencedLeafCount returns the number of leaves integrated into the tree
// at the time the transaction was started.
func (tx *logTX) GetSequencedLeafCount(ctx context.Context) (int64, error) {
currentSTH, err := tx.currentSTH(ctx)
if err != nil {
return -1, err
}

return currentSTH.TreeSize, nil
}

// leafmap is a map of LogLeaf by sequence number which knows how to populate
// itself directly from Spanner Rows.
type leafmap map[int64]*trillian.LogLeaf
Expand Down
3 changes: 0 additions & 3 deletions storage/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ type ReadOnlyLogTX interface {
type ReadOnlyLogTreeTX interface {
ReadOnlyTreeTX

// GetSequencedLeafCount returns the total number of leaves that have been integrated into the
// tree via sequencing.
GetSequencedLeafCount(ctx context.Context) (int64, error)
// GetLeavesByRange returns leaf data for a range of indexes. The returned
// slice is a contiguous prefix of leaves in [start, start+count) ordered by
// LeafIndex. It will be shorter than `count` if the requested range has
Expand Down
11 changes: 0 additions & 11 deletions storage/memory/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"errors"
"fmt"
"math"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -304,16 +303,6 @@ func (t *logTreeTX) AddSequencedLeaves(ctx context.Context, leaves []*trillian.L
return nil, status.Errorf(codes.Unimplemented, "AddSequencedLeaves is not implemented")
}

func (t *logTreeTX) GetSequencedLeafCount(ctx context.Context) (int64, error) {
var sequencedLeafCount int64

t.tx.DescendRange(seqLeafKey(t.treeID, math.MaxInt64), seqLeafKey(t.treeID, 0), func(i btree.Item) bool {
sequencedLeafCount = i.(*kv).v.(*trillian.LogLeaf).LeafIndex + 1
return false
})
return sequencedLeafCount, nil
}

func (t *logTreeTX) GetLeavesByRange(ctx context.Context, start, count int64) ([]*trillian.LogLeaf, error) {
ret := make([]*trillian.LogLeaf, 0, count)
for i := int64(0); i < count; i++ {
Expand Down
30 changes: 0 additions & 30 deletions storage/mock_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions storage/mysql/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const (
AND TreeState IN(?,?)
AND (Deleted IS NULL OR Deleted = 'false')`

selectSequencedLeafCountSQL = "SELECT COUNT(*) FROM SequencedLeafData WHERE TreeId=?"
selectLatestSignedLogRootSQL = `SELECT TreeHeadTimestamp,TreeSize,RootHash,TreeRevision,RootSignature
FROM TreeHead WHERE TreeId=?
ORDER BY TreeHeadTimestamp DESC LIMIT 1`
Expand Down Expand Up @@ -638,20 +637,6 @@ func (t *logTreeTX) AddSequencedLeaves(ctx context.Context, leaves []*trillian.L
return res, nil
}

func (t *logTreeTX) GetSequencedLeafCount(ctx context.Context) (int64, error) {
t.treeTX.mu.Lock()
defer t.treeTX.mu.Unlock()

var sequencedLeafCount int64

err := t.tx.QueryRowContext(ctx, selectSequencedLeafCountSQL, t.treeID).Scan(&sequencedLeafCount)
if err != nil {
glog.Warningf("Error getting sequenced leaf count: %s", err)
}

return sequencedLeafCount, err
}

func (t *logTreeTX) GetLeavesByRange(ctx context.Context, start, count int64) ([]*trillian.LogLeaf, error) {
t.treeTX.mu.Lock()
defer t.treeTX.mu.Unlock()
Expand Down
47 changes: 0 additions & 47 deletions storage/mysql/log_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ var (
dummyHash = []byte("hashxxxxhashxxxxhashxxxxhashxxxx")
dummyRawHash = []byte("xxxxhashxxxxhashxxxxhashxxxxhash")
dummyHash2 = []byte("HASHxxxxhashxxxxhashxxxxhashxxxx")
dummyHash3 = []byte("hashxxxxhashxxxxhashxxxxHASHxxxx")
)

// Time we will queue all leaves at
Expand Down Expand Up @@ -805,52 +804,6 @@ func TestReadOnlyLogTX_Rollback(t *testing.T) {
}
}

func TestGetSequencedLeafCount(t *testing.T) {
ctx := context.Background()

// We'll create leaves for two different trees
cleanTestDB(DB)
as := NewAdminStorage(DB)
log1 := mustCreateTree(ctx, t, as, testonly.LogTree)
log2 := mustCreateTree(ctx, t, as, testonly.LogTree)
s := NewLogStorage(DB, nil)

{
// Create fake leaf as if it had been sequenced
data := []byte("some data")
createFakeLeaf(ctx, DB, log1.TreeId, dummyHash, dummyRawHash, data, someExtraData, sequenceNumber, t)

// Create fake leaves for second tree as if they had been sequenced
data2 := []byte("some data 2")
data3 := []byte("some data 3")
createFakeLeaf(ctx, DB, log2.TreeId, dummyHash2, dummyRawHash, data2, someExtraData, sequenceNumber, t)
createFakeLeaf(ctx, DB, log2.TreeId, dummyHash3, dummyRawHash, data3, someExtraData, sequenceNumber+1, t)
}

// Read back the leaf counts from both trees
runLogTX(s, log1, t, func(ctx context.Context, tx storage.LogTreeTX) error {
count1, err := tx.GetSequencedLeafCount(ctx)
if err != nil {
t.Fatalf("unexpected error getting leaf count: %v", err)
}
if want, got := int64(1), count1; want != got {
t.Fatalf("expected %d sequenced for logId but got %d", want, got)
}
return nil
})

runLogTX(s, log2, t, func(ctx context.Context, tx storage.LogTreeTX) error {
count2, err := tx.GetSequencedLeafCount(ctx)
if err != nil {
t.Fatalf("unexpected error getting leaf count2: %v", err)
}
if want, got := int64(2), count2; want != got {
t.Fatalf("expected %d sequenced for logId2 but got %d", want, got)
}
return nil
})
}

func ensureAllLeavesDistinct(leaves []*trillian.LogLeaf, t *testing.T) {
t.Helper()
// All the leaf value hashes should be distinct because the leaves were created with distinct
Expand Down