From 3904a62661cdb8fe95b083c08ff4d69f55e01dc1 Mon Sep 17 00:00:00 2001 From: Hu# Date: Thu, 28 Sep 2023 17:19:51 +0800 Subject: [PATCH 1/2] dashboard_test: extend wait time for dashboard service (#7170) close tikv/pd#3182 Signed-off-by: husharp --- server/config/config.go | 2 +- tests/dashboard/service_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index 5b9088ac8ea..0485e077c67 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -505,7 +505,7 @@ type PDServerConfig struct { // RuntimeServices is the running extension services. RuntimeServices typeutil.StringSlice `toml:"runtime-services" json:"runtime-services"` // MetricStorage is the cluster metric storage. - // Currently we use prometheus as metric storage, we may use PD/TiKV as metric storage later. + // Currently, we use prometheus as metric storage, we may use PD/TiKV as metric storage later. MetricStorage string `toml:"metric-storage" json:"metric-storage"` // There are some values supported: "auto", "none", or a specific address, default: "auto" DashboardAddress string `toml:"dashboard-address" json:"dashboard-address"` diff --git a/tests/dashboard/service_test.go b/tests/dashboard/service_test.go index ab3a2c431cb..5f72efb2c36 100644 --- a/tests/dashboard/service_test.go +++ b/tests/dashboard/service_test.go @@ -86,7 +86,8 @@ func (suite *dashboardTestSuite) checkRespCode(url string, code int) { } func waitForConfigSync() { - time.Sleep(time.Second) + // Need to wait dashboard service start. + time.Sleep(3 * time.Second) } func (suite *dashboardTestSuite) checkServiceIsStarted(internalProxy bool, servers map[string]*tests.TestServer, leader *tests.TestServer) string { From 54219d649fb4c8834cd94362a63988f3c074d33e Mon Sep 17 00:00:00 2001 From: buffer <1045931706@qq.com> Date: Thu, 28 Sep 2023 17:42:21 +0800 Subject: [PATCH 2/2] region: fix the potential panic . (#7143) close tikv/pd#4399 Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/core/region.go | 20 ++++++++++++++++++-- pkg/core/region_test.go | 13 +++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkg/core/region.go b/pkg/core/region.go index 9e32bf7c2f5..8d0379f266f 100644 --- a/pkg/core/region.go +++ b/pkg/core/region.go @@ -23,11 +23,13 @@ import ( "sort" "strings" "sync/atomic" + "time" "unsafe" "github.com/docker/go-units" "github.com/gogo/protobuf/proto" "github.com/pingcap/errors" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/kvproto/pkg/replication_modepb" @@ -996,6 +998,11 @@ func (r *RegionsInfo) setRegionLocked(region *RegionInfo, withOverlaps bool, ol // UpdateSubTree updates the subtree. func (r *RegionsInfo) UpdateSubTree(region, origin *RegionInfo, overlaps []*RegionInfo, rangeChanged bool) { + failpoint.Inject("UpdateSubTree", func() { + if origin == nil { + time.Sleep(time.Second) + } + }) r.st.Lock() defer r.st.Unlock() if origin != nil { @@ -1004,8 +1011,17 @@ func (r *RegionsInfo) UpdateSubTree(region, origin *RegionInfo, overlaps []*Regi // TODO: Improve performance by deleting only the different peers. r.removeRegionFromSubTreeLocked(origin) } else { - r.updateSubTreeStat(origin, region) - r.subRegions[region.GetID()].RegionInfo = region + // The region tree and the subtree update is not atomic and the region tree is updated first. + // If there are two thread needs to update region tree, + // t1: thread-A update region tree + // t2: thread-B: update region tree again + // t3: thread-B: update subtree + // t4: thread-A: update region subtree + // to keep region tree consistent with subtree, we need to drop this update. + if tree, ok := r.subRegions[region.GetID()]; ok { + r.updateSubTreeStat(origin, region) + tree.RegionInfo = region + } return } } diff --git a/pkg/core/region_test.go b/pkg/core/region_test.go index 5588d9190ec..50302de920e 100644 --- a/pkg/core/region_test.go +++ b/pkg/core/region_test.go @@ -21,6 +21,7 @@ import ( "strconv" "testing" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" @@ -450,6 +451,18 @@ func TestRegionKey(t *testing.T) { } } +func TestSetRegionConcurrence(t *testing.T) { + re := require.New(t) + re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/core/UpdateSubTree", `return()`)) + regions := NewRegionsInfo() + region := NewTestRegionInfo(1, 1, []byte("a"), []byte("b")) + go func() { + regions.AtomicCheckAndPutRegion(region) + }() + regions.AtomicCheckAndPutRegion(region) + re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/core/UpdateSubTree")) +} + func TestSetRegion(t *testing.T) { re := require.New(t) regions := NewRegionsInfo()