etcdctl: add --max-txn-ops flag to make-mirror command

--max-txn-ops flag allows users to define the maximum number of operations permitted in
a transaction during syncing updates.if unlimited syncing may fail when number of txn ops
exceeds the maximum number of server side.

Signed-off-by: xakdwch <xakdwch5@gmail.com>
This commit is contained in:
xakdwch 2022-08-12 16:35:36 +08:00
parent 043a3aa70e
commit 7cc3f5f97e
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) - 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. - [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 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 ### etcdutl v3

View File

@ -1466,6 +1466,8 @@ RPC: UserRevokeRole
- dest-insecure-transport -- Disable transport security for client connections - dest-insecure-transport -- Disable transport security for client connections
- max-txn-ops -- Maximum number of operations permitted in a transaction during syncing updates
#### Output #### Output
The approximate total number of keys transferred to the destination cluster, updated every 30 seconds. 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" "github.com/spf13/cobra"
) )
const (
defaultMaxTxnOps = uint(128)
)
var ( var (
mminsecureTr bool mminsecureTr bool
mmcert string mmcert string
@ -44,6 +48,7 @@ var (
mmpassword string mmpassword string
mmnodestprefix bool mmnodestprefix bool
mmrev int64 mmrev int64
mmmaxTxnOps uint
) )
// NewMakeMirrorCommand returns the cobra command for "makeMirror". // 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().StringVar(&mmprefix, "prefix", "", "Key-value prefix to mirror")
c.Flags().Int64Var(&mmrev, "rev", 0, "Specify the kv revision to start 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().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().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") 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{} ops = []clientv3.Op{}
} }
lastRev = nextRev 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 { switch ev.Type {
case mvccpb.PUT: case mvccpb.PUT:
ops = append(ops, clientv3.OpPut(modifyPrefix(string(ev.Kv.Key)), string(ev.Kv.Value))) ops = append(ops, clientv3.OpPut(modifyPrefix(string(ev.Kv.Key)), string(ev.Kv.Value)))