Skip to content

Commit f8a6077

Browse files
committed
Use badger opts
1 parent 05f0d9e commit f8a6077

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", 10000, "Maximum number of antispam rows to insert per batch update.")
48+
antispamBlockCacheSize = flag.String("antispam_block_cache_size", "768MB", "Amount of RAM to allocate for antispam block cache, set to zero to disable.")
49+
antispamIndexCacheSize = flag.String("antispam_index_cache_size", "768MB", "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"
@@ -98,6 +99,10 @@ var (
9899
clientHTTPMaxIdle = flag.Int("client_http_max_idle", 20, "Maximum number of idle HTTP connections for outgoing requests.")
99100
clientHTTPMaxIdlePerHost = flag.Int("client_http_max_idle_per_host", 10, "Maximum number of idle HTTP connections per host for outgoing requests.")
100101
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.")
102+
antispamBatchSize = flag.Uint("antispam_batch_size", 10000, "Maximum number of antispam rows to insert per batch update.")
103+
antispamBlockCacheSize = flag.String("antispam_block_cache_size", "768MB", "Amount of RAM to allocate for antispam block cache, set to zero to disable.")
104+
antispamIndexCacheSize = flag.String("antispam_index_cache_size", "768MB", "Amount of RAM to allocate for antispam index cache, set to zero for unlimited.")
105+
antispamCompactionInterval = flag.Duration("antispam_compaction_interval", tposix_as.DefaultCompactionInterval, "Interval between GC/compaction runs on the antispam index.")
101106

102107
// Infrastructure setup flags
103108
storageDir = flag.String("storage_dir", "", "Path to root of log storage.")
@@ -225,8 +230,23 @@ func newStorage(ctx context.Context, signer note.Signer) (st *storage.CTStorage,
225230
if err != nil {
226231
return nil, fmt.Errorf("failed to initialize POSIX Tessera storage driver: %v", err)
227232
}
233+
antispamIndexCacheBytes, error := humanize.ParseBytes(*antispamIndexCacheSize)
234+
if error != nil {
235+
return nil, fmt.Errorf("invalid antispam index cache size: %v", error)
236+
}
237+
antispamBlockCacheBytes, error := humanize.ParseBytes(*antispamBlockCacheSize)
238+
if error != nil {
239+
return nil, fmt.Errorf("invalid antispam block cache size: %v", error)
240+
}
228241
asOpts := tposix_as.AntispamOpts{
229-
PushbackThreshold: *pushbackMaxAntispamLag,
242+
PushbackThreshold: *pushbackMaxAntispamLag,
243+
MaxBatchSize: *antispamBatchSize,
244+
CompactionInterval: *antispamCompactionInterval,
245+
BadgerOptions: func(o badger.Options) badger.Options {
246+
return o.
247+
WithIndexCacheSize(int64(antispamIndexCacheBytes)).
248+
WithBlockCacheSize(int64(antispamBlockCacheBytes))
249+
},
230250
}
231251
antispam, err := tposix_as.NewAntispam(ctx, filepath.Join(*storageDir, ".state", "antispam"), asOpts)
232252
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)