github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/ctl/cmd_ping.go (about)

     1  // Copyright 2021 - 2022 Matrix Origin
     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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ctl
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    19  
    20  	"github.com/fagongzi/util/format"
    21  	"github.com/fagongzi/util/protoc"
    22  	pb "github.com/matrixorigin/matrixone/pkg/pb/ctl"
    23  )
    24  
    25  func handlePing() handleFunc {
    26  	return getDNHandlerFunc(
    27  		pb.CmdMethod_Ping,
    28  		func(parameter string) ([]uint64, error) {
    29  			if len(parameter) > 0 {
    30  				id, err := format.ParseStringUint64(parameter)
    31  				if err != nil {
    32  					return nil, err
    33  				}
    34  				return []uint64{id}, nil
    35  			}
    36  			return nil, nil
    37  		},
    38  		func(dnShardID uint64, parameter string, _ *process.Process) ([]byte, error) {
    39  			return protoc.MustMarshal(&pb.DNPingRequest{Parameter: parameter}), nil
    40  		},
    41  		func(data []byte) (interface{}, error) {
    42  			pong := pb.DNPingResponse{}
    43  			protoc.MustUnmarshal(&pong, data)
    44  			return pong, nil
    45  		})
    46  }