This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
worker, ha: increase keepalive TTL to 1 minute, and to 30 minutes if relay enabled #1405
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
17ff623
worker, ha: increase keepalive TTL to 1 minute, and 30 minutes if rel…
lance6716 d35c2af
fix CI
lance6716 6477292
Merge branch 'master' of https://github.com/pingcap/dm into dynamic-k…
lance6716 a070119
make vet happy and add IT
lance6716 37eeed1
also change TTL in config
lance6716 84d69a5
fix CI
lance6716 2b87406
Update tests/incremental_mode/run.sh
lance6716 d5fd23a
address comment
lance6716 b1ce5ed
Merge branch 'master' into dynamic-keepalive
lance6716 53c0444
Merge branch 'dynamic-keepalive' of github.com:lance6716/dm into dyna…
lance6716 7766214
fix CI
lance6716 a6cb5bb
Merge branch 'master' into dynamic-keepalive
lance6716 41ec924
fix CI
lance6716 387d9e1
address comment
lance6716 6dd8b52
Merge branch 'master' into dynamic-keepalive
lance6716 132afd4
Merge branch 'master' into dynamic-keepalive
lance6716 66b581f
Merge branch 'master' into dynamic-keepalive
lance6716 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 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 |
---|---|---|
|
@@ -27,6 +27,15 @@ import ( | |
"github.com/pingcap/dm/pkg/log" | ||
) | ||
|
||
var ( | ||
keepAliveUpdateCh = make(chan int64, 10) | ||
) | ||
|
||
// NotifyKeepAliveChange is used to dynamically change keepalive TTL and don't let watcher observe a DELETE of old key | ||
func NotifyKeepAliveChange(newTTL int64) { | ||
keepAliveUpdateCh <- newTTL | ||
} | ||
|
||
// WorkerEvent represents the PUT/DELETE keepalive event of DM-worker. | ||
type WorkerEvent struct { | ||
WorkerName string `json:"worker-name"` // the worker name of the worker. | ||
|
@@ -98,7 +107,12 @@ func KeepAlive(ctx context.Context, cli *clientv3.Client, workerName string, kee | |
} | ||
}() | ||
|
||
ch, err := cli.KeepAlive(ctx, lease.ID) | ||
keepAliveCtx, keepAliveCancel := context.WithCancel(ctx) | ||
defer func() { | ||
keepAliveCancel() | ||
}() | ||
lichunzhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ch, err := cli.KeepAlive(keepAliveCtx, lease.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -112,6 +126,30 @@ func KeepAlive(ctx context.Context, cli *clientv3.Client, workerName string, kee | |
case <-ctx.Done(): | ||
log.L().Info("ctx is canceled, keepalive will exit now") | ||
return nil | ||
case newTTL := <-keepAliveUpdateCh: | ||
// create a new lease with new TTL, and overwrite original KV | ||
cliCtx, cancel := context.WithTimeout(ctx, etcdutil.DefaultRequestTimeout) | ||
defer cancel() | ||
lease, err = cli.Grant(cliCtx, newTTL) | ||
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. The revokeLease function should be called for the old lease, like line 104. 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. lease will expire if not keepalive, so I think it's not needed |
||
if err != nil { | ||
log.L().Error("meet error when change keepalive TTL", zap.Error(err)) | ||
return err | ||
} | ||
_, err = cli.Put(cliCtx, k, workerEventJSON, clientv3.WithLease(lease.ID)) | ||
if err != nil { | ||
log.L().Error("meet error when change keepalive TTL", zap.Error(err)) | ||
return err | ||
} | ||
|
||
oldCancel := keepAliveCancel | ||
keepAliveCtx, keepAliveCancel = context.WithCancel(ctx) | ||
ch, err = cli.KeepAlive(keepAliveCtx, lease.ID) | ||
if err != nil { | ||
log.L().Error("meet error when change keepalive TTL", zap.Error(err)) | ||
return err | ||
} | ||
// after new keepalive is succeed, we cancel the old keepalive | ||
oldCancel() | ||
lichunzhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
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.
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.
What if I set
KeepAliveTTL
to31s
? 🤔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.
I think we should left a chance if user doesn't want this feature, so only increase TTL when default value
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.
Then I think we should add a
configuration
namedrelayEnabledKeepAliveTTL
. In the current way, I can't setkeepAliveTTL
and increaserelayKeepAliveTTL
at the same time.