Skip to content

Commit

Permalink
Merge branch 'master' into label-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
HunDunDM authored Mar 12, 2021
2 parents d51ef57 + 2cf8161 commit 5d52a62
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Fetch Go module
run: |
go mod download
DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap-incubator/tidb-dashboard)
DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap/tidb-dashboard)
DASHBOARD_RELEASE_VERSION=$(grep -v '^#' "${DASHBOARD_DIR}/release-version")
echo DASHBOARD_DIR="$DASHBOARD_DIR" >> $GITHUB_ENV
echo DASHBOARD_RELEASE_VERSION="$DASHBOARD_RELEASE_VERSION" >> $GITHUB_ENV
Expand All @@ -42,7 +42,7 @@ jobs:
rm -rf /tmp/dashboard
mkdir -p /tmp/dashboard
cd /tmp/dashboard
DOWNLOAD_URL="https://github.com/pingcap-incubator/tidb-dashboard/archive/v${DASHBOARD_RELEASE_VERSION}.zip"
DOWNLOAD_URL="https://github.com/pingcap/tidb-dashboard/archive/v${DASHBOARD_RELEASE_VERSION}.zip"
curl -L "${DOWNLOAD_URL}" --fail --output source.zip
unzip source.zip
- name: Check diff
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ LDFLAGS += -X "$(PD_PKG)/server/versioninfo.PDEdition=$(PD_EDITION)"

ifneq ($(DASHBOARD), 0)
# Note: LDFLAGS must be evaluated lazily for these scripts to work correctly
LDFLAGS += -X "github.com/pingcap-incubator/tidb-dashboard/pkg/utils/version.InternalVersion=$(shell scripts/describe-dashboard.sh internal-version)"
LDFLAGS += -X "github.com/pingcap-incubator/tidb-dashboard/pkg/utils/version.Standalone=No"
LDFLAGS += -X "github.com/pingcap-incubator/tidb-dashboard/pkg/utils/version.PDVersion=$(shell git describe --tags --dirty --always)"
LDFLAGS += -X "github.com/pingcap-incubator/tidb-dashboard/pkg/utils/version.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "github.com/pingcap-incubator/tidb-dashboard/pkg/utils/version.BuildGitHash=$(shell scripts/describe-dashboard.sh git-hash)"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.InternalVersion=$(shell scripts/describe-dashboard.sh internal-version)"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.Standalone=No"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.PDVersion=$(shell git describe --tags --dirty --always)"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "github.com/pingcap/tidb-dashboard/pkg/utils/version.BuildGitHash=$(shell scripts/describe-dashboard.sh git-hash)"
endif

GOVER_MAJOR := $(shell go version | sed -E -e "s/.*go([0-9]+)[.]([0-9]+).*/\1/")
Expand Down Expand Up @@ -117,7 +117,7 @@ install-go-tools:
swagger-spec: export GO111MODULE=on
swagger-spec: install-go-tools
go mod vendor
swag init --parseVendor -generalInfo server/api/router.go --exclude vendor/github.com/pingcap-incubator/tidb-dashboard --output docs/swagger
swag init --parseVendor -generalInfo server/api/router.go --exclude vendor/github.com/pingcap/tidb-dashboard --output docs/swagger
go mod tidy
rm -rf vendor

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ require (
github.com/opentracing/opentracing-go v1.1.0
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20210104140916-41a0a3a87e75
github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712
github.com/pingcap/errcode v0.3.0
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3
github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce
github.com/pingcap/kvproto v0.0.0-20210219064844-c1844a4775d6
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99
github.com/pingcap/tidb-dashboard v0.0.0-20210312062513-eef5d6404638
github.com/prometheus/client_golang v1.2.1
github.com/prometheus/common v0.9.1
github.com/sasha-s/go-deadlock v0.2.0
Expand Down
9 changes: 3 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,6 @@ github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g=
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d/go.mod h1:lXfE4PvvTW5xOjO6Mba8zDPyw8M93B6AQ7frTGnMlA8=
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20210104140916-41a0a3a87e75 h1:XJ/OVqPtHuGNLgCu6xgSlCouz5roe3Yf3TXHjVNf+9w=
github.com/pingcap-incubator/tidb-dashboard v0.0.0-20210104140916-41a0a3a87e75/go.mod h1:EONGys2gM5n14pII2vjmU/5VG3Dtj6kpqUT1GUZ4ysw=
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ=
github.com/pingcap/check v0.0.0-20191107115940-caf2b9e6ccf4/go.mod h1:PYMCGwN0JHjoqGr3HrZoD+b8Tgx8bKnArhSq8YVzUMc=
github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12/go.mod h1:PYMCGwN0JHjoqGr3HrZoD+b8Tgx8bKnArhSq8YVzUMc=
Expand All @@ -320,6 +318,7 @@ github.com/pingcap/errcode v0.3.0/go.mod h1:4b2X8xSqxIroj/IZ9MX/VGZhAwc11wB9wRIz
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pingcap/errors v0.11.5-0.20200917111840-a15ef68f753d/go.mod h1:g4vx//d6VakjJ0mk7iLBlKA8LFavV/sAVINT/1PFxeQ=
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3 h1:LllgC9eGfqzkfubMgjKIDyZYaa609nNWAyNZtpy2B3M=
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3/go.mod h1:G7x87le1poQzLB/TqvTJI2ILrSgobnq4Ut7luOwvfvI=
github.com/pingcap/failpoint v0.0.0-20191029060244-12f4ac2fd11d/go.mod h1:DNS3Qg7bEDhU6EXNHF+XSv/PGznQaMJ5FWvctpm6pQI=
Expand All @@ -330,13 +329,14 @@ github.com/pingcap/kvproto v0.0.0-20200411081810-b85805c9476c/go.mod h1:IOdRDPLy
github.com/pingcap/kvproto v0.0.0-20210219064844-c1844a4775d6 h1:lNGXD00uNXOKMM2pnTe9XvUv3IOEOtFhqNQljlTDZKc=
github.com/pingcap/kvproto v0.0.0-20210219064844-c1844a4775d6/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI=
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20200117041106-d28c14d3b1cd/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20200511115504-543df19646ad/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8 h1:M+DNpOu/I3uDmwee6vcnoPd6GgSMqND4gxvDQ/W584U=
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99 h1:/ogXgm4guJzow4UafiyXZ6ciAIPzxImaXYiFvTpKzKY=
github.com/pingcap/sysutil v0.0.0-20210221112134-a07bda3bde99/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/tidb-dashboard v0.0.0-20210312062513-eef5d6404638 h1:348LTgzsZmaOobmgxNBX2TryRWyijwyXsGb8gvrH+iw=
github.com/pingcap/tidb-dashboard v0.0.0-20210312062513-eef5d6404638/go.mod h1:OzFN8H0EDMMqeulPhPMw2i2JaiZWOKFQ7zdRPhENNgo=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -489,7 +489,6 @@ go.uber.org/zap v1.8.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.12.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -630,8 +629,6 @@ gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvR
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/oleiade/reflections.v1 v1.0.0 h1:nV9NFaFd5bXKjilVvPvA+/V/tNQk1pOEEc9gGWDkj+s=
gopkg.in/oleiade/reflections.v1 v1.0.0/go.mod h1:SpA8pv+LUnF0FbB2hyRxc8XSng78D6iLBZ11PDb8Z5g=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/adapter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package adapter

import (
"github.com/pingcap-incubator/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/config"

"github.com/tikv/pd/server"
)
Expand Down
10 changes: 7 additions & 3 deletions pkg/dashboard/adapter/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"sync"
"time"

"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/tidb-dashboard/pkg/apiserver"

"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
Expand Down Expand Up @@ -97,7 +97,9 @@ func (m *Manager) updateInfo() {
if !m.srv.GetMember().IsLeader() {
m.isLeader = false
m.members = nil
m.srv.GetPersistOptions().Reload(m.srv.GetStorage())
if err := m.srv.GetPersistOptions().Reload(m.srv.GetStorage()); err != nil {
log.Warn("failed to reload persist options")
}
return
}

Expand Down Expand Up @@ -187,7 +189,9 @@ func (m *Manager) setNewAddress() {
// set new dashboard address
cfg := m.srv.GetPersistOptions().GetPDServerConfig().Clone()
cfg.DashboardAddress = addr
m.srv.SetPDServerConfig(*cfg)
if err := m.srv.SetPDServerConfig(*cfg); err != nil {
log.Warn("failed to set persist options")
}
}

func (m *Manager) startService() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/dashboard/adapter/redirector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"net/url"
"sync"

"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver"
"github.com/pingcap-incubator/tidb-dashboard/pkg/utils"
"github.com/pingcap/tidb-dashboard/pkg/apiserver"
"github.com/pingcap/tidb-dashboard/pkg/utils"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"net/http"
"time"

"github.com/pingcap-incubator/tidb-dashboard/pkg/apiserver"
"github.com/pingcap-incubator/tidb-dashboard/pkg/config"
"github.com/pingcap-incubator/tidb-dashboard/pkg/uiserver"
"github.com/pingcap/tidb-dashboard/pkg/apiserver"
"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/uiserver"

"github.com/tikv/pd/pkg/dashboard/adapter"
"github.com/tikv/pd/pkg/dashboard/keyvisual"
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/keyvisual/input/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package input

import (
regionpkg "github.com/pingcap-incubator/tidb-dashboard/pkg/keyvisual/region"
"github.com/pingcap/log"
regionpkg "github.com/pingcap/tidb-dashboard/pkg/keyvisual/region"
"github.com/tikv/pd/server"
"github.com/tikv/pd/server/core"
"go.uber.org/zap"
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/keyvisual/keyvisual.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package keyvisual

import (
"github.com/pingcap-incubator/tidb-dashboard/pkg/keyvisual/region"
"github.com/pingcap/tidb-dashboard/pkg/keyvisual/region"

"github.com/tikv/pd/pkg/dashboard/keyvisual/input"
"github.com/tikv/pd/server"
Expand Down
4 changes: 2 additions & 2 deletions pkg/dashboard/uiserver/embedded_assets_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"sync"
"time"

"github.com/pingcap-incubator/tidb-dashboard/pkg/config"
"github.com/pingcap-incubator/tidb-dashboard/pkg/uiserver"
"github.com/pingcap/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/uiserver"
)

var once sync.Once
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/without_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"net/http"
"time"

"github.com/pingcap-incubator/tidb-dashboard/pkg/config"
"github.com/pingcap/tidb-dashboard/pkg/config"

"github.com/tikv/pd/server"
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ "${DASHBOARD-}" == "0" ]; then
exit 0
fi

DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap-incubator/tidb-dashboard)
DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap/tidb-dashboard)

if [ "$1" = "git-hash" ]; then
echo "${DASHBOARD_DIR}" | awk -F- '{print $NF}'
Expand Down
4 changes: 2 additions & 2 deletions scripts/embed-dashboard-ui.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go mod download

echo '+ Discover TiDB Dashboard release version'

$DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap-incubator/tidb-dashboard)
$DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap/tidb-dashboard)
echo " - Dashboard directory: $DASHBOARD_DIR"

$DASHBOARD_RELEASE_VERSION= cat "${DASHBOARD_DIR}/release-version" | Select-String -Pattern "^#" -NotMatch
Expand All @@ -26,7 +26,7 @@ if (Test-Path "$CACHE_FILE" ){
else{
echo ' - Cached archive does not exist'
echo ' - Download pre-built embedded assets from GitHub release'
$DOWNLOAD_URL="https://github.com/pingcap-incubator/tidb-dashboard/releases/download/v${DASHBOARD_RELEASE_VERSION}/embedded-assets-golang.zip"
$DOWNLOAD_URL="https://github.com/pingcap/tidb-dashboard/releases/download/v${DASHBOARD_RELEASE_VERSION}/embedded-assets-golang.zip"
$DOWNLOAD_FILE= Join-Path($CACHE_DIR) \embedded-assets-golang.zip
echo " - Download ${DOWNLOAD_URL}"
Invoke-WebRequest -Uri "${DOWNLOAD_URL}" -OutFile "${DOWNLOAD_FILE}"
Expand Down
4 changes: 2 additions & 2 deletions scripts/embed-dashboard-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rm -f ASSET_DEST_PATH

echo '+ Fetch TiDB Dashboard Go module'
go mod download
DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap-incubator/tidb-dashboard)
DASHBOARD_DIR=$(go list -f "{{.Dir}}" -m github.com/pingcap/tidb-dashboard)
echo " - TiDB Dashboard directory: ${DASHBOARD_DIR}"


Expand All @@ -47,7 +47,7 @@ function download_embed_asset {
echo ' - Cached archive does not exist'
echo ' - Download pre-built embedded assets from GitHub release'

DOWNLOAD_URL="https://github.com/pingcap-incubator/tidb-dashboard/releases/download/v${DASHBOARD_RELEASE_VERSION}/embedded-assets-golang.zip"
DOWNLOAD_URL="https://github.com/pingcap/tidb-dashboard/releases/download/v${DASHBOARD_RELEASE_VERSION}/embedded-assets-golang.zip"
DOWNLOAD_FILE=${CACHE_DIR}/embedded-assets-golang.zip
echo " - Download ${DOWNLOAD_URL}"
if ! curl -L "${DOWNLOAD_URL}" --fail --output "${DOWNLOAD_FILE}"; then
Expand Down
10 changes: 6 additions & 4 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,13 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
}
saveCache, needSync = true, true
}
if len(region.GetDownPeers()) > 0 || len(region.GetPendingPeers()) > 0 {
saveCache = true
if !core.SortedPeersStatsEqual(region.GetDownPeers(), origin.GetDownPeers()) {
log.Debug("down-peers changed", zap.Uint64("region-id", region.GetID()))
saveCache, needSync = true, true
}
if len(origin.GetDownPeers()) > 0 || len(origin.GetPendingPeers()) > 0 {
saveCache = true
if !core.SortedPeersEqual(region.GetPendingPeers(), origin.GetPendingPeers()) {
log.Debug("pending-peers changed", zap.Uint64("region-id", region.GetID()))
saveCache, needSync = true, true
}
if len(region.GetPeers()) != len(origin.GetPeers()) {
saveKV, saveCache = true, true
Expand Down
65 changes: 61 additions & 4 deletions server/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

// errRegionIsStale is error info for region is stale.
var errRegionIsStale = func(region *metapb.Region, origin *metapb.Region) error {
func errRegionIsStale(region *metapb.Region, origin *metapb.Region) error {
return errors.Errorf("region is stale: region %v origin %v", region, origin)
}

Expand Down Expand Up @@ -83,9 +83,16 @@ func classifyVoterAndLearner(region *RegionInfo) {
region.voters = voters
}

// EmptyRegionApproximateSize is the region approximate size of an empty region
// (heartbeat size <= 1MB).
const EmptyRegionApproximateSize = 1
const (
// EmptyRegionApproximateSize is the region approximate size of an empty region
// (heartbeat size <= 1MB).
EmptyRegionApproximateSize = 1
// ImpossibleFlowSize is an impossible flow size (such as written_bytes, read_keys, etc.)
// It may be caused by overflow, refer to https://github.com/tikv/pd/issues/3379.
// They need to be filtered so as not to affect downstream.
// (flow size >= 1024TB)
ImpossibleFlowSize = 1 << 50
)

// RegionFromHeartbeat constructs a Region from region heartbeat.
func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest) *RegionInfo {
Expand All @@ -112,6 +119,18 @@ func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest) *RegionInfo {
replicationStatus: heartbeat.GetReplicationStatus(),
}

if region.writtenKeys >= ImpossibleFlowSize || region.writtenBytes >= ImpossibleFlowSize {
region.writtenKeys = 0
region.writtenBytes = 0
}
if region.readKeys >= ImpossibleFlowSize || region.readBytes >= ImpossibleFlowSize {
region.readKeys = 0
region.readBytes = 0
}

sort.Sort(peerStatsSlice(region.downPeers))
sort.Sort(peerSlice(region.pendingPeers))

classifyVoterAndLearner(region)
return region
}
Expand Down Expand Up @@ -729,6 +748,44 @@ func (s peerSlice) Less(i, j int) bool {
return s[i].GetId() < s[j].GetId()
}

// SortedPeersEqual judges whether two sorted `peerSlice` are equal
func SortedPeersEqual(peersA, peersB []*metapb.Peer) bool {
if len(peersA) != len(peersB) {
return false
}
for i, peer := range peersA {
if peer.GetId() != peersB[i].GetId() {
return false
}
}
return true
}

type peerStatsSlice []*pdpb.PeerStats

func (s peerStatsSlice) Len() int {
return len(s)
}
func (s peerStatsSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s peerStatsSlice) Less(i, j int) bool {
return s[i].GetPeer().GetId() < s[j].GetPeer().GetId()
}

// SortedPeersStatsEqual judges whether two sorted `peerStatsSlice` are equal
func SortedPeersStatsEqual(peersA, peersB []*pdpb.PeerStats) bool {
if len(peersA) != len(peersB) {
return false
}
for i, peerStats := range peersA {
if peerStats.GetPeer().GetId() != peersB[i].GetPeer().GetId() {
return false
}
}
return true
}

// shouldRemoveFromSubTree return true when the region leader changed, peer transferred,
// new peer was created, learners changed, pendingPeers changed, and so on.
func (r *RegionsInfo) shouldRemoveFromSubTree(region *RegionInfo, origin *RegionInfo) bool {
Expand Down
8 changes: 6 additions & 2 deletions server/core/region_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package core

import (
"sort"

"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/kvproto/pkg/replication_modepb"
Expand All @@ -28,14 +30,16 @@ type RegionCreateOption func(region *RegionInfo)
// WithDownPeers sets the down peers for the region.
func WithDownPeers(downPeers []*pdpb.PeerStats) RegionCreateOption {
return func(region *RegionInfo) {
region.downPeers = downPeers
region.downPeers = append(downPeers[:0:0], downPeers...)
sort.Sort(peerStatsSlice(region.downPeers))
}
}

// WithPendingPeers sets the pending peers for the region.
func WithPendingPeers(pendingPeers []*metapb.Peer) RegionCreateOption {
return func(region *RegionInfo) {
region.pendingPeers = pendingPeers
region.pendingPeers = append(pendingPeers[:0:0], pendingPeers...)
sort.Sort(peerSlice(region.pendingPeers))
}
}

Expand Down
Loading

0 comments on commit 5d52a62

Please sign in to comment.