-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bin Shi <[email protected]>
- Loading branch information
1 parent
0e08a5e
commit dd860c4
Showing
4 changed files
with
193 additions
and
59 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,91 @@ | ||
// 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" | ||
"net/http" | ||
|
||
"github.com/pingcap/kvproto/pkg/tsopb" | ||
"github.com/tikv/pd/pkg/mcs/registry" | ||
"github.com/tikv/pd/server" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
var _ tsopb.TSOServer = (*Service)(nil) | ||
|
||
// SetUpRestHandler is a hook to sets up the REST service. | ||
var SetUpRestHandler = func(srv *Service) (http.Handler, server.APIServiceGroup) { | ||
return dummyRestService{}, server.APIServiceGroup{} | ||
} | ||
|
||
type dummyRestService struct{} | ||
|
||
func (d dummyRestService) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusNotImplemented) | ||
w.Write([]byte("not implemented")) | ||
} | ||
|
||
// Service is the gRPC service for TSO. | ||
type Service struct { | ||
ctx context.Context | ||
server *Server | ||
// settings | ||
} | ||
|
||
// NewService creates a new TSO service. | ||
func NewService(svr *Server) registry.RegistrableService { | ||
return &Service{ | ||
ctx: svr.Context(), | ||
server: svr, | ||
} | ||
} | ||
|
||
// RegisterGRPCService registers the service to gRPC server. | ||
func (s *Service) RegisterGRPCService(g *grpc.Server) { | ||
tsopb.RegisterTSOServer(g, s) | ||
} | ||
|
||
// RegisterRESTHandler registers the service to REST server. | ||
func (s *Service) RegisterRESTHandler(userDefineHandlers map[string]http.Handler) { | ||
handler, group := SetUpRestHandler(s) | ||
server.RegisterUserDefinedHandlers(userDefineHandlers, &group, handler) | ||
} | ||
|
||
// Tso returns a stream of timestamps | ||
func (s *Service) Tso(stream tsopb.TSO_TsoServer) error { | ||
return nil | ||
} | ||
|
||
// SyncMaxTS will check whether MaxTS is the biggest one among all Local TSOs this PD is holding when skipCheck is set, | ||
// and write it into all Local TSO Allocators then if it's indeed the biggest one. | ||
func (s *Service) SyncMaxTS(_ context.Context, request *tsopb.SyncMaxTSRequest) (*tsopb.SyncMaxTSResponse, error) { | ||
return nil, nil | ||
} | ||
|
||
// GetDCLocationInfo gets the dc-location info of the given dc-location from PD leader's TSO allocator manager. | ||
func (s *Service) GetDCLocationInfo(ctx context.Context, request *tsopb.GetDCLocationInfoRequest) (*tsopb.GetDCLocationInfoResponse, error) { | ||
return nil, nil | ||
} | ||
|
||
// SetExternalTimestamp sets a given external timestamp to perform stale read. | ||
func (s *Service) SetExternalTimestamp(ctx context.Context, request *tsopb.SetExternalTimestampRequest) (*tsopb.SetExternalTimestampResponse, error) { | ||
return nil, nil | ||
} | ||
|
||
// GetExternalTimestamp gets the saved external timstamp. | ||
func (s *Service) GetExternalTimestamp(ctx context.Context, request *tsopb.GetExternalTimestampRequest) (*tsopb.GetExternalTimestampResponse, error) { | ||
return nil, nil | ||
} |
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,65 @@ | ||
// 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" | ||
"time" | ||
|
||
"github.com/pingcap/log" | ||
basicsvr "github.com/tikv/pd/pkg/basic_server" | ||
_ "github.com/tikv/pd/pkg/mcs/registry" | ||
tsosvr "github.com/tikv/pd/pkg/mcs/tso/server" | ||
"github.com/tikv/pd/server/config" | ||
"go.etcd.io/etcd/clientv3" | ||
"go.uber.org/zap" | ||
_ "google.golang.org/grpc" | ||
) | ||
|
||
// TSOStart starts the TSO server. | ||
func TSOStart(ctx context.Context, cfg *config.Config) basicsvr.Server { | ||
// start client | ||
etcdTimeout := time.Second * 3 | ||
tlsConfig, err := cfg.Security.ToTLSConfig() | ||
if err != nil { | ||
return nil | ||
} | ||
etcdCfg, err := cfg.GenEmbedEtcdConfig() | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
endpoints := []string{etcdCfg.ACUrls[0].String()} | ||
log.Info("create etcd v3 client", zap.Strings("endpoints", endpoints), zap.Reflect("cert", cfg.Security)) | ||
|
||
lgc := zap.NewProductionConfig() | ||
lgc.Encoding = log.ZapEncodingName | ||
client, err := clientv3.New(clientv3.Config{ | ||
Endpoints: endpoints, | ||
DialTimeout: etcdTimeout, | ||
TLS: tlsConfig, | ||
LogConfig: &lgc, | ||
}) | ||
if err != nil { | ||
return nil | ||
} | ||
// start server | ||
svr := tsosvr.NewServer(ctx, client) | ||
// TODO: wait for #5933 to check-in | ||
//gs := grpc.NewServer() | ||
//registry.ServerServiceRegistry.RegisterService("TSO", tsosvr.NewService) | ||
//registry.ServerServiceRegistry.InstallAllGRPCServices(svr, gs) | ||
return svr | ||
} |