Skip to content

Commit

Permalink
GetActiveLogs returns PREORDERED_LOG trees as well (#1038)
Browse files Browse the repository at this point in the history
* Both in MySQL and Cloud Spanner storage
* Test the new behavior
  • Loading branch information
pav-kv authored Mar 8, 2018
1 parent 2130693 commit 36c4f21
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions storage/cloudspanner/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ const (
numByteValues = 256

unsequencedCountSQL = "SELECT Unsequenced.TreeID, COUNT(1) FROM Unsequenced GROUP BY TreeID"
// t.TreeState 1 == Active, State 5 = Draining

// t.TreeType: 1 = Log, 3 = PreorderedLog.
// t.TreeState: 1 = Active, 5 = Draining.
getActiveLogIDsSQL = `SELECT t.TreeID FROM TreeRoots t
WHERE t.TreeType = 1
WHERE (t.TreeType = 1 OR t.TreeType = 3)
AND (t.TreeState = 1 OR t.TreeState = 5)
AND t.Deleted=false`
)
Expand Down
3 changes: 2 additions & 1 deletion storage/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ type CountByLogID map[int64]int64

// LogMetadata provides access to information about the logs in storage
type LogMetadata interface {
// GetActiveLogs returns a list of the IDs of all the logs that are configured in storage
// GetActiveLogIDs returns a list of the IDs of all the logs that are
// configured in storage and are eligible to have entries sequenced.
GetActiveLogIDs(ctx context.Context) ([]int64, error)

// GetUnsequencedCounts returns a map of the number of unsequenced entries
Expand Down
11 changes: 6 additions & 5 deletions storage/mysql/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
const (
selectNonDeletedTreeIDByTypeAndStateSQL = `
SELECT TreeId FROM Trees
WHERE TreeType = ?
WHERE TreeType IN(?,?)
AND TreeState IN(?,?)
AND (Deleted IS NULL OR Deleted = 'false')`

Expand Down Expand Up @@ -172,6 +172,7 @@ func (m *mySQLLogStorage) getLeavesByLeafIdentityHashStmt(ctx context.Context, n

// readOnlyLogTX implements storage.ReadOnlyLogTX
type readOnlyLogTX struct {
ls *mySQLLogStorage
tx *sql.Tx
}

Expand All @@ -181,7 +182,7 @@ func (m *mySQLLogStorage) Snapshot(ctx context.Context) (storage.ReadOnlyLogTX,
glog.Warningf("Could not start ReadOnlyLogTX: %s", err)
return nil, err
}
return &readOnlyLogTX{tx}, nil
return &readOnlyLogTX{m, tx}, nil
}

func (t *readOnlyLogTX) Commit() error {
Expand All @@ -204,9 +205,9 @@ func (t *readOnlyLogTX) GetActiveLogIDs(ctx context.Context) ([]int64, error) {
// Include logs that are DRAINING in the active list as we're still
// integrating leaves into them.
rows, err := t.tx.QueryContext(
ctx, selectNonDeletedTreeIDByTypeAndStateSQL, trillian.TreeType_LOG.String(),
trillian.TreeState_ACTIVE.String(),
trillian.TreeState_DRAINING.String())
ctx, selectNonDeletedTreeIDByTypeAndStateSQL,
trillian.TreeType_LOG.String(), trillian.TreeType_PREORDERED_LOG.String(),
trillian.TreeState_ACTIVE.String(), trillian.TreeState_DRAINING.String())
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions storage/mysql/log_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,13 +974,14 @@ func TestGetActiveLogIDs(t *testing.T) {
// Create a few test trees
log1 := proto.Clone(testonly.LogTree).(*trillian.Tree)
log2 := proto.Clone(testonly.LogTree).(*trillian.Tree)
log3 := proto.Clone(testonly.PreorderedLogTree).(*trillian.Tree)
drainingLog := proto.Clone(testonly.LogTree).(*trillian.Tree)
frozenLog := proto.Clone(testonly.LogTree).(*trillian.Tree)
deletedLog := proto.Clone(testonly.LogTree).(*trillian.Tree)
map1 := proto.Clone(testonly.MapTree).(*trillian.Tree)
map2 := proto.Clone(testonly.MapTree).(*trillian.Tree)
deletedMap := proto.Clone(testonly.MapTree).(*trillian.Tree)
for _, tree := range []*trillian.Tree{log1, log2, drainingLog, frozenLog, deletedLog, map1, map2, deletedMap} {
for _, tree := range []*trillian.Tree{log1, log2, log3, drainingLog, frozenLog, deletedLog, map1, map2, deletedMap} {
newTree, err := storage.CreateTree(ctx, admin, tree)
if err != nil {
t.Fatalf("CreateTree(%+v) returned err = %v", tree, err)
Expand Down Expand Up @@ -1027,7 +1028,7 @@ func TestGetActiveLogIDs(t *testing.T) {
t.Errorf("Commit() returned err = %v", err)
}

want := []int64{log1.TreeId, log2.TreeId, drainingLog.TreeId}
want := []int64{log1.TreeId, log2.TreeId, log3.TreeId, drainingLog.TreeId}
sort.Slice(got, func(i, j int) bool { return got[i] < got[j] })
sort.Slice(want, func(i, j int) bool { return want[i] < want[j] })
if diff := pretty.Compare(got, want); diff != "" {
Expand Down

0 comments on commit 36c4f21

Please sign in to comment.