Skip to content

Commit

Permalink
Fix sequence and integrate in MySQL storage implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
roger2hk committed Jul 31, 2024
1 parent 38251d6 commit aa8ab34
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions storage/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,14 @@ func (s *Storage) sequenceBatch(ctx context.Context, entries []*tessera.Entry) e
// integrate incorporates the provided entries into the log starting at fromSeq.
func (s *Storage) integrate(ctx context.Context, tx *sql.Tx, fromSeq uint64, entries []*tessera.Entry) error {
tb := storage.NewTreeBuilder(func(ctx context.Context, tileIDs []storage.TileID, treeSize uint64) ([]*api.HashTile, error) {
hashTiles := make([]*api.HashTile, len(tileIDs))
hashTiles := make([]*api.HashTile, 0, len(tileIDs))
if len(tileIDs) == 0 {
return hashTiles, nil
}

// Build the SQL and args to fetch the hash tiles.
var sql strings.Builder
args := make([]uint64, 0, len(tileIDs)*2)
args := make([]any, 0, len(tileIDs)*2)
for i, id := range tileIDs {
if i != 0 {
sql.WriteString(" UNION ALL ")
Expand All @@ -275,7 +278,7 @@ func (s *Storage) integrate(ctx context.Context, tx *sql.Tx, fromSeq uint64, ent
args = append(args, id.Level, id.Index)
}

rows, err := tx.QueryContext(ctx, sql.String(), args)
rows, err := tx.QueryContext(ctx, sql.String(), args...)
if err != nil {
return nil, fmt.Errorf("failed to query the hash tiles with SQL (%s): %w", sql.String(), err)
}
Expand Down

0 comments on commit aa8ab34

Please sign in to comment.