Skip to content
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

[bug] logservice: add timeout for RPC read. #12160

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/mo-service/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ func waitAnyShardReady(client logservice.CNHAKeeperClient) error {
if ok, err := func() (bool, error) {
details, err := client.GetClusterDetails(ctx)
if err != nil {
return false, err
if errors.Is(err, context.DeadlineExceeded) {
logutil.Errorf("wait TN ready timeout: %s", err)
return false, err
}
logutil.Errorf("failed to get cluster details %s", err)
return false, nil
}
for _, store := range details.TNStores {
if len(store.Shards) > 0 {
Expand Down
12 changes: 11 additions & 1 deletion pkg/logservice/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,15 @@ func connectToLogService(ctx context.Context,
addresses[i], addresses[j] = addresses[j], addresses[i]
})
for _, addr := range addresses {
cc, err := getRPCClient(ctx, addr, c.respPool, c.cfg.MaxMessageSize, cfg.EnableCompress, cfg.Tag)
cc, err := getRPCClient(
ctx,
addr,
c.respPool,
c.cfg.MaxMessageSize,
cfg.EnableCompress,
0,
cfg.Tag,
)
if err != nil {
e = err
continue
Expand Down Expand Up @@ -511,6 +519,7 @@ func getRPCClient(
pool *sync.Pool,
maxMessageSize int,
enableCompress bool,
readTimeout time.Duration,
tag ...string) (morpc.RPCClient, error) {
mf := func() morpc.Message {
return pool.Get().(*RPCResponse)
Expand All @@ -521,6 +530,7 @@ func getRPCClient(
morpc.WithBackendConnectTimeout(time.Second),
morpc.WithBackendHasPayloadResponse(),
morpc.WithBackendLogger(logutil.GetGlobalLogger().Named("hakeeper-client-backend")),
morpc.WithBackendReadTimeout(readTimeout),
}
backendOpts = append(backendOpts, GetBackendOptions(ctx)...)

Expand Down
15 changes: 14 additions & 1 deletion pkg/logservice/hakeeper_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"math/rand"
"sync"
"time"

"go.uber.org/zap"

Expand All @@ -30,6 +31,10 @@ import (
"github.com/matrixorigin/matrixone/pkg/util/trace"
)

const (
defaultBackendReadTimeout = time.Second * 8
)

type basicHAKeeperClient interface {
// Close closes the hakeeper client.
Close() error
Expand Down Expand Up @@ -571,7 +576,15 @@ func connectToHAKeeper(ctx context.Context,
addresses[i], addresses[j] = addresses[j], addresses[i]
})
for _, addr := range addresses {
cc, err := getRPCClient(ctx, addr, c.respPool, defaultMaxMessageSize, cfg.EnableCompress, "connectToHAKeeper")
cc, err := getRPCClient(
ctx,
addr,
c.respPool,
defaultMaxMessageSize,
cfg.EnableCompress,
defaultBackendReadTimeout,
"connectToHAKeeper",
)
if err != nil {
e = err
continue
Expand Down
9 changes: 8 additions & 1 deletion pkg/logservice/hakeeper_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,14 @@ func testNotHAKeeperErrorIsHandled(t *testing.T, fn func(*testing.T, *managedHAK
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
cc, err := getRPCClient(ctx, cfg1.LogServiceServiceAddr(), c.respPool, defaultMaxMessageSize, false)
cc, err := getRPCClient(
ctx,
cfg1.LogServiceServiceAddr(),
c.respPool,
defaultMaxMessageSize,
false,
0,
)
require.NoError(t, err)
c.addr = cfg1.LogServiceServiceAddr()
c.client = cc
Expand Down
10 changes: 9 additions & 1 deletion pkg/logservice/shardinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ func GetShardInfo(address string, shardID uint64) (ShardInfo, bool, error) {
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
cc, err := getRPCClient(ctx, address, respPool, defaultMaxMessageSize, false, "GetShardInfo")
cc, err := getRPCClient(
ctx,
address,
respPool,
defaultMaxMessageSize,
false,
0,
"GetShardInfo",
)
if err != nil {
return ShardInfo{}, false, err
}
Expand Down