Skip to content

Commit

Permalink
Make raft-wal default when resource-apis is active (#19090)
Browse files Browse the repository at this point in the history
Make raft-wal default when v2 catalog experiment is on
  • Loading branch information
dhiaayachi authored and jmurret committed Oct 12, 2023
1 parent c869ee0 commit 5cd5171
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
4 changes: 2 additions & 2 deletions agent/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ func (b *builder) validate(rt RuntimeConfig) error {

// Raft LogStore validation
if rt.RaftLogStoreConfig.Backend != consul.LogStoreBackendBoltDB &&
rt.RaftLogStoreConfig.Backend != consul.LogStoreBackendWAL {
rt.RaftLogStoreConfig.Backend != consul.LogStoreBackendWAL && rt.RaftLogStoreConfig.Backend != consul.LogStoreBackendDefault {
return fmt.Errorf("raft_logstore.backend must be one of '%s' or '%s'",
consul.LogStoreBackendBoltDB, consul.LogStoreBackendWAL)
}
Expand Down Expand Up @@ -2782,7 +2782,7 @@ func (b *builder) parsePrefixFilter(telemetry *Telemetry) ([]string, []string) {
func (b *builder) raftLogStoreConfigVal(raw *RaftLogStoreRaw) consul.RaftLogStoreConfig {
var cfg consul.RaftLogStoreConfig
if raw != nil {
cfg.Backend = stringValWithDefault(raw.Backend, consul.LogStoreBackendBoltDB)
cfg.Backend = stringValWithDefault(raw.Backend, consul.LogStoreBackendDefault)
cfg.DisableLogCache = boolVal(raw.DisableLogCache)

cfg.Verification.Enabled = boolVal(raw.Verification.Enabled)
Expand Down
1 change: 0 additions & 1 deletion agent/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func DefaultSource() Source {
raft_snapshot_interval = "` + cfg.RaftConfig.SnapshotInterval.String() + `"
raft_trailing_logs = ` + strconv.Itoa(int(cfg.RaftConfig.TrailingLogs)) + `
raft_logstore {
backend = "boltdb"
wal {
segment_size_mb = 64
}
Expand Down
20 changes: 19 additions & 1 deletion agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6010,8 +6010,26 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
hcl: []string{``},
expected: func(rt *RuntimeConfig) {
rt.DataDir = dataDir
rt.RaftLogStoreConfig.Backend = consul.LogStoreBackendBoltDB
rt.RaftLogStoreConfig.Backend = consul.LogStoreBackendDefault
rt.RaftLogStoreConfig.WAL.SegmentSize = 64 * 1024 * 1024
},
})
run(t, testCase{
desc: "logstore defaults",
args: []string{
`-data-dir=` + dataDir,
},
json: []string{`
{
"experiments": ["resource-apis"]
}
`},
hcl: []string{`experiments=["resource-apis"]`},
expected: func(rt *RuntimeConfig) {
rt.DataDir = dataDir
rt.RaftLogStoreConfig.Backend = consul.LogStoreBackendDefault
rt.RaftLogStoreConfig.WAL.SegmentSize = 64 * 1024 * 1024
rt.Experiments = []string{"resource-apis"}
},
})
run(t, testCase{
Expand Down
5 changes: 3 additions & 2 deletions agent/consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ const (

// LogStoreBackend* are well-known string values used to configure different
// log store backends.
LogStoreBackendBoltDB = "boltdb"
LogStoreBackendWAL = "wal"
LogStoreBackendDefault = "default"
LogStoreBackendBoltDB = "boltdb"
LogStoreBackendWAL = "wal"
)

var (
Expand Down
21 changes: 16 additions & 5 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
}

// Initialize the Raft server.
if err := s.setupRaft(); err != nil {
if err := s.setupRaft(stringslice.Contains(flat.Experiments, CatalogResourceExperimentName)); err != nil {
s.Shutdown()
return nil, fmt.Errorf("Failed to start Raft: %v", err)
}
Expand Down Expand Up @@ -1032,7 +1032,7 @@ func (s *Server) connectCARootsMonitor(ctx context.Context) {
}

// setupRaft is used to setup and initialize Raft
func (s *Server) setupRaft() error {
func (s *Server) setupRaft(isCatalogResourceExperiment bool) error {
// If we have an unclean exit then attempt to close the Raft store.
defer func() {
if s.raft == nil && s.raftStore != nil {
Expand Down Expand Up @@ -1091,8 +1091,7 @@ func (s *Server) setupRaft() error {
return fmt.Errorf("failed trying to see if raft.db exists not sure how to continue: %w", err)
}

// Only use WAL if there is no existing raft.db, even if it's enabled.
if s.config.LogStoreConfig.Backend == LogStoreBackendWAL && !boltFileExists {
initWAL := func() error {
walDir := filepath.Join(path, "wal")
if err := os.MkdirAll(walDir, 0755); err != nil {
return err
Expand All @@ -1111,13 +1110,25 @@ func (s *Server) setupRaft() error {
s.raftStore = wal
log = wal
stable = wal
return nil
}
// Only use WAL if there is no existing raft.db, even if it's enabled.
if s.config.LogStoreConfig.Backend == LogStoreBackendDefault && !boltFileExists && isCatalogResourceExperiment {
s.config.LogStoreConfig.Backend = LogStoreBackendWAL
if err = initWAL(); err != nil {
return err
}
} else if s.config.LogStoreConfig.Backend == LogStoreBackendWAL && !boltFileExists {
if err = initWAL(); err != nil {
return err
}
} else {
if s.config.LogStoreConfig.Backend == LogStoreBackendWAL {
// User configured the new storage, but still has old raft.db. Warn
// them!
s.logger.Warn("BoltDB file raft.db found, IGNORING raft_logstore.backend which is set to 'wal'")
}

s.config.LogStoreConfig.Backend = LogStoreBackendBoltDB
// Create the backend raft store for logs and stable storage.
store, err := raftboltdb.New(raftboltdb.Options{
BoltOptions: &bbolt.Options{
Expand Down
8 changes: 6 additions & 2 deletions agent/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ func getPrometheusDefs(cfg *config.RuntimeConfig, isServer bool) ([]prometheus.G
gauges = append(gauges, verifierGauges)
}

if isServer && cfg.RaftLogStoreConfig.Backend == consul.LogStoreBackendWAL {
if isServer &&
(cfg.RaftLogStoreConfig.Backend == consul.LogStoreBackendWAL ||
cfg.RaftLogStoreConfig.Backend == consul.LogStoreBackendDefault) {

walGauges := make([]prometheus.GaugeDefinition, 0)
for _, d := range wal.MetricDefinitions.Gauges {
Expand Down Expand Up @@ -452,7 +454,9 @@ func getPrometheusDefs(cfg *config.RuntimeConfig, isServer bool) ([]prometheus.G
}
counters = append(counters, verifierCounters)
}
if isServer && cfg.RaftLogStoreConfig.Backend == consul.LogStoreBackendWAL {
if isServer &&
(cfg.RaftLogStoreConfig.Backend == consul.LogStoreBackendWAL ||
cfg.RaftLogStoreConfig.Backend == consul.LogStoreBackendDefault) {
walCounters := make([]prometheus.CounterDefinition, 0)
for _, d := range wal.MetricDefinitions.Counters {
walCounters = append(walCounters, prometheus.CounterDefinition{
Expand Down

0 comments on commit 5cd5171

Please sign in to comment.