Skip to content

Commit

Permalink
config in compile
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Sep 20, 2023
1 parent 2df55d6 commit 4df65ba
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 33 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ifeq ("$(WITH_RACE)", "1")
BUILD_CGO_ENABLED := 1
endif

ifeq ($(PLUGIN), 1)
BUILD_TAGS += with_plugin
endif

LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDReleaseVersion=$(shell git describe --tags --dirty --always)"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDGitHash=$(shell git rev-parse HEAD)"
Expand Down Expand Up @@ -82,6 +86,9 @@ pd-server-failpoint:
FAILPOINT=1 $(MAKE) pd-server || { $(FAILPOINT_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)

pd-server-plugin:
PLUGIN=1 $(MAKE) pd-server

pd-server-basic:
SWAGGER=0 DASHBOARD=0 $(MAKE) pd-server

Expand Down Expand Up @@ -286,4 +293,4 @@ clean-build:
rm -rf $(BUILD_BIN_PATH)
rm -rf $(GO_TOOLS_BIN_PATH)

.PHONY: clean clean-test clean-build
.PHONY: clean clean-test clean-build
7 changes: 0 additions & 7 deletions pkg/mcs/scheduling/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,6 @@ func (o *PersistConfig) SetHaltScheduling(halt bool, source string) {
o.SetScheduleConfig(v)
}

// SetEnableSchedulePlugin set EnableSchedulePlugin.
func (o *PersistConfig) SetEnableSchedulePlugin(enable bool) {
v := o.GetScheduleConfig().Clone()
v.EnableSchedulePlugin = enable
o.SetScheduleConfig(v)
}

// CheckRegionKeys return error if the smallest region's keys is less than mergeKeys
func (o *PersistConfig) CheckRegionKeys(keys, mergeKeys uint64) error {
return o.GetStoreConfig().CheckRegionKeys(keys, mergeKeys)
Expand Down
8 changes: 0 additions & 8 deletions pkg/schedule/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const (
defaultEnablePlacementRules = true
defaultEnableWitness = false
defaultHaltScheduling = false
defaultEnableSchedulePlugin = false

defaultRegionScoreFormulaVersion = "v2"
defaultLeaderSchedulePolicy = "count"
Expand Down Expand Up @@ -270,9 +269,6 @@ type ScheduleConfig struct {
// HaltScheduling is the option to halt the scheduling. Once it's on, PD will halt the scheduling,
// and any other scheduling configs will be ignored.
HaltScheduling bool `toml:"halt-scheduling" json:"halt-scheduling,string,omitempty"`

// EnableSchedulePlugin is the option to enable plugin.
EnableSchedulePlugin bool `toml:"enable-schedule-plugin" json:"enable-schedule-plugin,string"`
}

// Clone returns a cloned scheduling configuration.
Expand Down Expand Up @@ -371,10 +367,6 @@ func (c *ScheduleConfig) Adjust(meta *configutil.ConfigMetaData, reloading bool)
c.HaltScheduling = defaultHaltScheduling
}

if !meta.IsDefined("enable-schedule-plugin") {
c.EnableSchedulePlugin = defaultEnableSchedulePlugin
}

adjustSchedulers(&c.Schedulers, DefaultSchedulers)

for k, b := range c.migrateConfigurationMap() {
Expand Down
1 change: 0 additions & 1 deletion pkg/schedule/config/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ type SharedConfigProvider interface {
IsWitnessAllowed() bool
IsPlacementRulesCacheEnabled() bool
SetHaltScheduling(bool, string)
SetEnableSchedulePlugin(bool)

// for test purpose
SetPlacementRulesCacheEnabled(bool)
Expand Down
1 change: 0 additions & 1 deletion pkg/utils/configutil/configutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ type SecurityConfig struct {
// RedactInfoLog indicates that whether enabling redact log
RedactInfoLog bool `toml:"redact-info-log" json:"redact-info-log"`
Encryption encryption.Config `toml:"encryption" json:"encryption"`
GrantPlugin bool `toml:"grant-plugin" json:"grant-plugin"`
}

// PrintConfigCheckMsg prints the message about configuration checks.
Expand Down
11 changes: 3 additions & 8 deletions server/api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build with_plugin
// +build with_plugin

package api

import (
Expand Down Expand Up @@ -48,10 +51,6 @@ func newPluginHandler(handler *server.Handler, rd *render.Render) *pluginHandler
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /plugin [post]
func (h *pluginHandler) LoadPlugin(w http.ResponseWriter, r *http.Request) {
if !h.GetScheduleConfig().EnableSchedulePlugin {
h.rd.JSON(w, http.StatusInternalServerError, errors.New("load plugin failed, please enable plugin first"))
return
}
h.processPluginCommand(w, r, schedule.PluginLoad)
}

Expand All @@ -66,10 +65,6 @@ func (h *pluginHandler) LoadPlugin(w http.ResponseWriter, r *http.Request) {
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /plugin [delete]
func (h *pluginHandler) UnloadPlugin(w http.ResponseWriter, r *http.Request) {
if !h.GetScheduleConfig().EnableSchedulePlugin {
h.rd.JSON(w, http.StatusInternalServerError, errors.New("unload plugin failed, please enable plugin first"))
return
}
h.processPluginCommand(w, r, schedule.PluginUnload)
}

Expand Down
41 changes: 41 additions & 0 deletions server/api/plugin_disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

//go:build !with_plugin
// +build !with_plugin

package api

import (
"net/http"

"github.com/tikv/pd/server"
"github.com/unrolled/render"
)

type pluginHandler struct{}

func newPluginHandler(_ *server.Handler, _ *render.Render) *pluginHandler {
return &pluginHandler{}
}

func (h *pluginHandler) LoadPlugin(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
w.Write([]byte("load plugin is disabled, please `make pd-server-plugin` first"))
}

func (h *pluginHandler) UnloadPlugin(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
w.Write([]byte("unload plugin is disabled, please `make pd-server-plugin` first"))
}
7 changes: 0 additions & 7 deletions server/config/persist_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,13 +982,6 @@ func (o *PersistOptions) IsSchedulingHalted() bool {
return o.GetScheduleConfig().HaltScheduling
}

// SetEnableSchedulePlugin to set the option for witness. It's only used to test.
func (o *PersistOptions) SetEnableSchedulePlugin(enable bool) {
v := o.GetScheduleConfig().Clone()
v.EnableSchedulePlugin = enable
o.SetScheduleConfig(v)
}

// GetRegionMaxSize returns the max region size in MB
func (o *PersistOptions) GetRegionMaxSize() uint64 {
return o.GetStoreConfig().GetRegionMaxSize()
Expand Down

0 comments on commit 4df65ba

Please sign in to comment.