Skip to content

Commit

Permalink
api: Revert for showing State in StoreInfo (tikv#4485)
Browse files Browse the repository at this point in the history
* Revert "fix tikv#3816: recovered pdctl/store_test && add comment to function onlu used by test"

This reverts commit acc531f.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

* Revert "fix tikv#3816: fix code format problem"

This reverts commit 0f0f65a.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

* Revert "fix tikv#3816: fix code format problem"

This reverts commit b36673f.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

* Revert "fix tikv#3816: fix code format problem"

This reverts commit 8c28174.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

* Revert "Fix tikv#3816 delete unnecessary field and fix unit test"

This reverts commit acc942e.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

* revert tikv#4334

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

* revert tikv#4334: empty commit for add signed-off-by

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: JmPotato <ghzpotato@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
  • Loading branch information
CabinfeverB and JmPotato committed Dec 28, 2021
1 parent 25a1423 commit b610683
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 113 deletions.
57 changes: 7 additions & 50 deletions server/api/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,56 +36,10 @@ import (
"github.com/unrolled/render"
)

// MetaStore contains meta information about a store which needed to show.
// MetaStore contains meta information about a store.
type MetaStore struct {
StoreID uint64 `json:"id,omitempty"`
Address string `json:"address,omitempty"`
Labels []*metapb.StoreLabel `json:"labels,omitempty"`
Version string `json:"version,omitempty"`
PeerAddress string `json:"peer_address,omitempty"`
StatusAddress string `json:"status_address,omitempty"`
GitHash string `json:"git_hash,omitempty"`
StartTimestamp int64 `json:"start_timestamp,omitempty"`
DeployPath string `json:"deploy_path,omitempty"`
LastHeartbeat int64 `json:"last_heartbeat,omitempty"`
PhysicallyDestroyed bool `json:"physically_destroyed,omitempty"`
StateName string `json:"state_name"`
}

// NewMetaStore convert metapb.Store to MetaStore without State
func NewMetaStore(store *metapb.Store, stateName string) *MetaStore {
metaStore := &MetaStore{StateName: stateName}
metaStore.StoreID = store.GetId()
metaStore.Address = store.GetAddress()
metaStore.Labels = store.GetLabels()
metaStore.Version = store.GetVersion()
metaStore.PeerAddress = store.GetPeerAddress()
metaStore.StatusAddress = store.GetStatusAddress()
metaStore.GitHash = store.GetGitHash()
metaStore.StartTimestamp = store.GetStartTimestamp()
metaStore.DeployPath = store.GetDeployPath()
metaStore.LastHeartbeat = store.GetLastHeartbeat()
metaStore.PhysicallyDestroyed = store.GetPhysicallyDestroyed()
return metaStore
}

// ConvertToMetapbStore convert to metapb.Store
// For test only.
func (m *MetaStore) ConvertToMetapbStore() *metapb.Store {
metapbStore := &metapb.Store{
Id: m.StoreID,
Address: m.Address,
State: metapb.StoreState(metapb.StoreState_value[m.StateName]),
Labels: m.Labels,
Version: m.Version,
PeerAddress: m.PeerAddress,
StatusAddress: m.StatusAddress,
GitHash: m.GitHash,
StartTimestamp: m.StartTimestamp,
DeployPath: m.DeployPath,
LastHeartbeat: m.LastHeartbeat,
}
return metapbStore
*metapb.Store
StateName string `json:"state_name"`
}

// StoreStatus contains status about a store.
Expand Down Expand Up @@ -123,7 +77,10 @@ const (

func newStoreInfo(opt *config.ScheduleConfig, store *core.StoreInfo) *StoreInfo {
s := &StoreInfo{
Store: NewMetaStore(store.GetMeta(), store.GetState().String()),
Store: &MetaStore{
Store: store.GetMeta(),
StateName: store.GetState().String(),
},
Status: &StoreStatus{
Capacity: typeutil.ByteSize(store.GetCapacity()),
Available: typeutil.ByteSize(store.GetAvailable()),
Expand Down
63 changes: 8 additions & 55 deletions server/api/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/tikv/pd/server"
"github.com/tikv/pd/server/config"
"github.com/tikv/pd/server/core"
"github.com/tikv/pd/server/versioninfo"
)

var _ = Suite(&testStoreSuite{})
Expand Down Expand Up @@ -115,8 +114,7 @@ func checkStoresInfo(c *C, ss []*StoreInfo, want []*metapb.Store) {
}
}
for _, s := range ss {
metapbStore := s.Store.ConvertToMetapbStore()
obtained := proto.Clone(metapbStore).(*metapb.Store)
obtained := proto.Clone(s.Store.Store).(*metapb.Store)
expected := proto.Clone(mapWant[obtained.Id]).(*metapb.Store)
// Ignore lastHeartbeat
obtained.LastHeartbeat, expected.LastHeartbeat = 0, 0
Expand Down Expand Up @@ -168,51 +166,6 @@ func (s *testStoreSuite) TestStoreGet(c *C) {
checkStoresInfo(c, []*StoreInfo{info}, s.stores[:1])
}

func (s *testStoreSuite) TestStoreInfoGet(c *C) {
timeStamp := time.Now().Unix()
url := fmt.Sprintf("%s/store/1112", s.urlPrefix)
_, errPut := s.grpcSvr.PutStore(context.Background(), &pdpb.PutStoreRequest{
Header: &pdpb.RequestHeader{ClusterId: s.svr.ClusterID()},
Store: &metapb.Store{
Id: 1112,
Address: fmt.Sprintf("tikv%d", 1112),
State: 1,
Labels: nil,
Version: versioninfo.MinSupportedVersion(versioninfo.Version5_0).String(),
StatusAddress: fmt.Sprintf("tikv%d", 1112),
GitHash: "45ce5b9584d618bc777877bea77cb94f61b8410",
StartTimestamp: timeStamp,
DeployPath: "/home/test",
LastHeartbeat: timeStamp,
},
})
c.Assert(errPut, IsNil)

info := new(StoreInfo)

err := readJSON(testDialClient, url, info)
c.Assert(err, IsNil)
c.Assert(info.Store.StateName, Equals, metapb.StoreState_Offline.String())
c.Assert(info.Store.StoreID, Equals, uint64(1112))
c.Assert(info.Store.Address, Equals, "tikv1112")
c.Assert(info.Store.Version, Equals, versioninfo.MinSupportedVersion(versioninfo.Version5_0).String())
c.Assert(info.Store.StatusAddress, Equals, fmt.Sprintf("tikv%d", 1112))
c.Assert(info.Store.GitHash, Equals, "45ce5b9584d618bc777877bea77cb94f61b8410")
c.Assert(info.Store.StartTimestamp, Equals, timeStamp)
c.Assert(info.Store.DeployPath, Equals, "/home/test")
c.Assert(info.Store.LastHeartbeat, Equals, timeStamp)

resp, err := testDialClient.Get(url)
c.Assert(err, IsNil)
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
c.Assert(err, IsNil)
str := string(b)
c.Assert(strings.Contains(str, "\"state\""), Equals, false)
s.cleanup()
s.SetUpSuite(c)
}

func (s *testStoreSuite) TestStoreLabel(c *C) {
url := fmt.Sprintf("%s/store/1", s.urlPrefix)
var info StoreInfo
Expand Down Expand Up @@ -309,7 +262,7 @@ func (s *testStoreSuite) TestStoreDelete(c *C) {
err := readJSON(testDialClient, url, store)
c.Assert(err, IsNil)
c.Assert(store.Store.PhysicallyDestroyed, IsFalse)
c.Assert(store.Store.StateName, Equals, metapb.StoreState_Offline.String())
c.Assert(store.Store.State, Equals, metapb.StoreState_Offline)

// up store success because it is offline but not physically destroyed
status := requestStatusBody(c, testDialClient, http.MethodPost, fmt.Sprintf("%s/state?state=Up", url))
Expand All @@ -320,15 +273,15 @@ func (s *testStoreSuite) TestStoreDelete(c *C) {
store = new(StoreInfo)
err = readJSON(testDialClient, url, store)
c.Assert(err, IsNil)
c.Assert(store.Store.StateName, Equals, metapb.StoreState_Up.String())
c.Assert(store.Store.State, Equals, metapb.StoreState_Up)
c.Assert(store.Store.PhysicallyDestroyed, IsFalse)

// offline store with physically destroyed
status = requestStatusBody(c, testDialClient, http.MethodDelete, fmt.Sprintf("%s?force=true", url))
c.Assert(status, Equals, http.StatusOK)
err = readJSON(testDialClient, url, store)
c.Assert(err, IsNil)
c.Assert(store.Store.StateName, Equals, metapb.StoreState_Offline.String())
c.Assert(store.Store.State, Equals, metapb.StoreState_Offline)
c.Assert(store.Store.PhysicallyDestroyed, IsTrue)

// try to up store again failed because it is physically destroyed
Expand All @@ -344,15 +297,15 @@ func (s *testStoreSuite) TestStoreSetState(c *C) {
info := StoreInfo{}
err := readJSON(testDialClient, url, &info)
c.Assert(err, IsNil)
c.Assert(info.Store.StateName, Equals, metapb.StoreState_Up.String())
c.Assert(info.Store.State, Equals, metapb.StoreState_Up)

// Set to Offline.
info = StoreInfo{}
err = postJSON(testDialClient, url+"/state?state=Offline", nil)
c.Assert(err, IsNil)
err = readJSON(testDialClient, url, &info)
c.Assert(err, IsNil)
c.Assert(info.Store.StateName, Equals, metapb.StoreState_Offline.String())
c.Assert(info.Store.State, Equals, metapb.StoreState_Offline)

// store not found
info = StoreInfo{}
Expand All @@ -367,7 +320,7 @@ func (s *testStoreSuite) TestStoreSetState(c *C) {
c.Assert(err, NotNil)
err = readJSON(testDialClient, url, &info)
c.Assert(err, IsNil)
c.Assert(info.Store.StateName, Equals, metapb.StoreState_Offline.String())
c.Assert(info.Store.State, Equals, metapb.StoreState_Offline)
}

// Set back to Up.
Expand All @@ -376,7 +329,7 @@ func (s *testStoreSuite) TestStoreSetState(c *C) {
c.Assert(err, IsNil)
err = readJSON(testDialClient, url, &info)
c.Assert(err, IsNil)
c.Assert(info.Store.StateName, Equals, metapb.StoreState_Up.String())
c.Assert(info.Store.State, Equals, metapb.StoreState_Up)
}

func (s *testStoreSuite) TestUrlStoreFilter(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions server/api/trend.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func (h *trendHandler) getTrendStores() ([]trendStore, error) {
for _, store := range stores {
info := newStoreInfo(h.svr.GetScheduleConfig(), store)
s := trendStore{
ID: info.Store.StoreID,
Address: info.Store.Address,
ID: info.Store.GetId(),
Address: info.Store.GetAddress(),
StateName: info.Store.StateName,
Capacity: uint64(info.Status.Capacity),
Available: uint64(info.Status.Available),
Expand Down
2 changes: 1 addition & 1 deletion tests/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (s *TestServer) GetStoreRegions(storeID uint64) []*core.RegionInfo {
func (s *TestServer) BootstrapCluster() error {
bootstrapReq := &pdpb.BootstrapRequest{
Header: &pdpb.RequestHeader{ClusterId: s.GetClusterID()},
Store: &metapb.Store{Id: 1, Address: "mock://1", LastHeartbeat: time.Now().UnixNano()},
Store: &metapb.Store{Id: 1, Address: "mock://1"},
Region: &metapb.Region{Id: 2, Peers: []*metapb.Peer{{Id: 3, StoreId: 1, Role: metapb.PeerRole_Voter}}},
}
_, err := s.grpcServer.Bootstrap(context.Background(), bootstrapReq)
Expand Down
3 changes: 1 addition & 2 deletions tests/pdctl/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func CheckStoresInfo(c *check.C, stores []*api.StoreInfo, want []*metapb.Store)
}
}
for _, s := range stores {
metapbStore := s.Store.ConvertToMetapbStore()
obtained := proto.Clone(metapbStore).(*metapb.Store)
obtained := proto.Clone(s.Store.Store).(*metapb.Store)
expected := proto.Clone(mapWant[obtained.Id]).(*metapb.Store)
// Ignore lastHeartbeat
obtained.LastHeartbeat, expected.LastHeartbeat = 0, 0
Expand Down
6 changes: 3 additions & 3 deletions tests/pdctl/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ func (s *storeTestSuite) TestStore(c *C) {
c.Assert(ok, IsFalse)

// store delete <store_id> command
c.Assert(storeInfo.Store.StateName, Equals, metapb.StoreState_Up.String())
c.Assert(storeInfo.Store.State, Equals, metapb.StoreState_Up)
args = []string{"-u", pdAddr, "store", "delete", "1"}
_, err = pdctl.ExecuteCommand(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "store", "1"}
output, err = pdctl.ExecuteCommand(cmd, args...)
c.Assert(err, IsNil)
c.Assert(json.Unmarshal(output, &storeInfo), IsNil)
c.Assert(storeInfo.Store.StateName, Equals, metapb.StoreState_Offline.String())
c.Assert(storeInfo.Store.State, Equals, metapb.StoreState_Offline)

// store check status
args = []string{"-u", pdAddr, "store", "check", "Offline"}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (s *storeTestSuite) TestStore(c *C) {
output, err = pdctl.ExecuteCommand(cmd, args...)
c.Assert(err, IsNil)
c.Assert(json.Unmarshal(output, &storeInfo), IsNil)
c.Assert(storeInfo.Store.StateName, Equals, metapb.StoreState_Offline.String())
c.Assert(storeInfo.Store.State, Equals, metapb.StoreState_Offline)

// store remove-tombstone
args = []string{"-u", pdAddr, "store", "remove-tombstone"}
Expand Down

0 comments on commit b610683

Please sign in to comment.