Skip to content

Commit

Permalink
storage: Move flag out of the package to main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
pav-kv committed Jan 22, 2021
1 parent 219fef4 commit 8f82c64
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
4 changes: 3 additions & 1 deletion cmd/trillian_log_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ var (
quotaSystem = flag.String("quota_system", "mysql", fmt.Sprintf("Quota system to use. One of: %v", quota.Providers()))
quotaDryRun = flag.Bool("quota_dry_run", false, "If true no requests are blocked due to lack of tokens")

storageSystem = flag.String("storage_system", "mysql", fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))

treeGCEnabled = flag.Bool("tree_gc", true, "If true, tree garbage collection (hard-deletion) is periodically performed")
treeDeleteThreshold = flag.Duration("tree_delete_threshold", serverutil.DefaultTreeDeleteThreshold, "Minimum period a tree has to remain deleted before being hard-deleted")
treeDeleteMinRunInterval = flag.Duration("tree_delete_min_run_interval", serverutil.DefaultTreeDeleteMinInterval, "Minimum interval between tree garbage collection sweeps. Actual runs happen randomly between [minInterval,2*minInterval).")
Expand Down Expand Up @@ -115,7 +117,7 @@ func main() {
options = append(options, opts...)
}

sp, err := storage.NewProviderFromFlags(mf)
sp, err := storage.NewProvider(*storageSystem, mf)
if err != nil {
glog.Exitf("Failed to get storage provider: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/trillian_log_signer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var (
"Increase factor for tokens replenished by sequencing-based quotas (1 means a 1:1 relationship between sequenced leaves and replenished tokens)."+
"Only effective for --quota_system=etcd.")

storageSystem = flag.String("storage_system", "mysql", fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))

preElectionPause = flag.Duration("pre_election_pause", 1*time.Second, "Maximum time to wait before starting elections")
masterHoldInterval = flag.Duration("master_hold_interval", 60*time.Second, "Minimum interval to hold mastership for")
masterHoldJitter = flag.Duration("master_hold_jitter", 120*time.Second, "Maximal random addition to --master_hold_interval")
Expand Down Expand Up @@ -108,7 +110,7 @@ func main() {
mf := prometheus.MetricFactory{}
monitoring.SetStartSpan(opencensus.StartSpan)

sp, err := storage.NewProviderFromFlags(mf)
sp, err := storage.NewProvider(*storageSystem, mf)
if err != nil {
glog.Exitf("Failed to get storage provider: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/trillian_map_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ var (
quotaSystem = flag.String("quota_system", "mysql", fmt.Sprintf("Quota system to use. One of: %v", quota.Providers()))
quotaDryRun = flag.Bool("quota_dry_run", false, "If true no requests are blocked due to lack of tokens")

storageSystem = flag.String("storage_system", "mysql", fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))

treeGCEnabled = flag.Bool("tree_gc", true, "If true, tree garbage collection (hard-deletion) is periodically performed")
treeDeleteThreshold = flag.Duration("tree_delete_threshold", serverutil.DefaultTreeDeleteThreshold, "Minimum period a tree has to remain deleted before being hard-deleted")
treeDeleteMinRunInterval = flag.Duration("tree_delete_min_run_interval", serverutil.DefaultTreeDeleteMinInterval, "Minimum interval between tree garbage collection sweeps. Actual runs happen randomly between [minInterval,2*minInterval).")
Expand Down Expand Up @@ -111,7 +113,7 @@ func main() {
options = append(options, opts...)
}

sp, err := storage.NewProviderFromFlags(mf)
sp, err := storage.NewProvider(*storageSystem, mf)
if err != nil {
glog.Exitf("Failed to get storage provider: %v", err)
}
Expand Down
6 changes: 0 additions & 6 deletions server/storage_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ type StorageProvider = storage.Provider
// Deprecated: storage.RegisterProvider should be used directly.
var RegisterStorageProvider = storage.RegisterProvider

// NewStorageProviderFromFlags returns a new StorageProvider instance of the
// type specified by flag.
//
// Deprecated: storage.NewProviderFromFlags should be used directly.
var NewStorageProviderFromFlags = storage.NewProviderFromFlags

// NewStorageProvider returns a new StorageProvider instance of the type
// specified by name.
//
Expand Down
14 changes: 2 additions & 12 deletions storage/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package storage

import (
"flag"
"fmt"
"sync"

Expand All @@ -27,9 +26,6 @@ import (
type NewProviderFunc func(monitoring.MetricFactory) (Provider, error)

var (
// TODO(pavelkalinnikov): Move this flag to main file.
storageSystem = flag.String("storage_system", "mysql", fmt.Sprintf("Storage system to use. One of: %v", providers()))

spMu sync.RWMutex
spByName = make(map[string]NewProviderFunc)
)
Expand All @@ -47,12 +43,6 @@ func RegisterProvider(name string, sp NewProviderFunc) error {
return nil
}

// NewProviderFromFlags returns a new Provider instance of the type
// specified by flag.
func NewProviderFromFlags(mf monitoring.MetricFactory) (Provider, error) {
return NewProvider(*storageSystem, mf)
}

// NewProvider returns a new Provider instance of the type specified by name.
func NewProvider(name string, mf monitoring.MetricFactory) (Provider, error) {
spMu.RLock()
Expand All @@ -66,8 +56,8 @@ func NewProvider(name string, mf monitoring.MetricFactory) (Provider, error) {
return sp(mf)
}

// providers returns a slice of all registered storage provider names.
func providers() []string {
// Providers returns a slice of all registered storage provider names.
func Providers() []string {
spMu.RLock()
defer spMu.RUnlock()

Expand Down

0 comments on commit 8f82c64

Please sign in to comment.