Skip to content

Commit

Permalink
Fix flag initialization
Browse files Browse the repository at this point in the history
Flag parsing happens in main, after all init functions have been called.
This change moves the parsing code from init to a custom flag Set
method.
  • Loading branch information
pav-kv committed Jun 7, 2022
1 parent d62733d commit 25e2d16
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions log/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package log
import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"strconv"
Expand Down Expand Up @@ -66,20 +67,41 @@ var (
QuotaIncreaseFactor = 1.1
)

type stringSet map[string]bool

func (s *stringSet) String() string {
if (*s)["*"] {
return "*"
}
keys := make([]string, 0, len(*s))
for k, v := range *s {
if v {
keys = append(keys, k)
}
}
return strings.Join(keys, ",")
}

func (s *stringSet) Set(value string) error {
if len(*s) > 0 {
return errors.New("flag already set")
}
for _, id := range strings.Split(value, ",") {
(*s)[id] = true
}
return nil
}

// The tree IDs for which sequencer does not store ephemeral node hashes.
// Trillian releases up to v1.4.1 store the ephemeral hashes, which corresponds
// to this slice being empty. Release v1.4.2 allows disabling this behaviour
// for individual, or all trees (denoted by the "*" wildcard). The release
// after v1.4.2 will switch to "*" behaviour unconditionally.
var idsWithNoEphemeralNodes = make(map[string]bool)
var idsWithNoEphemeralNodes stringSet = make(stringSet)

// TODO(pavelkalinnikov): Remove this flag in the next release.
func init() {
var ids string
flag.StringVar(&ids, "tree_ids_with_no_ephemeral_nodes", "", "Comma-separated list of tree IDs for which storing the ephemeral nodes is disabled, or * to disable it for all trees")
for _, id := range strings.Split(ids, ",") {
idsWithNoEphemeralNodes[id] = true
}
flag.Var(&idsWithNoEphemeralNodes, "tree_ids_with_no_ephemeral_nodes", "Comma-separated list of tree IDs for which storing the ephemeral nodes is disabled, or * to disable it for all trees")
}

func quotaIncreaseFactor() float64 {
Expand Down

0 comments on commit 25e2d16

Please sign in to comment.