github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/cmd/redo/meta.go (about) 1 // Copyright 2021 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package redo 15 16 import ( 17 "github.com/pingcap/tiflow/pkg/applier" 18 cmdcontext "github.com/pingcap/tiflow/pkg/cmd/context" 19 "github.com/spf13/cobra" 20 ) 21 22 // metaOptions defines flags for the `redo meta` command. 23 type metaOptions struct { 24 options 25 } 26 27 // newMetaOptions creates new MetaOptions for the `redo apply` command. 28 func newMetaOptions() *metaOptions { 29 return &metaOptions{} 30 } 31 32 // run runs the `redo meta` command. 33 func (o *metaOptions) run(cmd *cobra.Command) error { 34 ctx := cmdcontext.GetDefaultContext() 35 36 cfg := &applier.RedoApplierConfig{ 37 Storage: o.storage, 38 Dir: o.dir, 39 } 40 ap := applier.NewRedoApplier(cfg) 41 checkpointTs, resolvedTs, err := ap.ReadMeta(ctx) 42 if err != nil { 43 return err 44 } 45 cmd.Printf("checkpoint-ts:%d, resolved-ts:%d\n", checkpointTs, resolvedTs) 46 return nil 47 } 48 49 // newCmdMeta creates the `redo meta` command. 50 func newCmdMeta(opt *options) *cobra.Command { 51 command := &cobra.Command{ 52 Use: "meta", 53 Short: "read redo log meta", 54 RunE: func(cmd *cobra.Command, args []string) error { 55 o := newMetaOptions() 56 o.options = *opt 57 return o.run(cmd) 58 }, 59 } 60 61 return command 62 }