github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cmd/client_tso.go (about)

     1  // Copyright 2020 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 cmd
    15  
    16  import (
    17  	"os"
    18  
    19  	"github.com/pingcap/tidb/store/tikv/oracle"
    20  	"github.com/spf13/cobra"
    21  )
    22  
    23  func newTsoCommand() *cobra.Command {
    24  	command := &cobra.Command{
    25  		Use:   "tso",
    26  		Short: "Manage tso",
    27  	}
    28  	command.AddCommand(
    29  		newQueryTsoCommand(),
    30  	)
    31  	return command
    32  }
    33  
    34  func newQueryTsoCommand() *cobra.Command {
    35  	command := &cobra.Command{
    36  		Use:   "query",
    37  		Short: "Get tso from PD",
    38  		RunE: func(cmd *cobra.Command, args []string) error {
    39  			ctx := defaultContext
    40  			ts, logic, err := pdCli.GetTS(ctx)
    41  			if err != nil {
    42  				return err
    43  			}
    44  			cmd.Println(oracle.ComposeTS(ts, logic))
    45  			return nil
    46  		},
    47  	}
    48  	command.SetOut(os.Stdout)
    49  	command.SetErr(os.Stdout)
    50  	return command
    51  }