Merge pull request #14340 from xakdwch/main

etcdctl: add --max-txn-ops flag to make-mirror command
This commit is contained in:
Benjamin Wang 2022-08-17 05:36:16 +08:00 committed by GitHub
commit ff6b85da83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -29,6 +29,7 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.5.0...v3.6.0).
- When print endpoint status, [show db size in use](https://github.com/etcd-io/etcd/pull/13639)
- [Always print the raft_term in decimal](https://github.com/etcd-io/etcd/pull/13711) when displaying member list in json.
- [Add one more field `storageVersion`](https://github.com/etcd-io/etcd/pull/13773) into the response of command `etcdctl endpoint status`.
- Add [`--max-txn-ops`](https://github.com/etcd-io/etcd/pull/14340) flag to make-mirror command.
### etcdutl v3

View File

@ -1466,6 +1466,8 @@ RPC: UserRevokeRole
- dest-insecure-transport -- Disable transport security for client connections
- max-txn-ops -- Maximum number of operations permitted in a transaction during syncing updates
#### Output
The approximate total number of keys transferred to the destination cluster, updated every 30 seconds.

View File

@ -33,6 +33,10 @@ import (
"github.com/spf13/cobra"
)
const (
defaultMaxTxnOps = uint(128)
)
var (
mminsecureTr bool
mmcert string
@ -44,6 +48,7 @@ var (
mmpassword string
mmnodestprefix bool
mmrev int64
mmmaxTxnOps uint
)
// NewMakeMirrorCommand returns the cobra command for "makeMirror".
@ -56,6 +61,7 @@ func NewMakeMirrorCommand() *cobra.Command {
c.Flags().StringVar(&mmprefix, "prefix", "", "Key-value prefix to mirror")
c.Flags().Int64Var(&mmrev, "rev", 0, "Specify the kv revision to start to mirror")
c.Flags().UintVar(&mmmaxTxnOps, "max-txn-ops", defaultMaxTxnOps, "Maximum number of operations permitted in a transaction during syncing updates.")
c.Flags().StringVar(&mmdestprefix, "dest-prefix", "", "destination prefix to mirror a prefix to a different prefix in the destination cluster")
c.Flags().BoolVar(&mmnodestprefix, "no-dest-prefix", false, "mirror key-values to the root of the destination cluster")
c.Flags().StringVar(&mmcert, "dest-cert", "", "Identify secure client using this TLS certificate file for the destination cluster")
@ -197,6 +203,15 @@ func makeMirror(ctx context.Context, c *clientv3.Client, dc *clientv3.Client) er
ops = []clientv3.Op{}
}
lastRev = nextRev
if len(ops) == int(mmmaxTxnOps) {
_, err := dc.Txn(ctx).Then(ops...).Commit()
if err != nil {
return err
}
ops = []clientv3.Op{}
}
switch ev.Type {
case mvccpb.PUT:
ops = append(ops, clientv3.OpPut(modifyPrefix(string(ev.Kv.Key)), string(ev.Kv.Value)))