-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: add graceful stop timeout to avoid node stop hang under extr…
…eme cases (#30320) 1. add coordinator and proxy graceful stop timeout to 5s. 3. add other work node graceful stop timeout to 900s, and we should potentially change this to 600s when graceful stop is smooth 4. change the order of datacoord component while stop. 5. `LivenessCheck` do not perform graceful shutdown now. issue: #30310 pr: #30317 also see: #30306 --------- Signed-off-by: chyezh <[email protected]>
- Loading branch information
Showing
26 changed files
with
282 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,38 @@ | ||
package components | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"time" | ||
|
||
"github.com/cockroachdb/errors" | ||
|
||
"github.com/milvus-io/milvus/pkg/util/conc" | ||
) | ||
|
||
var errStopTimeout = errors.New("stop timeout") | ||
|
||
// exitWhenStopTimeout stops a component with timeout and exit progress when timeout. | ||
func exitWhenStopTimeout(stop func() error, timeout time.Duration) error { | ||
err := stopWithTimeout(stop, timeout) | ||
if errors.Is(err, errStopTimeout) { | ||
os.Exit(1) | ||
} | ||
return err | ||
} | ||
|
||
// stopWithTimeout stops a component with timeout. | ||
func stopWithTimeout(stop func() error, timeout time.Duration) error { | ||
ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
defer cancel() | ||
|
||
future := conc.Go(func() (struct{}, error) { | ||
return struct{}{}, stop() | ||
}) | ||
select { | ||
case <-future.Inner(): | ||
return errors.Wrap(future.Err(), "failed to stop component") | ||
case <-ctx.Done(): | ||
return errStopTimeout | ||
} | ||
} |
This file contains 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,38 @@ | ||
package components | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/cockroachdb/errors" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestExitWithTimeout(t *testing.T) { | ||
// only normal path can be tested. | ||
targetErr := errors.New("stop error") | ||
err := exitWhenStopTimeout(func() error { | ||
time.Sleep(1 * time.Second) | ||
return targetErr | ||
}, 5*time.Second) | ||
assert.ErrorIs(t, err, targetErr) | ||
} | ||
|
||
func TestStopWithTimeout(t *testing.T) { | ||
ch := make(chan struct{}) | ||
stop := func() error { | ||
<-ch | ||
return nil | ||
} | ||
|
||
err := stopWithTimeout(stop, 1*time.Second) | ||
assert.ErrorIs(t, err, errStopTimeout) | ||
|
||
targetErr := errors.New("stop error") | ||
stop = func() error { | ||
return targetErr | ||
} | ||
|
||
err = stopWithTimeout(stop, 1*time.Second) | ||
assert.ErrorIs(t, err, targetErr) | ||
} |
This file contains 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 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 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.