Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Aug 28, 2023
1 parent 0278b12 commit 822af06
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 13 deletions.
8 changes: 4 additions & 4 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import (
"github.com/tikv/pd/server/join"
"go.uber.org/zap"

// register microservice HTTP API
_ "github.com/tikv/pd/pkg/mcs/resourcemanager/server/apis/v1"
_ "github.com/tikv/pd/pkg/mcs/scheduling/server/apis/v1"
_ "github.com/tikv/pd/pkg/mcs/tso/server/apis/v1"
// register microservice API
_ "github.com/tikv/pd/pkg/mcs/resourcemanager/server/install"
_ "github.com/tikv/pd/pkg/mcs/scheduling/server/install"
_ "github.com/tikv/pd/pkg/mcs/tso/server/install"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/resourcemanager/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Service struct {
}

// NewService creates a new resource manager service.
func NewService[T ResourceManagerConfigProvider](svr bs.Server) registry.RegistrableService {
func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService {
manager := NewManager[T](svr)

return &Service{
Expand Down
4 changes: 2 additions & 2 deletions pkg/mcs/resourcemanager/server/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package install

import (
"github.com/tikv/pd/pkg/mcs/registry"
rm_server "github.com/tikv/pd/pkg/mcs/resourcemanager/server"
"github.com/tikv/pd/pkg/mcs/resourcemanager/server"

// init API group
_ "github.com/tikv/pd/pkg/mcs/resourcemanager/server/apis/v1"
Expand All @@ -28,5 +28,5 @@ func init() {

// Install registers the API group and grpc service.
func Install(register *registry.ServiceRegistry) {
register.RegisterService("ResourceManager", rm_server.NewService[*rm_server.Server])
register.RegisterService("ResourceManager", server.NewService[*server.Server])
}
8 changes: 4 additions & 4 deletions pkg/mcs/resourcemanager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ type Manager struct {
consumptionRecord map[string]time.Time
}

// ResourceManagerConfigProvider is used to get resource manager config from the given
// ConfigProvider is used to get resource manager config from the given
// `bs.server` without modifying its interface.
type ResourceManagerConfigProvider interface {
type ConfigProvider interface {
GetControllerConfig() *ControllerConfig
}

// NewManager returns a new manager base on the given server,
// which should implement the `ResourceManagerConfigProvider` interface.
func NewManager[T ResourceManagerConfigProvider](srv bs.Server) *Manager {
// which should implement the `ConfigProvider` interface.
func NewManager[T ConfigProvider](srv bs.Server) *Manager {
m := &Manager{
controllerConfig: srv.(T).GetControllerConfig(),
groups: make(map[string]*ResourceGroup),
Expand Down
4 changes: 3 additions & 1 deletion pkg/mcs/scheduling/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ func (d dummyRestService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("not implemented"))
}

type ConfigProvider interface{}

// Service is the scheduling grpc service.
type Service struct {
*Server
}

// NewService creates a new TSO service.
func NewService(svr bs.Server) registry.RegistrableService {
func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService {
server, ok := svr.(*Server)
if !ok {
log.Fatal("create scheduling server failed")
Expand Down
32 changes: 32 additions & 0 deletions pkg/mcs/scheduling/server/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 install

import (
"github.com/tikv/pd/pkg/mcs/registry"
"github.com/tikv/pd/pkg/mcs/scheduling/server"

// init API group
_ "github.com/tikv/pd/pkg/mcs/scheduling/server/apis/v1"
)

func init() {
Install(registry.ServerServiceRegistry)
}

// Install registers the API group and grpc service.
func Install(register *registry.ServiceRegistry) {
register.RegisterService("Scheduling", server.NewService[*server.Server])
}
4 changes: 3 additions & 1 deletion pkg/mcs/tso/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ func (d dummyRestService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("not implemented"))
}

type ConfigProvider interface{}

// Service is the TSO grpc service.
type Service struct {
*Server
}

// NewService creates a new TSO service.
func NewService(svr bs.Server) registry.RegistrableService {
func NewService[T ConfigProvider](svr bs.Server) registry.RegistrableService {
server, ok := svr.(*Server)
if !ok {
log.Fatal("create tso server failed")
Expand Down
32 changes: 32 additions & 0 deletions pkg/mcs/tso/server/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 install

import (
"github.com/tikv/pd/pkg/mcs/registry"
"github.com/tikv/pd/pkg/mcs/tso/server"

// init API group
_ "github.com/tikv/pd/pkg/mcs/tso/server/apis/v1"
)

func init() {
Install(registry.ServerServiceRegistry)
}

// Install registers the API group and grpc service.
func Install(register *registry.ServiceRegistry) {
register.RegisterService("Scheduling", server.NewService[*server.Server])
}

0 comments on commit 822af06

Please sign in to comment.