Skip to content

Commit

Permalink
Revert "storage: log SQL statement with V(4)"
Browse files Browse the repository at this point in the history
This reverts commit 161f7f4.
  • Loading branch information
daviddrysdale committed Feb 27, 2017
1 parent 2483f92 commit 10a43e9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
16 changes: 1 addition & 15 deletions storage/mysql/log_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func (m *mySQLLogStorage) getDeleteUnsequencedStmt(num int) (*sql.Stmt, error) {
}

func getActiveLogIDsInternal(tx *sql.Tx, sql string) ([]int64, error) {
glog.V(4).Infof("Query: %v", flatten(sql))
rows, err := tx.Query(sql)
if err != nil {
return nil, err
Expand Down Expand Up @@ -183,7 +182,6 @@ func (m *mySQLLogStorage) hasher(treeID int64) (merkle.TreeHasher, error) {
func (m *mySQLLogStorage) beginInternal(ctx context.Context, treeID int64) (storage.LogTreeTX, error) {
// TODO(codingllama): Validate treeType
var duplicatePolicy string
glog.V(4).Infof("QueryRow: %v with %v", flatten(getTreePropertiesSQL), treeID)
if err := m.db.QueryRow(getTreePropertiesSQL, treeID).Scan(&duplicatePolicy); err != nil {
return nil, fmt.Errorf("failed to get tree row for treeID %v: %s", treeID, err)
}
Expand Down Expand Up @@ -254,7 +252,6 @@ func (t *logTreeTX) DequeueLeaves(limit int, cutoffTime time.Time) ([]*trillian.
}

leaves := make([]*trillian.LogLeaf, 0, limit)
glog.V(4).Infof("Query: %v with %v, %v, %v", flatten(selectQueuedLeavesSQL), t.treeID, cutoffTime.UnixNano(), limit)
rows, err := stx.Query(t.treeID, cutoffTime.UnixNano(), limit)

if err != nil {
Expand Down Expand Up @@ -335,7 +332,6 @@ func (t *logTreeTX) QueueLeaves(leaves []*trillian.LogLeaf, queueTimestamp time.
// can suppress errors unrelated to key collisions. We don't use REPLACE because
// if there's ever a hash collision it will do the wrong thing and it also
// causes a DELETE / INSERT, which is undesirable.
glog.V(4).Infof("Exec: %s with %v, %v, %v, %v", flatten(insertSQL), t.treeID, leaf.LeafIdentityHash, leaf.LeafValue, leaf.ExtraData)
_, err := t.tx.Exec(insertSQL, t.treeID, leaf.LeafIdentityHash, leaf.LeafValue, leaf.ExtraData)
if err != nil {
if strings.Contains(err.Error(), "Duplicate entry") {
Expand Down Expand Up @@ -374,8 +370,6 @@ func (t *logTreeTX) QueueLeaves(leaves []*trillian.LogLeaf, queueTimestamp time.
hasher.Write(leaf.LeafIdentityHash)
messageID := hasher.Sum(nil)

glog.V(4).Infof("Exec: %s with %v, %v, %v, %v, %v", flatten(insertUnsequencedEntrySQL),
t.treeID, leaf.LeafIdentityHash, leaf.MerkleLeafHash, messageID, queueTimestamp.UnixNano())
_, err = t.tx.Exec(insertUnsequencedEntrySQL,
t.treeID, leaf.LeafIdentityHash, leaf.MerkleLeafHash, messageID, queueTimestamp.UnixNano())

Expand All @@ -391,8 +385,8 @@ func (t *logTreeTX) QueueLeaves(leaves []*trillian.LogLeaf, queueTimestamp time.
func (t *logTreeTX) GetSequencedLeafCount() (int64, error) {
var sequencedLeafCount int64

glog.V(4).Infof("QueryRow: %v with %v", flatten(selectSequencedLeafCountSQL), t.treeID)
err := t.tx.QueryRow(selectSequencedLeafCountSQL, t.treeID).Scan(&sequencedLeafCount)

if err != nil {
glog.Warningf("Error getting sequenced leaf count: %s", err)
}
Expand All @@ -411,7 +405,6 @@ func (t *logTreeTX) GetLeavesByIndex(leaves []int64) ([]*trillian.LogLeaf, error
args = append(args, interface{}(int64(nodeID)))
}
args = append(args, interface{}(t.treeID))
glog.V(4).Infof("Query: %v with %v", flatStmt(tmpl), args)
rows, err := stx.Query(args...)
if err != nil {
glog.Warningf("Failed to get leaves by idx: %s", err)
Expand Down Expand Up @@ -459,7 +452,6 @@ func (t *logTreeTX) fetchLatestRoot() (trillian.SignedLogRoot, error) {
var rootHash, rootSignatureBytes []byte
var rootSignature spb.DigitallySigned

glog.V(4).Infof("QueryRow: %v with %v", flatten(selectLatestSignedLogRootSQL), t.treeID)
err := t.tx.QueryRow(
selectLatestSignedLogRootSQL, t.treeID).Scan(
&timestamp, &treeSize, &rootHash, &treeRevision, &rootSignatureBytes)
Expand Down Expand Up @@ -494,8 +486,6 @@ func (t *logTreeTX) StoreSignedLogRoot(root trillian.SignedLogRoot) error {
return err
}

glog.V(4).Infof("Exec: %s with %v, %v, %v, %v, %v, %v", flatten(insertTreeHeadSQL), t.treeID, root.TimestampNanos, root.TreeSize,
root.RootHash, root.TreeRevision, signatureBytes)
res, err := t.tx.Exec(insertTreeHeadSQL, t.treeID, root.TimestampNanos, root.TreeSize,
root.RootHash, root.TreeRevision, signatureBytes)

Expand All @@ -515,7 +505,6 @@ func (t *logTreeTX) UpdateSequencedLeaves(leaves []*trillian.LogLeaf) error {
return errors.New("Sequenced leaf has incorrect hash size")
}

glog.V(4).Infof("Exec: %s with %v, %v, %v, %v", flatten(insertSequencedLeafSQL), t.treeID, leaf.LeafIdentityHash, leaf.MerkleLeafHash, leaf.LeafIndex)
_, err := t.tx.Exec(insertSequencedLeafSQL, t.treeID, leaf.LeafIdentityHash, leaf.MerkleLeafHash,
leaf.LeafIndex)

Expand Down Expand Up @@ -545,8 +534,6 @@ func (t *logTreeTX) removeSequencedLeaves(leaves []*trillian.LogLeaf) error {
args = append(args, interface{}(leaf.LeafIdentityHash))
}
args = append(args, interface{}(t.treeID))

glog.V(4).Infof("Exec: %s with %v", flatStmt(tmpl), args)
result, err := stx.Exec(args...)

if err != nil {
Expand All @@ -570,7 +557,6 @@ func (t *logTreeTX) getLeavesByHashInternal(leafHashes [][]byte, tmpl *sql.Stmt,
args = append(args, interface{}([]byte(hash)))
}
args = append(args, interface{}(t.treeID))
glog.V(4).Infof("Query: %v with %v", flatStmt(tmpl), args)
rows, err := stx.Query(args...)
if err != nil {
glog.Warningf("Query() %s hash = %v", desc, err)
Expand Down
4 changes: 0 additions & 4 deletions storage/mysql/map_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func (m *mapTreeTX) Set(keyHash []byte, value trillian.MapLeaf) error {
}
defer stmt.Close()

glog.V(4).Infof("Exec: %s with %v, %v, %v, %v", flatten(insertMapLeafSQL), m.treeID, keyHash, m.writeRevision, flatValue)
_, err = stmt.Exec(m.treeID, keyHash, m.writeRevision, flatValue)
return err
}
Expand All @@ -188,7 +187,6 @@ func (m *mapTreeTX) Get(revision int64, indexes [][]byte) ([]trillian.MapLeaf, e

glog.Infof("args size %d", len(args))

glog.V(4).Infof("Query: %v with %v", flatStmt(stmt), args)
rows, err := stx.Query(args...)
// It's possible there are no values for any of these keys yet
if err == sql.ErrNoRows {
Expand Down Expand Up @@ -238,7 +236,6 @@ func (m *mapTreeTX) LatestSignedMapRoot() (trillian.SignedMapRoot, error) {
}
defer stmt.Close()

glog.V(4).Infof("QueryRow: %v with %v", flatStmt(stmt), m.treeID)
err = stmt.QueryRow(m.treeID).Scan(
&timestamp, &rootHash, &mapRevision, &rootSignatureBytes, &mapperMetaBytes)

Expand Down Expand Up @@ -297,7 +294,6 @@ func (m *mapTreeTX) StoreSignedMapRoot(root trillian.SignedMapRoot) error {
defer stmt.Close()

// TODO(al): store transactionLogHead too
glog.V(4).Infof("Exec: %s with %v, %v, %v, %v, %v, %v", flatten(insertMapHeadSQL), m.treeID, root.TimestampNanos, root.RootHash, root.MapRevision, signatureBytes, mapperMetaBytes)
res, err := stmt.Exec(m.treeID, root.TimestampNanos, root.RootHash, root.MapRevision, signatureBytes, mapperMetaBytes)

if err != nil {
Expand Down
19 changes: 3 additions & 16 deletions storage/mysql/tree_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,13 @@ const (
n.TreeId = ? AND n.SubtreeRevision <= ?
GROUP BY n.SubtreeId
) AS x
INNER JOIN Subtree
ON Subtree.SubtreeId = x.SubtreeId
AND Subtree.SubtreeRevision = x.MaxRevision
INNER JOIN Subtree
ON Subtree.SubtreeId = x.SubtreeId
AND Subtree.SubtreeRevision = x.MaxRevision
AND Subtree.TreeId = ?`
placeholderSQL = "<placeholder>"
)

func flatten(s string) string {
return strings.Join(strings.Fields(s), " ")
}

func flatStmt(s *sql.Stmt) string {
return flatten(fmt.Sprintf("%v", s))
}

// mySQLTreeStorage is shared between the mySQLLog- and (forthcoming) mySQLMap-
// Storage implementations, and contains functionality which is common to both,
type mySQLTreeStorage struct {
Expand All @@ -83,7 +75,6 @@ func OpenDB(dbURL string) (*sql.DB, error) {
return nil, err
}

glog.V(4).Info("Exec: SET sql_mode = 'STRICT_ALL_TABLES'")
if _, err := db.Exec("SET sql_mode = 'STRICT_ALL_TABLES'"); err != nil {
glog.Warningf("Failed to set strict mode on mysql db: %s", err)
return nil, err
Expand Down Expand Up @@ -244,7 +235,6 @@ func (t *treeTX) getSubtrees(treeRevision int64, nodeIDs []storage.NodeID) ([]*s
args = append(args, interface{}(treeRevision))
args = append(args, interface{}(t.treeID))

glog.V(4).Infof("Query: %v with %v", flatStmt(tmpl), args)
rows, err := stx.Query(args...)
if err != nil {
glog.Warningf("Failed to get merkle subtrees: %s", err)
Expand Down Expand Up @@ -317,7 +307,6 @@ func (t *treeTX) storeSubtrees(subtrees []*storagepb.SubtreeProto) error {
stx := t.tx.Stmt(tmpl)
defer stx.Close()

glog.V(4).Infof("Exec: %v with %v", flatStmt(tmpl), args)
r, err := stx.Exec(args...)
if err != nil {
glog.Warningf("Failed to set merkle subtrees: %s", err)
Expand Down Expand Up @@ -359,7 +348,6 @@ func (t *treeTX) GetTreeRevisionIncludingSize(treeSize int64) (int64, int64, err
}

var treeRevision, actualTreeSize int64
glog.V(4).Infof("QueryRow: %v with %v, %v", flatten(selectTreeRevisionAtSizeOrLargerSQL), t.treeID, treeSize)
err := t.tx.QueryRow(selectTreeRevisionAtSizeOrLargerSQL, t.treeID, treeSize).Scan(&treeRevision, &actualTreeSize)

return treeRevision, actualTreeSize, err
Expand Down Expand Up @@ -440,7 +428,6 @@ func checkDatabaseAccessible(ctx context.Context, db *sql.DB) error {
}
defer stmt.Close()

glog.V(4).Info("Exec: SELECT TreeId FROM Trees LIMIT 1")
_, err = stmt.Exec()
return err
}

0 comments on commit 10a43e9

Please sign in to comment.