Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: check raftcluster nil #7054

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions server/api/min_resolved_ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"strings"

"github.com/gorilla/mux"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/utils/typeutil"
"github.com/tikv/pd/server"
"github.com/unrolled/render"
Expand Down Expand Up @@ -54,6 +55,10 @@
// @Router /min-resolved-ts/{store_id} [get]
func (h *minResolvedTSHandler) GetStoreMinResolvedTS(w http.ResponseWriter, r *http.Request) {
c := h.svr.GetRaftCluster()
if c == nil {
h.rd.JSON(w, http.StatusInternalServerError, errs.ErrNotBootstrapped.FastGenByArgs().Error())
return

Check warning on line 60 in server/api/min_resolved_ts.go

View check run for this annotation

Codecov / codecov/patch

server/api/min_resolved_ts.go#L58-L60

Added lines #L58 - L60 were not covered by tests
}
idStr := mux.Vars(r)["store_id"]
storeID, err := strconv.ParseUint(idStr, 10, 64)
if err != nil {
Expand Down Expand Up @@ -85,6 +90,10 @@
// @Router /min-resolved-ts [get]
func (h *minResolvedTSHandler) GetMinResolvedTS(w http.ResponseWriter, r *http.Request) {
c := h.svr.GetRaftCluster()
if c == nil {
h.rd.JSON(w, http.StatusInternalServerError, errs.ErrNotBootstrapped.FastGenByArgs().Error())
return

Check warning on line 95 in server/api/min_resolved_ts.go

View check run for this annotation

Codecov / codecov/patch

server/api/min_resolved_ts.go#L94-L95

Added lines #L94 - L95 were not covered by tests
}
scopeMinResolvedTS := c.GetMinResolvedTS()
persistInterval := c.GetPDServerConfig().MinResolvedTSPersistenceInterval

Expand Down
4 changes: 4 additions & 0 deletions server/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@
// @Router /store/{id}/limit [post]
func (h *storeHandler) SetStoreLimit(w http.ResponseWriter, r *http.Request) {
rc := getCluster(r)
if rc == nil {
h.rd.JSON(w, http.StatusInternalServerError, errs.ErrNotBootstrapped.GenWithStackByArgs().Error())
return

Check warning on line 433 in server/api/store.go

View check run for this annotation

Codecov / codecov/patch

server/api/store.go#L432-L433

Added lines #L432 - L433 were not covered by tests
}
vars := mux.Vars(r)
storeID, errParse := apiutil.ParseUint64VarsField(vars, "id")
if errParse != nil {
Expand Down
4 changes: 3 additions & 1 deletion server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,6 @@
if rc == nil {
return &pdpb.ReportBatchSplitResponse{Header: s.notBootstrappedHeader()}, nil
}

_, err := rc.HandleBatchReportSplit(request)
if err != nil {
return &pdpb.ReportBatchSplitResponse{
Expand Down Expand Up @@ -2089,6 +2088,9 @@
return rsp.(*pdpb.SplitAndScatterRegionsResponse), err
}
rc := s.GetRaftCluster()
if rc == nil {
return &pdpb.SplitAndScatterRegionsResponse{Header: s.notBootstrappedHeader()}, nil

Check warning on line 2092 in server/grpc_service.go

View check run for this annotation

Codecov / codecov/patch

server/grpc_service.go#L2091-L2092

Added lines #L2091 - L2092 were not covered by tests
}
splitFinishedPercentage, newRegionIDs := rc.GetRegionSplitter().SplitRegions(ctx, request.GetSplitKeys(), int(request.GetRetryLimit()))
scatterFinishedPercentage, err := scatterRegions(rc, newRegionIDs, request.GetGroup(), int(request.GetRetryLimit()), false)
if err != nil {
Expand Down
92 changes: 85 additions & 7 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
if err != nil {
return false, err
}
if rc == nil {
return false, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 118 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L118

Added line #L118 was not covered by tests
}
return rc.GetCoordinator().GetSchedulersController().IsSchedulerPaused(name)
}

Expand All @@ -123,6 +126,9 @@
if err != nil {
return false, err
}
if rc == nil {
return false, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 130 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L130

Added line #L130 was not covered by tests
}
return rc.GetCoordinator().GetSchedulersController().IsSchedulerDisabled(name)
}

Expand All @@ -132,6 +138,9 @@
if err != nil {
return false, err
}
if rc == nil {
return false, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 142 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L142

Added line #L142 was not covered by tests
}
return rc.GetCoordinator().GetSchedulersController().IsSchedulerExisted(name)
}

Expand All @@ -146,6 +155,9 @@
if err != nil {
return nil, err
}
if c == nil {
return nil, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 159 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L159

Added line #L159 was not covered by tests
}
return c.GetSchedulers(), nil
}

Expand All @@ -155,6 +167,9 @@
if err != nil {
return false, err
}
if rc == nil {
return false, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 171 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L171

Added line #L171 was not covered by tests
}
return rc.GetCoordinator().IsCheckerPaused(name)
}

Expand All @@ -180,7 +195,7 @@
// GetHotWriteRegions gets all hot write regions stats.
func (h *Handler) GetHotWriteRegions() *statistics.StoreHotPeersInfos {
c, err := h.GetRaftCluster()
if err != nil {
if err != nil || c == nil {
return nil
}
return c.GetHotWriteRegions()
Expand All @@ -189,7 +204,7 @@
// GetHotBuckets returns all hot buckets stats.
func (h *Handler) GetHotBuckets(regionIDs ...uint64) map[uint64][]*buckets.BucketStat {
c, err := h.GetRaftCluster()
if err != nil {
if err != nil || c == nil {
return nil
}
degree := c.GetOpts().GetHotRegionCacheHitsThreshold()
Expand All @@ -199,7 +214,7 @@
// GetHotReadRegions gets all hot read regions stats.
func (h *Handler) GetHotReadRegions() *statistics.StoreHotPeersInfos {
c, err := h.GetRaftCluster()
if err != nil {
if err != nil || c == nil {
return nil
}
return c.GetHotReadRegions()
Expand Down Expand Up @@ -230,6 +245,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 249 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L249

Added line #L249 was not covered by tests
}

s, err := schedulers.CreateScheduler(name, c.GetOperatorController(), h.s.storage, schedulers.ConfigSliceDecoder(name, args), c.GetCoordinator().GetSchedulersController().RemoveScheduler)
if err != nil {
Expand Down Expand Up @@ -258,6 +276,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 280 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L280

Added line #L280 was not covered by tests
}
if !h.s.IsAPIServiceMode() {
if err = c.RemoveScheduler(name); err != nil {
log.Error("can not remove scheduler", zap.String("scheduler-name", name), errs.ZapError(err))
Expand Down Expand Up @@ -288,6 +309,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 313 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L313

Added line #L313 was not covered by tests
}
if err = c.PauseOrResumeScheduler(name, t); err != nil {
if t == 0 {
log.Error("can not resume scheduler", zap.String("scheduler-name", name), errs.ZapError(err))
Expand All @@ -312,6 +336,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 340 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L340

Added line #L340 was not covered by tests
}
if err = c.PauseOrResumeChecker(name, t); err != nil {
if t == 0 {
log.Error("can not resume checker", zap.String("checker-name", name), errs.ZapError(err))
Expand Down Expand Up @@ -526,6 +553,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 557 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L557

Added line #L557 was not covered by tests
}
return c.SetAllStoresLimit(limitType, ratePerMin)
}

Expand All @@ -535,6 +565,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 569 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L569

Added line #L569 was not covered by tests
}
c.SetAllStoresLimitTTL(limitType, ratePerMin, ttl)
return nil
}
Expand All @@ -545,6 +578,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 582 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L582

Added line #L582 was not covered by tests
}
for _, store := range c.GetStores() {
for _, label := range labels {
for _, sl := range store.GetLabels() {
Expand All @@ -564,6 +600,9 @@
if err != nil {
return nil, err
}
if c == nil {
return nil, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 604 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L603-L604

Added lines #L603 - L604 were not covered by tests
}
return c.GetAllStoresLimit(), nil
}

Expand All @@ -573,6 +612,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 616 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L616

Added line #L616 was not covered by tests
}
return c.SetStoreLimit(storeID, limitType, ratePerMin)
}

Expand All @@ -582,6 +624,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 628 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L628

Added line #L628 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -610,6 +655,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 659 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L659

Added line #L659 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -654,6 +702,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 706 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L706

Added line #L706 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -687,6 +738,9 @@
if err != nil {
return nil, nil, err
}
if c == nil {
return nil, nil, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 742 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L742

Added line #L742 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -752,6 +806,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 810 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L810

Added line #L810 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -779,6 +836,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 840 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L840

Added line #L840 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -821,6 +881,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 885 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L885

Added line #L885 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -860,6 +923,9 @@
if err != nil {
return err
}
if c == nil {
return errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 927 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L927

Added line #L927 was not covered by tests
}

region := c.GetRegion(regionID)
if region == nil {
Expand Down Expand Up @@ -890,6 +956,9 @@
if err != nil {
return 0, err
}
if c == nil {
return 0, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 960 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L959-L960

Added lines #L959 - L960 were not covered by tests
}
opsCount := 0
var failures map[uint64]error
// If startKey and endKey are both defined, use them first.
Expand Down Expand Up @@ -934,6 +1003,9 @@
if err != nil {
return nil, err
}
if c == nil {
return nil, errs.ErrNotBootstrapped.GenWithStackByArgs()

Check warning on line 1007 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L1007

Added line #L1007 was not covered by tests
}
mux := http.NewServeMux()
for name, handler := range c.GetSchedulerHandlers() {
prefix := path.Join(pdRootPath, SchedulerConfigHandlerPath, name)
Expand Down Expand Up @@ -961,14 +1033,20 @@

// SetStoreLimitScene sets the limit values for different scenes
func (h *Handler) SetStoreLimitScene(scene *storelimit.Scene, limitType storelimit.Type) {
cluster := h.s.GetRaftCluster()
cluster.GetStoreLimiter().ReplaceStoreLimitScene(scene, limitType)
rc := h.s.GetRaftCluster()
if rc == nil {
return

Check warning on line 1038 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L1038

Added line #L1038 was not covered by tests
}
rc.GetStoreLimiter().ReplaceStoreLimitScene(scene, limitType)
}

// GetStoreLimitScene returns the limit values for different scenes
func (h *Handler) GetStoreLimitScene(limitType storelimit.Type) *storelimit.Scene {
cluster := h.s.GetRaftCluster()
return cluster.GetStoreLimiter().StoreLimitScene(limitType)
rc := h.s.GetRaftCluster()
if rc == nil {
return nil

Check warning on line 1047 in server/handler.go

View check run for this annotation

Codecov / codecov/patch

server/handler.go#L1047

Added line #L1047 was not covered by tests
}
return rc.GetStoreLimiter().StoreLimitScene(limitType)
}

// GetProgressByID returns the progress details for a given store ID.
Expand Down
Loading
Loading