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

Support WithBatching in GCP #91

Merged
merged 3 commits into from
Jul 26, 2024
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
6 changes: 5 additions & 1 deletion cmd/example-gcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/http"
"os"
"strings"
"time"

tessera "github.com/transparency-dev/trillian-tessera"
"github.com/transparency-dev/trillian-tessera/storage/gcp"
Expand All @@ -50,7 +51,10 @@ func main() {
Bucket: *bucket,
Spanner: *spanner,
}
storage, err := gcp.New(ctx, gcpCfg, tessera.WithCheckpointSignerVerifier(signerFromFlags(), nil))
storage, err := gcp.New(ctx, gcpCfg,
tessera.WithCheckpointSignerVerifier(signerFromFlags(), nil),
tessera.WithBatching(1024, time.Second),
AlCutter marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
klog.Exitf("Failed to create new GCP storage: %v", err)
}
Expand Down
6 changes: 5 additions & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"golang.org/x/mod/sumdb/note"
)

const DefaultBatchMaxSize = 1

// NewCPFunc is the signature of a function which knows how to format and sign checkpoints.
type NewCPFunc func(size uint64, hash []byte) ([]byte, error)

Expand All @@ -40,7 +42,9 @@ 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{}
defaults = &StorageOptions{
BatchMaxSize: DefaultBatchMaxSize,
}
}
for _, opt := range opts {
opt(defaults)
Expand Down
3 changes: 1 addition & 2 deletions storage/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ func New(ctx context.Context, cfg Config, opts ...func(*tessera.StorageOptions))
sequencer: seq,
newCP: opt.NewCP,
}
// TODO(al): make queue options configurable:
r.queue = storage.NewQueue(ctx, time.Second, 256, r.sequencer.assignEntries)
r.queue = storage.NewQueue(ctx, opt.BatchMaxAge, opt.BatchMaxSize, r.sequencer.assignEntries)

go func() {
t := time.NewTicker(1 * time.Second)
Expand Down
Loading