-
Notifications
You must be signed in to change notification settings - Fork 3
Thread-safe config reads and SIGHUP reload for HTTP API server #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
122339c
fix: thread-safe config reads and SIGHUP reload for HTTP API server
mason-sharp 0b6a360
fix: snapshot CDC config once per replication stream to prevent mid-s…
mason-sharp 9c711e8
fix: snapshot mtree schema once per task to prevent mid-task config d…
mason-sharp d2b3168
refactor: snapshot config per request and extract SIGHUP reload helper
mason-sharp 03fce10
fix: use config.Get() consistently and simplify Reload() signature
mason-sharp d3e2988
fix: reload mTLS security config on SIGHUP
rasifr a5db6e9
fix: address few minor issues with SIGHUP reload correctness and docs
rasifr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/pgedge/ace/pkg/config" | ||
| ) | ||
|
|
||
| // TestResolversPickUpReloadedConfig verifies that the handler resolver | ||
| // functions read from the config snapshot passed to them, so that a | ||
| // SIGHUP-triggered config.Set takes effect for subsequent API requests | ||
| // while keeping each request internally consistent. | ||
| func TestResolversPickUpReloadedConfig(t *testing.T) { | ||
| original := config.Get() | ||
| t.Cleanup(func() { | ||
| if original != nil { | ||
| config.Set(original) | ||
| } else { | ||
| config.Set(&config.Config{}) | ||
| } | ||
| }) | ||
|
|
||
| // Set initial config. | ||
| config.Set(&config.Config{ | ||
| TableDiff: config.DiffConfig{ | ||
| DiffBlockSize: 5000, | ||
| ConcurrencyFactor: 0.25, | ||
| CompareUnitSize: 2000, | ||
| MaxDiffRows: 100, | ||
| }, | ||
| Server: config.ServerConfig{ | ||
| TaskStorePath: "/tmp/old-tasks.db", | ||
| }, | ||
| }) | ||
|
|
||
| s := &APIServer{} | ||
| cfg := config.Get() | ||
|
|
||
| // Verify resolvers return initial values (0 = "use config default"). | ||
| if got := s.resolveBlockSize(cfg, 0); got != 5000 { | ||
| t.Errorf("resolveBlockSize: got %d, want 5000", got) | ||
| } | ||
| if got := s.resolveConcurrency(cfg, 0); got != 0.25 { | ||
| t.Errorf("resolveConcurrency: got %f, want 0.25", got) | ||
| } | ||
| if got := s.resolveCompareUnitSize(cfg, 0); got != 2000 { | ||
| t.Errorf("resolveCompareUnitSize: got %d, want 2000", got) | ||
| } | ||
| if got := s.resolveMaxDiffRows(cfg, 0); got != 100 { | ||
| t.Errorf("resolveMaxDiffRows: got %d, want 100", got) | ||
| } | ||
| if got := cfg.Server.TaskStorePath; got != "/tmp/old-tasks.db" { | ||
| t.Errorf("TaskStorePath: got %q, want /tmp/old-tasks.db", got) | ||
| } | ||
|
|
||
| // Simulate SIGHUP: swap in new config. | ||
| config.Set(&config.Config{ | ||
| TableDiff: config.DiffConfig{ | ||
| DiffBlockSize: 9999, | ||
| ConcurrencyFactor: 0.75, | ||
| CompareUnitSize: 4000, | ||
| MaxDiffRows: 500, | ||
| }, | ||
| Server: config.ServerConfig{ | ||
| TaskStorePath: "/tmp/new-tasks.db", | ||
| }, | ||
| }) | ||
|
|
||
| newCfg := config.Get() | ||
|
|
||
| // Verify resolvers now return the reloaded values. | ||
| if got := s.resolveBlockSize(newCfg, 0); got != 9999 { | ||
| t.Errorf("after reload resolveBlockSize: got %d, want 9999", got) | ||
| } | ||
| if got := s.resolveConcurrency(newCfg, 0); got != 0.75 { | ||
| t.Errorf("after reload resolveConcurrency: got %f, want 0.75", got) | ||
| } | ||
| if got := s.resolveCompareUnitSize(newCfg, 0); got != 4000 { | ||
| t.Errorf("after reload resolveCompareUnitSize: got %d, want 4000", got) | ||
| } | ||
| if got := s.resolveMaxDiffRows(newCfg, 0); got != 500 { | ||
| t.Errorf("after reload resolveMaxDiffRows: got %d, want 500", got) | ||
| } | ||
| if got := newCfg.Server.TaskStorePath; got != "/tmp/new-tasks.db" { | ||
| t.Errorf("after reload TaskStorePath: got %q, want /tmp/new-tasks.db", got) | ||
| } | ||
|
|
||
| // Verify old snapshot still returns old values (per-request consistency). | ||
| if got := s.resolveBlockSize(cfg, 0); got != 5000 { | ||
| t.Errorf("old snapshot resolveBlockSize: got %d, want 5000", got) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.