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

Fff3 #45

Open
wants to merge 76 commits into
base: master
Choose a base branch
from
Open

Fff3 #45

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
dc2cfac
test
lhy1024 Jan 14, 2025
8240a5b
test-1
lhy1024 Jan 14, 2025
21d02cf
test-1
lhy1024 Jan 14, 2025
042957a
test-1
lhy1024 Jan 14, 2025
d7cd516
test-1
lhy1024 Jan 14, 2025
0661d87
test-2
lhy1024 Jan 14, 2025
451eeb8
test-1
lhy1024 Jan 14, 2025
fdbcad5
test-1
lhy1024 Jan 14, 2025
52480eb
test-1
lhy1024 Jan 14, 2025
86216d2
t
lhy1024 Jan 14, 2025
a415121
test-1
lhy1024 Jan 14, 2025
b230cad
test-1
lhy1024 Jan 14, 2025
5e66ddd
test-1
lhy1024 Jan 14, 2025
eb60c1f
test-1
lhy1024 Jan 14, 2025
bb4eb69
test-1
lhy1024 Jan 14, 2025
72f9e46
test-2
lhy1024 Jan 14, 2025
f3b3a38
test-3
lhy1024 Jan 14, 2025
1d36f00
test-4
lhy1024 Jan 14, 2025
1e0f978
test-1
lhy1024 Jan 14, 2025
3ce7dc4
test-1
lhy1024 Jan 14, 2025
db8b21b
test-1
lhy1024 Jan 14, 2025
fc52844
test-2
lhy1024 Jan 14, 2025
6c545b6
test-1
lhy1024 Jan 14, 2025
ec66400
test-1
lhy1024 Jan 14, 2025
9cfae91
test-1
lhy1024 Jan 14, 2025
b480ca5
a
lhy1024 Jan 14, 2025
979ccd0
test-1
lhy1024 Jan 14, 2025
34b1e59
test-1
lhy1024 Jan 14, 2025
4d4c81b
test-1
lhy1024 Jan 14, 2025
ff21691
test-1
lhy1024 Jan 14, 2025
ad42d1b
test-1
lhy1024 Jan 14, 2025
20f14f5
test-1
lhy1024 Jan 14, 2025
0dabf16
add log
lhy1024 Jan 14, 2025
b4d913b
test-1
lhy1024 Jan 14, 2025
eddc8e8
test-1
lhy1024 Jan 14, 2025
9c0734d
test-1
lhy1024 Jan 14, 2025
3da3772
test-1
lhy1024 Jan 14, 2025
063332c
test-1
lhy1024 Jan 14, 2025
976c5f9
test-1
lhy1024 Jan 14, 2025
c582045
test-1
lhy1024 Jan 14, 2025
126ea6c
test-1
lhy1024 Jan 14, 2025
ba7384e
test-1
lhy1024 Jan 14, 2025
33133fc
test-1
lhy1024 Jan 14, 2025
4f987db
test-1
lhy1024 Jan 14, 2025
1c394d4
test-1
lhy1024 Jan 14, 2025
437b369
test-1
lhy1024 Jan 14, 2025
40981b4
test-2
lhy1024 Jan 14, 2025
5f21a2c
test
lhy1024 Jan 14, 2025
5832e60
test-1
lhy1024 Jan 14, 2025
ec91738
test-2
lhy1024 Jan 14, 2025
3264e80
test-3
lhy1024 Jan 14, 2025
ec6fbb7
test-1
lhy1024 Jan 14, 2025
3924fa6
test-1
lhy1024 Jan 14, 2025
e03cc1e
test-1
lhy1024 Jan 14, 2025
67b3f35
test-1
lhy1024 Jan 14, 2025
c35fbbb
test-2
lhy1024 Jan 14, 2025
6bfeb83
test-1
lhy1024 Jan 14, 2025
12c8020
test-1
lhy1024 Jan 14, 2025
f9a4b86
test-1
lhy1024 Jan 14, 2025
8b23fe9
test-1
lhy1024 Jan 14, 2025
22b3df6
test-1
lhy1024 Jan 14, 2025
55c7c3b
test-1
lhy1024 Jan 14, 2025
d5daf8c
test-1
lhy1024 Jan 14, 2025
e0fdbc9
test-1
lhy1024 Jan 14, 2025
0bacb68
test-1
lhy1024 Jan 14, 2025
cd4b290
test-1
lhy1024 Jan 14, 2025
d7ff6ea
test-1
lhy1024 Jan 14, 2025
12c3391
test-1
lhy1024 Jan 14, 2025
1c15fe4
test-1
lhy1024 Jan 15, 2025
a9a3559
test-2
lhy1024 Jan 15, 2025
da279c3
test-3
lhy1024 Jan 15, 2025
769d48b
test-4
lhy1024 Jan 15, 2025
77b7816
test-5
lhy1024 Jan 15, 2025
d01bde4
test-1
lhy1024 Jan 15, 2025
c0e6d84
test-1
lhy1024 Jan 15, 2025
64d5a50
test-2
lhy1024 Jan 15, 2025
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
4 changes: 4 additions & 0 deletions pkg/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ func NewStoresInfo() *StoresInfo {
func (s *StoresInfo) GetStore(storeID uint64) *StoreInfo {
s.RLock()
defer s.RUnlock()
if s.stores == nil {
log.Fatal("invalid stores")
return nil
}
store, ok := s.stores[storeID]
if !ok {
return nil
Expand Down
58 changes: 55 additions & 3 deletions tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/goleak"
"go.uber.org/zap"

"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"

"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/response"
"github.com/tikv/pd/pkg/utils/apiutil"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/pkg/utils/typeutil"
Expand Down Expand Up @@ -798,6 +801,23 @@ func TestRemovingProgress(t *testing.T) {
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=2", http.MethodGet, http.StatusNotFound)
re.Contains(string(output), "no progress found for the given store ID")

testutil.Eventually(re, func() bool {
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores", http.MethodGet, http.StatusOK)
var storesInfo response.StoresInfo
if err := json.Unmarshal(output, &storesInfo); err != nil {
return false
}
if len(storesInfo.Stores) != 3 {
return false
}
for _, store := range storesInfo.Stores {
if store.Store.GetNodeState() != metapb.NodeState_Serving {
return false
}
}
return true
})

// remove store 1 and store 2
_ = sendRequest(re, leader.GetAddr()+"/pd/api/v1/store/1", http.MethodDelete, http.StatusOK)
_ = sendRequest(re, leader.GetAddr()+"/pd/api/v1/store/2", http.MethodDelete, http.StatusOK)
Expand Down Expand Up @@ -838,7 +858,21 @@ func TestRemovingProgress(t *testing.T) {
})
}

now := time.Now()
testutil.Eventually(re, func() bool {
defer func() {
if time.Since(now) > 19*time.Second {
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=1", http.MethodGet, http.StatusOK)
re.NoError(json.Unmarshal(output, &p))
log.Info("store 1 progress", zap.Any("progress", p))
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=2", http.MethodGet, http.StatusOK)
re.NoError(json.Unmarshal(output, &p))
log.Info("store 2 progress", zap.Any("progress", p))
}
}()
if leader.GetRaftCluster() == nil {
return false
}
// wait for cluster prepare
if !leader.GetRaftCluster().IsPrepared() {
leader.GetRaftCluster().SetPrepared()
Expand All @@ -850,30 +884,41 @@ func TestRemovingProgress(t *testing.T) {
re.NoError(err)
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Info("not ready", zap.String("url", url), zap.Int("status", resp.StatusCode))
return false
}
output, err := io.ReadAll(resp.Body)
re.NoError(err)
re.NoError(json.Unmarshal(output, &p))
if p.Action != "removing" {
log.Info("not removing", zap.String("action", p.Action))
return false
}
// store 1: (60-20)/(60+50) ~= 0.36
// store 2: (30-10)/(30+40) ~= 0.28
// average progress ~= (0.36+0.28)/2 = 0.32
if fmt.Sprintf("%.2f", p.Progress) != "0.32" {
log.Info("progress not match", zap.Float64("progress", p.Progress))
return false
}
// store 1: 40/10s = 4
// store 2: 20/10s = 2
// average speed = (2+4)/2 = 33
// average speed = (2+4)/2 = 3.0
if p.CurrentSpeed != 3.0 {
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=1", http.MethodGet, http.StatusOK)
re.NoError(json.Unmarshal(output, &p))
log.Info("store 1 progress", zap.Any("progress", p))
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=2", http.MethodGet, http.StatusOK)
re.NoError(json.Unmarshal(output, &p))
log.Info("store 2 progress", zap.Any("progress", p))
log.Info("speed not match", zap.Float64("speed", p.CurrentSpeed))
return false
}
// store 1: (20+50)/4 = 17.5s
// store 2: (10+40)/2 = 25s
// average time = (17.5+25)/2 = 21.25s
if p.LeftSeconds != 21.25 {
log.Info("time not match", zap.Float64("time", p.LeftSeconds))
return false
}
return true
Expand Down Expand Up @@ -1097,15 +1142,22 @@ func sendRequest(re *require.Assertions, url string, method string, statusCode i

testutil.Eventually(re, func() bool {
resp, err := tests.TestDialClient.Do(req)
re.NoError(err)
if err != nil {
log.Info("send request failed", zap.Error(err))
return false
}
defer resp.Body.Close()

// Due to service unavailability caused by environmental issues,
// we will retry it.
if resp.StatusCode == http.StatusServiceUnavailable {
log.Info("service unavailable", zap.String("url", url))
return false
}
if resp.StatusCode != statusCode {
log.Info("status code not match", zap.String("url", url), zap.Int("status", resp.StatusCode))
return false
}
re.Equal(statusCode, resp.StatusCode)
output, err = io.ReadAll(resp.Body)
re.NoError(err)
return true
Expand Down
7 changes: 5 additions & 2 deletions tests/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ func MustPutStore(re *require.Assertions, cluster *TestCluster, store *metapb.St
if ts == 0 {
ts = time.Now().UnixNano()
}
storeInfo := grpcServer.GetRaftCluster().GetStore(store.GetId())
raftCluster := grpcServer.GetRaftCluster()
id := store.GetId()
storeInfo := raftCluster.GetStore(id)
re.NotNil(storeInfo)
newStore := storeInfo.Clone(
core.SetStoreStats(&pdpb.StoreStats{
Capacity: uint64(10 * units.GiB),
Expand All @@ -220,7 +223,7 @@ func MustPutStore(re *require.Assertions, cluster *TestCluster, store *metapb.St
}),
core.SetLastHeartbeatTS(time.Unix(ts/1e9, ts%1e9)),
)
grpcServer.GetRaftCluster().GetBasicCluster().PutStore(newStore)
raftCluster.GetBasicCluster().PutStore(newStore)
if cluster.GetSchedulingPrimaryServer() != nil {
cluster.GetSchedulingPrimaryServer().GetCluster().PutStore(newStore)
}
Expand Down
Loading