From 25e2d16180fda617046da9e587013841de7d39a2 Mon Sep 17 00:00:00 2001 From: Pavel Kalinnikov Date: Tue, 7 Jun 2022 16:57:03 +0000 Subject: [PATCH] Fix flag initialization 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. --- log/sequencer.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/log/sequencer.go b/log/sequencer.go index 06953f53ad..be07b4c590 100644 --- a/log/sequencer.go +++ b/log/sequencer.go @@ -17,6 +17,7 @@ package log import ( "bytes" "context" + "errors" "flag" "fmt" "strconv" @@ -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 {