-
Notifications
You must be signed in to change notification settings - Fork 305
fix: speed up hakeeper bootstrap #26760
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| "sync/atomic" | ||
| "time" | ||
|
|
||
|
|
@@ -31,9 +32,10 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| minIDAllocCapacity uint64 = 1024 | ||
| defaultIDBatchSize uint64 = 1024 * 10 | ||
| checkBootstrapCycles = 100 | ||
| minIDAllocCapacity uint64 = 1024 | ||
| defaultIDBatchSize uint64 = 1024 * 10 | ||
| checkBootstrapCycles = 100 | ||
| bootstrapHAKeeperCheckInterval = 100 * time.Millisecond | ||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -252,16 +254,37 @@ func (l *store) getCheckerStateFromLeader() (*pb.CheckerState, uint64) { | |
|
|
||
| var debugPrintHAKeeperState atomic.Bool | ||
|
|
||
| func (l *store) hakeeperCheck() { | ||
| func (l *store) initialHAKeeperCheckInterval() time.Duration { | ||
| interval := l.cfg.HAKeeperCheckInterval.Duration | ||
| if interval > bootstrapHAKeeperCheckInterval { | ||
| return bootstrapHAKeeperCheckInterval | ||
| } | ||
| return interval | ||
| } | ||
|
|
||
| func (l *store) nextHAKeeperCheckInterval(state *pb.CheckerState) time.Duration { | ||
| interval := l.cfg.HAKeeperCheckInterval.Duration | ||
| if state != nil && state.State != pb.HAKeeperRunning { | ||
| if interval > bootstrapHAKeeperCheckInterval { | ||
| return bootstrapHAKeeperCheckInterval | ||
| } | ||
| } | ||
| return interval | ||
| } | ||
|
Comment on lines
+265
to
+273
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 33cdfa7. nil checker state now keeps the configured HAKeeper check interval, so non-leader LogServices do not stay on the 100ms bootstrap cadence. Verified with |
||
|
|
||
| func (l *store) hakeeperCheck() *pb.CheckerState { | ||
| state, term := l.getCheckerStateFromLeader() | ||
| if state == nil { | ||
| return | ||
| return nil | ||
| } | ||
|
|
||
| switch state.State { | ||
| case pb.HAKeeperCreated: | ||
| l.runtime.Logger().Warn("waiting for initial cluster info to be set, check skipped") | ||
| return | ||
| if time.Since(l.lastBootstrapLogTime) >= time.Second { | ||
| l.runtime.Logger().Warn("waiting for initial cluster info to be set, check skipped") | ||
| l.lastBootstrapLogTime = time.Now() | ||
| } | ||
| return state | ||
|
Comment on lines
282
to
+287
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 33cdfa7. The HAKeeperCreated warning is now throttled to once per second using the existing bootstrap log timestamp. Verified with |
||
| case pb.HAKeeperBootstrapping: | ||
| l.bootstrap(term, state) | ||
| case pb.HAKeeperBootstrapCommandsReceived: | ||
|
|
@@ -277,6 +300,7 @@ func (l *store) hakeeperCheck() { | |
| default: | ||
| panic("unknown HAKeeper state") | ||
| } | ||
| return state | ||
| } | ||
|
|
||
| func (l *store) assertHAKeeperState(s pb.HAKeeperState) { | ||
|
|
@@ -358,6 +382,13 @@ func (l *store) bootstrap(term uint64, state *pb.CheckerState) { | |
| } | ||
| cmds, err := l.getScheduleCommand(false, term, state) | ||
| if err != nil { | ||
| if isBootstrapWaitingForLogStores(err) { | ||
| if time.Since(l.lastBootstrapLogTime) >= time.Second { | ||
| l.runtime.Logger().Info("waiting for log stores before bootstrap", zap.Error(err)) | ||
| l.lastBootstrapLogTime = time.Now() | ||
| } | ||
| return | ||
| } | ||
| l.runtime.Logger().Error("failed to get bootstrap schedule commands", zap.Error(err)) | ||
| return | ||
| } | ||
|
|
@@ -398,9 +429,17 @@ func (l *store) bootstrap(term uint64, state *pb.CheckerState) { | |
| l.bootstrapCheckCycles = checkBootstrapCycles | ||
| l.bootstrapMgr = bootstrap.NewBootstrapManager(state.ClusterInfo) | ||
| l.assertHAKeeperState(pb.HAKeeperBootstrapCommandsReceived) | ||
| if l.bootstrapCommandsAdded != nil { | ||
| l.bootstrapCommandsAdded() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func isBootstrapWaitingForLogStores(err error) bool { | ||
| return moerr.IsMoErrCode(err, moerr.ErrInternal) && | ||
| strings.Contains(err.Error(), "not enough log stores") | ||
| } | ||
|
|
||
| func (l *store) checkBootstrap(state *pb.CheckerState) { | ||
| l.checkBootstrapWithSetter(state, l.setBootstrapState) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ import ( | |
| "github.com/matrixorigin/matrixone/pkg/pb/metadata" | ||
| "github.com/matrixorigin/matrixone/pkg/pb/task" | ||
| "github.com/matrixorigin/matrixone/pkg/taskservice" | ||
| "github.com/matrixorigin/matrixone/pkg/util/toml" | ||
| ) | ||
|
|
||
| func TestIDAllocatorDefaultState(t *testing.T) { | ||
|
|
@@ -46,6 +47,29 @@ func TestIDAllocatorDefaultState(t *testing.T) { | |
| assert.Equal(t, uint64(0), v) | ||
| } | ||
|
|
||
| func TestNextHAKeeperCheckIntervalUsesFastBootstrapInterval(t *testing.T) { | ||
| s := &store{ | ||
| cfg: Config{ | ||
| HAKeeperCheckInterval: toml.Duration{Duration: 3 * time.Second}, | ||
| }, | ||
| } | ||
|
|
||
| require.Equal(t, bootstrapHAKeeperCheckInterval, s.initialHAKeeperCheckInterval()) | ||
| require.Equal(t, 3*time.Second, s.nextHAKeeperCheckInterval(nil)) | ||
| require.Equal(t, bootstrapHAKeeperCheckInterval, s.nextHAKeeperCheckInterval(&pb.CheckerState{ | ||
| State: pb.HAKeeperCreated, | ||
| })) | ||
| require.Equal(t, bootstrapHAKeeperCheckInterval, s.nextHAKeeperCheckInterval(&pb.CheckerState{ | ||
| State: pb.HAKeeperBootstrapping, | ||
| })) | ||
| require.Equal(t, bootstrapHAKeeperCheckInterval, s.nextHAKeeperCheckInterval(&pb.CheckerState{ | ||
| State: pb.HAKeeperBootstrapCommandsReceived, | ||
| })) | ||
| require.Equal(t, 3*time.Second, s.nextHAKeeperCheckInterval(&pb.CheckerState{ | ||
| State: pb.HAKeeperRunning, | ||
| })) | ||
| } | ||
|
Comment on lines
+50
to
+71
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 33cdfa7. The test now asserts nil uses the configured interval, adds an explicit HAKeeperCreated bootstrap case, and checks the separate initial fast interval helper. Verified with |
||
|
|
||
| func TestIDAllocatorCapacity(t *testing.T) { | ||
| tests := []struct { | ||
| next uint64 | ||
|
|
@@ -940,11 +964,16 @@ func testBootstrap(t *testing.T, fail bool, remoteRecoveryPending bool) { | |
|
|
||
| state, err = store.getCheckerState() | ||
| require.NoError(t, err) | ||
| bootstrapCommandsAdded := false | ||
| store.bootstrapCommandsAdded = func() { | ||
| bootstrapCommandsAdded = true | ||
| } | ||
| store.bootstrap(term, state) | ||
|
|
||
| state, err = store.getCheckerState() | ||
| require.NoError(t, err) | ||
| assert.Equal(t, pb.HAKeeperBootstrapCommandsReceived, state.State) | ||
| assert.True(t, bootstrapCommandsAdded) | ||
| assert.Equal(t, uint64(checkBootstrapCycles), store.bootstrapCheckCycles) | ||
| require.NotNil(t, store.bootstrapMgr) | ||
| assert.False(t, store.bootstrapMgr.CheckBootstrap(state.LogState)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Updated the PR title to
fix: speed up hakeeper bootstrapand adjusted the body to describe the runtime bootstrap responsiveness and steady-state interval behavior.