From c1ecc9d8c03c557e0fc5adcf0824e5e7860a0622 Mon Sep 17 00:00:00 2001 From: AndreMouche Date: Thu, 27 Jul 2023 14:24:41 -0700 Subject: [PATCH] fix conflicts Signed-off-by: AndreMouche --- go.mod | 5 - go.sum | 7 +- server/api/region.go | 200 ++++---------------------------------- server/api/region_test.go | 4 - 4 files changed, 23 insertions(+), 193 deletions(-) diff --git a/go.mod b/go.mod index 45ea6d79f73..1f014c349a8 100644 --- a/go.mod +++ b/go.mod @@ -114,14 +114,9 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect -<<<<<<< HEAD github.com/leodido/go-urn v1.2.0 // indirect - github.com/mailru/easyjson v0.7.6 // indirect -======= - github.com/leodido/go-urn v1.2.1 // indirect github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect github.com/mailru/easyjson v0.7.6 ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-isatty v0.0.12 // indirect github.com/mattn/go-runewidth v0.0.8 // indirect diff --git a/go.sum b/go.sum index a0587f98dcd..940c431ad6b 100644 --- a/go.sum +++ b/go.sum @@ -216,8 +216,9 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20211122183932-1daafda22083 h1:c8EUapQFi+kjzedr4c6WqbwMdmB95+oDBWZ5XFHFYxY= github.com/google/pprof v0.0.0-20211122183932-1daafda22083/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= @@ -306,6 +307,9 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -715,7 +719,6 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= diff --git a/server/api/region.go b/server/api/region.go index 726ef715a84..5d03f404e81 100644 --- a/server/api/region.go +++ b/server/api/region.go @@ -388,12 +388,7 @@ func marshalRegionsInfoJSON(ctx context.Context, regions []*core.RegionInfo) ([] func (h *regionsHandler) GetRegions(w http.ResponseWriter, r *http.Request) { rc := getCluster(r) regions := rc.GetRegions() - b, err := marshalRegionsInfoJSON(r.Context(), regions) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - h.rd.Data(w, http.StatusOK, b) + h.returnWithRegions(w, r, regions) } // @Tags region @@ -423,12 +418,7 @@ func (h *regionsHandler) ScanRegions(w http.ResponseWriter, r *http.Request) { limit = maxRegionLimit } regions := rc.ScanRegions([]byte(startKey), []byte(endKey), limit) - b, err := marshalRegionsInfoJSON(r.Context(), regions) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - h.rd.Data(w, http.StatusOK, b) + h.returnWithRegions(w, r, regions) } // @Tags region @@ -459,103 +449,19 @@ func (h *regionsHandler) GetStoreRegions(w http.ResponseWriter, r *http.Request) return } regions := rc.GetStoreRegions(uint64(id)) - b, err := marshalRegionsInfoJSON(r.Context(), regions) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - h.rd.Data(w, http.StatusOK, b) + h.returnWithRegions(w, r, regions) } // @Tags region -<<<<<<< HEAD -======= -// @Summary List regions belongs to the given keyspace ID. -// @Param keyspace_id query string true "Keyspace ID" -// @Param limit query integer false "Limit count" default(16) -// @Produce json -// @Success 200 {object} RegionsInfo -// @Failure 400 {string} string "The input is invalid." -// @Router /regions/keyspace/id/{id} [get] -func (h *regionsHandler) GetKeyspaceRegions(w http.ResponseWriter, r *http.Request) { - rc := getCluster(r) - vars := mux.Vars(r) - keyspaceIDStr := vars["id"] - if keyspaceIDStr == "" { - h.rd.JSON(w, http.StatusBadRequest, "keyspace id is empty") - return - } - - keyspaceID64, err := strconv.ParseUint(keyspaceIDStr, 10, 32) - if err != nil { - h.rd.JSON(w, http.StatusBadRequest, err.Error()) - return - } - keyspaceID := uint32(keyspaceID64) - keyspaceManager := h.svr.GetKeyspaceManager() - if _, err := keyspaceManager.LoadKeyspaceByID(keyspaceID); err != nil { - h.rd.JSON(w, http.StatusBadRequest, err.Error()) - return - } - - limit := defaultRegionLimit - if limitStr := r.URL.Query().Get("limit"); limitStr != "" { - limit, err = strconv.Atoi(limitStr) - if err != nil { - h.rd.JSON(w, http.StatusBadRequest, err.Error()) - return - } - } - if limit > maxRegionLimit { - limit = maxRegionLimit - } - regionBound := keyspace.MakeRegionBound(keyspaceID) - regions := rc.ScanRegions(regionBound.RawLeftBound, regionBound.RawRightBound, limit) - if limit <= 0 || limit > len(regions) { - txnRegion := rc.ScanRegions(regionBound.TxnLeftBound, regionBound.TxnRightBound, limit-len(regions)) - regions = append(regions, txnRegion...) - } - b, err := marshalRegionsInfoJSON(r.Context(), regions) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - h.rd.Data(w, http.StatusOK, b) -} - -// @Tags region ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) // @Summary List all regions that miss peer. // @Produce json // @Success 200 {object} RegionsInfo // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/miss-peer [get] func (h *regionsHandler) GetMissPeerRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD -======= h.getRegionsByType(w, statistics.MissPeer, r) } -func (h *regionsHandler) getRegionsByType( - w http.ResponseWriter, - typ statistics.RegionStatisticType, - r *http.Request, -) { ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.MissPeer) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - b, err := marshalRegionsInfoJSON(r.Context(), regions) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - h.rd.Data(w, http.StatusOK, b) -} - // @Tags region // @Summary List all regions that has extra peer. // @Produce json @@ -563,18 +469,7 @@ func (h *regionsHandler) getRegionsByType( // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/extra-peer [get] func (h *regionsHandler) GetExtraPeerRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.ExtraPeer) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= h.getRegionsByType(w, statistics.ExtraPeer, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) } // @Tags region @@ -584,18 +479,7 @@ func (h *regionsHandler) GetExtraPeerRegions(w http.ResponseWriter, r *http.Requ // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/pending-peer [get] func (h *regionsHandler) GetPendingPeerRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.PendingPeer) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= h.getRegionsByType(w, statistics.PendingPeer, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) } // @Tags region @@ -605,18 +489,7 @@ func (h *regionsHandler) GetPendingPeerRegions(w http.ResponseWriter, r *http.Re // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/down-peer [get] func (h *regionsHandler) GetDownPeerRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.DownPeer) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= h.getRegionsByType(w, statistics.DownPeer, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) } // @Tags region @@ -626,18 +499,7 @@ func (h *regionsHandler) GetDownPeerRegions(w http.ResponseWriter, r *http.Reque // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/learner-peer [get] func (h *regionsHandler) GetLearnerPeerRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.LearnerPeer) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= h.getRegionsByType(w, statistics.LearnerPeer, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) } // @Tags region @@ -647,18 +509,7 @@ func (h *regionsHandler) GetLearnerPeerRegions(w http.ResponseWriter, r *http.Re // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/offline-peer [get] func (h *regionsHandler) GetOfflinePeerRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetOfflinePeer(statistics.OfflinePeer) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= h.getRegionsByType(w, statistics.OfflinePeer, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) } // @Tags region @@ -668,18 +519,7 @@ func (h *regionsHandler) GetOfflinePeerRegions(w http.ResponseWriter, r *http.Re // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/oversized-region [get] func (h *regionsHandler) GetOverSizedRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.OversizedRegion) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= h.getRegionsByType(w, statistics.OversizedRegion, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) } // @Tags region @@ -689,18 +529,7 @@ func (h *regionsHandler) GetOverSizedRegions(w http.ResponseWriter, r *http.Requ // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/undersized-region [get] func (h *regionsHandler) GetUndersizedRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.UndersizedRegion) - if err != nil { - h.rd.JSON(w, http.StatusInternalServerError, err.Error()) - return - } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= h.getRegionsByType(w, statistics.UndersizedRegion, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) } // @Tags region @@ -710,18 +539,25 @@ func (h *regionsHandler) GetUndersizedRegions(w http.ResponseWriter, r *http.Req // @Failure 500 {string} string "PD server failed to proceed the request." // @Router /regions/check/empty-region [get] func (h *regionsHandler) GetEmptyRegions(w http.ResponseWriter, r *http.Request) { -<<<<<<< HEAD - handler := h.svr.GetHandler() - regions, err := handler.GetRegionsByType(statistics.EmptyRegion) + h.getRegionsByType(w, statistics.EmptyRegion, r) + +} + +func (h *regionsHandler) getRegionsByType(w http.ResponseWriter, t statistics.RegionStatisticType, r *http.Request) { + regions, err := h.svr.GetHandler().GetRegionsByType(t) if err != nil { h.rd.JSON(w, http.StatusInternalServerError, err.Error()) return } - regionsInfo := convertToAPIRegions(regions) - h.rd.JSON(w, http.StatusOK, regionsInfo) -======= - h.getRegionsByType(w, statistics.EmptyRegion, r) ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) + h.returnWithRegions(w, r, regions) +} + +func (h *regionsHandler) returnWithRegions(w http.ResponseWriter, r *http.Request, regions []*core.RegionInfo) { + b, err := marshalRegionsInfoJSON(r.Context(), regions) + if err != nil { + h.rd.JSON(w, http.StatusInternalServerError, err.Error()) + } + h.rd.Data(w, http.StatusOK, b) } type histItem struct { diff --git a/server/api/region_test.go b/server/api/region_test.go index 1b3f743a6ea..9cf804c7d74 100644 --- a/server/api/region_test.go +++ b/server/api/region_test.go @@ -33,14 +33,10 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" -<<<<<<< HEAD - tu "github.com/tikv/pd/pkg/testutil" -======= "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/placement" "github.com/tikv/pd/pkg/utils/apiutil" tu "github.com/tikv/pd/pkg/utils/testutil" ->>>>>>> 4db173597 (api: use easyjson and context in regions interface (#6838)) "github.com/tikv/pd/server" "github.com/tikv/pd/server/core" "github.com/tikv/pd/server/schedule/placement"