Skip to content

Commit a8a841a

Browse files
committed
Use badger opts
1 parent dcee43d commit a8a841a

3 files changed

Lines changed: 50 additions & 11 deletions

File tree

cmd/experimental/migrate/posix/main.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"strings"
3030
"time"
3131

32+
"github.com/dgraph-io/badger/v4"
33+
"github.com/dustin/go-humanize"
3234
"github.com/transparency-dev/tessera"
3335
"github.com/transparency-dev/tessera/api/layout"
3436
"github.com/transparency-dev/tessera/client"
@@ -38,12 +40,15 @@ import (
3840
)
3941

4042
var (
41-
storageDir = flag.String("storage_dir", "", "Path to directory in which to store the migrated data.")
42-
sourceURL = flag.String("source_url", "", "Base monitoring URL for the source log.")
43-
numWorkers = flag.Uint("num_workers", 30, "Number of migration worker goroutines.")
44-
persistentAntispam = flag.Bool("antispam", true, "Set to true to populate antispam storage.")
45-
antispamBatchSize = flag.Uint("antispam_batch_size", 50000, "Maximum number of antispam rows to insert per batch update.")
46-
clientHTTPTimeout = flag.Duration("client_http_timeout", 30*time.Second, "Timeout for outgoing HTTP requests")
43+
storageDir = flag.String("storage_dir", "", "Path to directory in which to store the migrated data.")
44+
sourceURL = flag.String("source_url", "", "Base monitoring URL for the source log.")
45+
numWorkers = flag.Uint("num_workers", 30, "Number of migration worker goroutines.")
46+
persistentAntispam = flag.Bool("antispam", true, "Set to true to populate antispam storage.")
47+
antispamBatchSize = flag.Uint("antispam_batch_size", 50000, "Maximum number of antispam rows to insert per batch update.")
48+
antispamBlockCacheSize = flag.String("antispam_block_cache_size", "512MB", "Amount of RAM to allocate for antispam block cache, set to zero to disable.")
49+
antispamIndexCacheSize = flag.String("antispam_index_cache_size", "512MB", "Amount of RAM to allocate for antispam index cache, set to zero for unlimited.")
50+
antispamCompactionInterval = flag.Duration("antispam_compaction_interval", tposix_as.DefaultCompactionInterval, "Interval between GC/compaction runs on the antispam index.")
51+
clientHTTPTimeout = flag.Duration("client_http_timeout", 30*time.Second, "Timeout for outgoing HTTP requests")
4752
)
4853

4954
func main() {
@@ -103,10 +108,24 @@ func main() {
103108
// Configure antispam storage, if necessary
104109
var antispam tessera.Antispam
105110
if *persistentAntispam {
106-
as_opts := tposix_as.AntispamOpts{
107-
MaxBatchSize: *antispamBatchSize,
111+
antispamIndexCacheBytes, error := humanize.ParseBytes(*antispamIndexCacheSize)
112+
if error != nil {
113+
klog.Exitf("Invalid antispam index cache size: %v", error)
108114
}
109-
antispam, err = tposix_as.NewAntispam(ctx, filepath.Join(*storageDir, ".state", "antispam"), as_opts)
115+
antispamBlockCacheBytes, error := humanize.ParseBytes(*antispamBlockCacheSize)
116+
if error != nil {
117+
klog.Exitf("Invalid antispam block cache size: %v", error)
118+
}
119+
asOpts := tposix_as.AntispamOpts{
120+
MaxBatchSize: *antispamBatchSize,
121+
CompactionInterval: *antispamCompactionInterval,
122+
BadgerOptions: func(o badger.Options) badger.Options {
123+
return o.
124+
WithIndexCacheSize(int64(antispamIndexCacheBytes)).
125+
WithBlockCacheSize(int64(antispamBlockCacheBytes))
126+
},
127+
}
128+
antispam, err = tposix_as.NewAntispam(ctx, filepath.Join(*storageDir, ".state", "antispam"), asOpts)
110129
if err != nil {
111130
klog.Exitf("Failed to create new POSIX antispam storage: %v", err)
112131
}

cmd/tesseract/posix/main.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"syscall"
3535
"time"
3636

37+
"github.com/dgraph-io/badger/v4"
3738
"github.com/dustin/go-humanize"
3839
"github.com/transparency-dev/tessera"
3940
tposix "github.com/transparency-dev/tessera/storage/posix"
@@ -97,6 +98,10 @@ var (
9798
clientHTTPMaxIdle = flag.Int("client_http_max_idle", 20, "Maximum number of idle HTTP connections for outgoing requests.")
9899
clientHTTPMaxIdlePerHost = flag.Int("client_http_max_idle_per_host", 10, "Maximum number of idle HTTP connections per host for outgoing requests.")
99100
garbageCollectionInterval = flag.Duration("garbage_collection_interval", 10*time.Second, "Interval between scans to remove obsolete partial tiles and entry bundles. Set to 0 to disable.")
101+
antispamBatchSize = flag.Uint("antispam_batch_size", 20000, "Maximum number of antispam rows to insert per batch update.")
102+
antispamBlockCacheSize = flag.String("antispam_block_cache_size", "512MB", "Amount of RAM to allocate for antispam block cache, set to zero to disable.")
103+
antispamIndexCacheSize = flag.String("antispam_index_cache_size", "512MB", "Amount of RAM to allocate for antispam index cache, set to zero for unlimited.")
104+
antispamCompactionInterval = flag.Duration("antispam_compaction_interval", tposix_as.DefaultCompactionInterval, "Interval between GC/compaction runs on the antispam index.")
100105

101106
// Infrastructure setup flags
102107
storageDir = flag.String("storage_dir", "", "Path to root of log storage.")
@@ -222,8 +227,23 @@ func newStorage(ctx context.Context, signer note.Signer) (st *storage.CTStorage,
222227
if err != nil {
223228
return nil, fmt.Errorf("failed to initialize POSIX Tessera storage driver: %v", err)
224229
}
230+
antispamIndexCacheBytes, error := humanize.ParseBytes(*antispamIndexCacheSize)
231+
if error != nil {
232+
return nil, fmt.Errorf("invalid antispam index cache size: %v", error)
233+
}
234+
antispamBlockCacheBytes, error := humanize.ParseBytes(*antispamBlockCacheSize)
235+
if error != nil {
236+
return nil, fmt.Errorf("invalid antispam block cache size: %v", error)
237+
}
225238
asOpts := tposix_as.AntispamOpts{
226-
PushbackThreshold: *pushbackMaxAntispamLag,
239+
PushbackThreshold: *pushbackMaxAntispamLag,
240+
MaxBatchSize: *antispamBatchSize,
241+
CompactionInterval: *antispamCompactionInterval,
242+
BadgerOptions: func(o badger.Options) badger.Options {
243+
return o.
244+
WithIndexCacheSize(int64(antispamIndexCacheBytes)).
245+
WithBlockCacheSize(int64(antispamBlockCacheBytes))
246+
},
227247
}
228248
antispam, err := tposix_as.NewAntispam(ctx, filepath.Join(*storageDir, ".state", "antispam"), asOpts)
229249
if err != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/cenkalti/backoff/v5 v5.0.3
2020
github.com/charmbracelet/bubbletea v1.3.10
2121
github.com/charmbracelet/x/ansi v0.11.6
22+
github.com/dgraph-io/badger/v4 v4.9.1
2223
github.com/dustin/go-humanize v1.0.1
2324
github.com/fsouza/fake-gcs-server v1.54.0
2425
github.com/gdamore/tcell/v2 v2.13.8
@@ -90,7 +91,6 @@ require (
9091
github.com/clipperhouse/stringish v0.1.1 // indirect
9192
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
9293
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 // indirect
93-
github.com/dgraph-io/badger/v4 v4.9.1 // indirect
9494
github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect
9595
github.com/envoyproxy/go-control-plane/envoy v1.36.0 // indirect
9696
github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect

0 commit comments

Comments
 (0)