Skip to content

Commit

Permalink
Remove default options from ResolveStorageOptions (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter authored Aug 28, 2024
1 parent 6b00d15 commit ae47df5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
14 changes: 8 additions & 6 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import (
"golang.org/x/mod/sumdb/note"
)

const DefaultBatchMaxSize = 1
const (
DefaultBatchMaxSize = 256
DefaultBatchMaxAge = 250 * time.Millisecond
)

// ErrPushback is returned by underlying storage implementations when there are too many
// entries with indices assigned but which have not yet been integrated into the tree.
Expand All @@ -50,11 +53,10 @@ type StorageOptions struct {
}

// ResolveStorageOptions turns a variadic array of storage options into a StorageOptions instance.
func ResolveStorageOptions(defaults *StorageOptions, opts ...func(*StorageOptions)) *StorageOptions {
if defaults == nil {
defaults = &StorageOptions{
BatchMaxSize: DefaultBatchMaxSize,
}
func ResolveStorageOptions(opts ...func(*StorageOptions)) *StorageOptions {
defaults := &StorageOptions{
BatchMaxSize: DefaultBatchMaxSize,
BatchMaxAge: DefaultBatchMaxAge,
}
for _, opt := range opts {
opt(defaults)
Expand Down
2 changes: 1 addition & 1 deletion storage/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type Config struct {

// New creates a new instance of the GCP based Storage.
func New(ctx context.Context, cfg Config, opts ...func(*tessera.StorageOptions)) (*Storage, error) {
opt := tessera.ResolveStorageOptions(nil, opts...)
opt := tessera.ResolveStorageOptions(opts...)
if opt.PushbackMaxOutstanding == 0 {
opt.PushbackMaxOutstanding = DefaultPushbackMaxOutstanding
}
Expand Down
12 changes: 3 additions & 9 deletions storage/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"strings"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/transparency-dev/merkle/rfc6962"
Expand All @@ -41,10 +40,8 @@ const (
selectTiledLeavesSQL = "SELECT `data` FROM `TiledLeaves` WHERE `tile_index` = ?"
replaceTiledLeavesSQL = "REPLACE INTO `TiledLeaves` (`tile_index`, `data`) VALUES (?, ?)"

checkpointID = 0
entryBundleSize = 256
defaultBatchMaxSize = entryBundleSize
defaultQueueMaxAge = time.Second
checkpointID = 0
entryBundleSize = 256
)

// Storage is a MySQL-based storage implementation for Tessera.
Expand All @@ -59,10 +56,7 @@ type Storage struct {
// New creates a new instance of the MySQL-based Storage.
// Note that `tessera.WithCheckpointSignerVerifier()` is mandatory in the `opts` argument.
func New(ctx context.Context, db *sql.DB, opts ...func(*tessera.StorageOptions)) (*Storage, error) {
opt := tessera.ResolveStorageOptions(&tessera.StorageOptions{
BatchMaxAge: defaultQueueMaxAge,
BatchMaxSize: defaultBatchMaxSize,
}, opts...)
opt := tessera.ResolveStorageOptions(opts...)
s := &Storage{
db: db,
newCheckpoint: opt.NewCP,
Expand Down
2 changes: 1 addition & 1 deletion storage/posix/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func New(ctx context.Context, path string, curTree func() (uint64, []byte, error
if err != nil {
panic(err)
}
opt := tessera.ResolveStorageOptions(nil, opts...)
opt := tessera.ResolveStorageOptions(opts...)

r := &Storage{
path: path,
Expand Down

0 comments on commit ae47df5

Please sign in to comment.