-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skeleton to initialize tso microservice (#5917)
ref #5836, ref #5858 This PR added the skeleton along the E2E path to initialize the TSO microservice. It mainly contains the following change: 1. Parse the subcommands from the command line arguments and refactor the entrypoints for all-in-one pd service and other independent microservice. Needs to compare with @lhy1024's recent PR #5858 2. Refactor Server/TSO config. 3. Add the skeleton alone E2E path to initialize the TSO microservice. Signed-off-by: Bin Shi <binshi.bing@gmail.com> Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
- Loading branch information
1 parent
a3bb320
commit 28a95cd
Showing
7 changed files
with
238 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright 2023 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"net/http" | ||
"os" | ||
|
||
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" | ||
"github.com/pingcap/errors" | ||
"github.com/pingcap/log" | ||
basicsvr "github.com/tikv/pd/pkg/basic_server" | ||
"github.com/tikv/pd/pkg/errs" | ||
"github.com/tikv/pd/pkg/tso" | ||
"github.com/tikv/pd/pkg/utils/logutil" | ||
"github.com/tikv/pd/pkg/utils/metricutil" | ||
"go.etcd.io/etcd/clientv3" | ||
) | ||
|
||
// If server doesn't implement all methods of basicsvr.Server, this line will result in a clear | ||
// error message like "*Server does not implement basicsvr.Server (missing Method method)" | ||
var _ basicsvr.Server = (*Server)(nil) | ||
|
||
// Server is the TSO server, and it implements basicsvr.Server. | ||
// nolint | ||
type Server struct { | ||
ctx context.Context | ||
} | ||
|
||
// TODO: Implement the following methods defined in basicsvr.Server | ||
|
||
// Name returns the unique etcd Name for this server in etcd cluster. | ||
func (s *Server) Name() string { | ||
return "" | ||
} | ||
|
||
// Context returns the context of server. | ||
func (s *Server) Context() context.Context { | ||
return s.ctx | ||
} | ||
|
||
// Run runs the pd server. | ||
func (s *Server) Run() error { | ||
return nil | ||
} | ||
|
||
// Close closes the server. | ||
func (s *Server) Close() { | ||
} | ||
|
||
// GetClient returns builtin etcd client. | ||
func (s *Server) GetClient() *clientv3.Client { | ||
return nil | ||
} | ||
|
||
// GetHTTPClient returns builtin http client. | ||
func (s *Server) GetHTTPClient() *http.Client { | ||
return nil | ||
} | ||
|
||
// CreateServerWrapper encapsulates the configuration/log/metrics initialization and create the server | ||
func CreateServerWrapper(args []string) (context.Context, context.CancelFunc, basicsvr.Server) { | ||
cfg := tso.NewConfig() | ||
err := cfg.Parse(os.Args[1:]) | ||
|
||
if cfg.Version { | ||
printVersionInfo() | ||
exit(0) | ||
} | ||
|
||
defer logutil.LogPanic() | ||
|
||
switch errors.Cause(err) { | ||
case nil: | ||
case flag.ErrHelp: | ||
exit(0) | ||
default: | ||
log.Fatal("parse cmd flags error", errs.ZapError(err)) | ||
} | ||
|
||
if cfg.ConfigCheck { | ||
printConfigCheckMsg(cfg) | ||
exit(0) | ||
} | ||
|
||
// TODO: Initialize logger | ||
|
||
// TODO: Make it configurable if it has big impact on performance. | ||
grpcprometheus.EnableHandlingTimeHistogram() | ||
|
||
metricutil.Push(&cfg.Metric) | ||
|
||
// TODO: Create the server | ||
|
||
return nil, nil, nil | ||
} | ||
|
||
// TODO: implement it | ||
func printVersionInfo() { | ||
} | ||
|
||
// TODO: implement it | ||
func printConfigCheckMsg(cfg *tso.Config) { | ||
} | ||
|
||
func exit(code int) { | ||
log.Sync() | ||
os.Exit(code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2023 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package configutil | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
// ConfigMetaData is an utility to test if a configuration is defined. | ||
type ConfigMetaData struct { | ||
meta *toml.MetaData | ||
path []string | ||
} | ||
|
||
// NewConfigMetadata is the a factory method to create a ConfigMetaData object | ||
func NewConfigMetadata(meta *toml.MetaData) *ConfigMetaData { | ||
return &ConfigMetaData{meta: meta} | ||
} | ||
|
||
// IsDefined checks if the given key is defined in the configuration | ||
func (m *ConfigMetaData) IsDefined(key string) bool { | ||
if m.meta == nil { | ||
return false | ||
} | ||
keys := append([]string(nil), m.path...) | ||
keys = append(keys, key) | ||
return m.meta.IsDefined(keys...) | ||
} | ||
|
||
// Child gets the config metadata of the given path | ||
func (m *ConfigMetaData) Child(path ...string) *ConfigMetaData { | ||
newPath := append([]string(nil), m.path...) | ||
newPath = append(newPath, path...) | ||
return &ConfigMetaData{ | ||
meta: m.meta, | ||
path: newPath, | ||
} | ||
} | ||
|
||
// CheckUndecoded checks if the configuration contains undefined items | ||
func (m *ConfigMetaData) CheckUndecoded() error { | ||
if m.meta == nil { | ||
return nil | ||
} | ||
undecoded := m.meta.Undecoded() | ||
if len(undecoded) == 0 { | ||
return nil | ||
} | ||
errInfo := "Config contains undefined item: " | ||
for _, key := range undecoded { | ||
errInfo += key.String() + ", " | ||
} | ||
return errors.New(errInfo[:len(errInfo)-2]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.