Skip to content

Commit

Permalink
server/cluster: refine log errs in cluster (tikv#2712)
Browse files Browse the repository at this point in the history
Signed-off-by: Howard Lau <howardlau1999@hotmail.com>
  • Loading branch information
howardlau1999 authored and jyz0309 committed Aug 24, 2020
1 parent 072cdb0 commit 5cfb2ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
13 changes: 13 additions & 0 deletions pkg/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ var (
ErrWriteHTTPBody = errors.Normalize("write HTTP body failed", errors.RFCCodeText("PD:apiutil:ErrWriteHTTPBody"))
)

// cluster errors
var (
ErrPersistStore = errors.Normalize("failed to persist store", errors.RFCCodeText("PD:cluster:ErrPersistStore"))
ErrDeleteRegion = errors.Normalize("failed to delete region from storage", errors.RFCCodeText("PD:cluster:ErrDeleteRegion"))
ErrSaveRegion = errors.Normalize("failed to save region from storage", errors.RFCCodeText("PD:cluster:ErrSaveRegion"))
ErrBuryStore = errors.Normalize("failed to bury store", errors.RFCCodeText("PD:cluster:ErrBuryStore"))
ErrDeleteStore = errors.Normalize("failed to delete store", errors.RFCCodeText("PD:cluster:ErrDeleteStore"))
ErrPersistClusterVersion = errors.Normalize("persist cluster version meet error", errors.RFCCodeText("PD:cluster:ErrPersistClusterVersion"))
ErrGetMembers = errors.Normalize("get members failed", errors.RFCCodeText("PD:cluster:ErrGetMembers"))
// TODO: ErrNewHTTPRequest may not be suitable to put in cluster category
ErrNewHTTPRequest = errors.Normalize("new HTTP request failed", errors.RFCCodeText("PD:cluster:ErrNewHTTPRequest"))
)

// metricutil errors
var (
ErrPushGateway = errors.Normalize("push metrics to gateway failed", errors.RFCCodeText("PD:metricutil:ErrPushGateway"))
Expand Down
17 changes: 9 additions & 8 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/cache"
"github.com/tikv/pd/pkg/component"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/etcdutil"
"github.com/tikv/pd/pkg/keyutil"
"github.com/tikv/pd/pkg/logutil"
Expand Down Expand Up @@ -500,7 +501,7 @@ func (c *RaftCluster) HandleStoreHeartbeat(stats *pdpb.StoreStats) error {
}
if newStore.NeedPersist() && c.storage != nil {
if err := c.storage.SaveStore(newStore.GetMeta()); err != nil {
log.Error("failed to persist store", zap.Uint64("store-id", newStore.GetID()))
log.Error("failed to persist store", zap.Uint64("store-id", newStore.GetID()), errs.ZapError(errs.ErrPersistStore, err))
} else {
newStore = newStore.Clone(core.SetLastPersistTime(time.Now()))
}
Expand Down Expand Up @@ -628,7 +629,7 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
log.Error("failed to delete region from storage",
zap.Uint64("region-id", item.GetID()),
zap.Stringer("region-meta", core.RegionToHexMeta(item.GetMeta())),
zap.Error(err))
errs.ZapError(errs.ErrDeleteRegion, err))
}
}
}
Expand Down Expand Up @@ -680,7 +681,7 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
log.Error("failed to save region to storage",
zap.Uint64("region-id", region.GetID()),
zap.Stringer("region-meta", core.RegionToHexMeta(region.GetMeta())),
zap.Error(err))
errs.ZapError(errs.ErrSaveRegion, err))
}
regionEventCounter.WithLabelValues("update_kv").Inc()
}
Expand Down Expand Up @@ -1139,7 +1140,7 @@ func (c *RaftCluster) checkStores() {
if err := c.BuryStore(offlineStore.GetId(), false); err != nil {
log.Error("bury store failed",
zap.Stringer("store", offlineStore),
zap.Error(err))
errs.ZapError(errs.ErrBuryStore, err))
}
} else {
offlineStores = append(offlineStores, offlineStore)
Expand Down Expand Up @@ -1170,7 +1171,7 @@ func (c *RaftCluster) RemoveTombStoneRecords() error {
if err != nil {
log.Error("delete store failed",
zap.Stringer("store", store.GetMeta()),
zap.Error(err))
errs.ZapError(errs.ErrDeleteStore, err))
return err
}
c.RemoveStoreLimit(store.GetID())
Expand Down Expand Up @@ -1243,7 +1244,7 @@ func (c *RaftCluster) resetClusterMetrics() {
func (c *RaftCluster) collectHealthStatus() {
members, err := GetMembers(c.etcdClient)
if err != nil {
log.Error("get members error", zap.Error(err))
log.Error("get members error", errs.ZapError(errs.ErrGetMembers, err))
}
unhealth := CheckHealth(c.httpClient, members)
for _, member := range members {
Expand Down Expand Up @@ -1317,7 +1318,7 @@ func (c *RaftCluster) OnStoreVersionChange() {
}
err := c.opt.Persist(c.storage)
if err != nil {
log.Error("persist cluster version meet error", zap.Error(err))
log.Error("persist cluster version meet error", errs.ZapError(errs.ErrPersistClusterVersion, err))
}
log.Info("cluster version changed",
zap.Stringer("old-cluster-version", clusterVersion),
Expand Down Expand Up @@ -1799,7 +1800,7 @@ func CheckHealth(client *http.Client, members []*pdpb.Member) map[uint64]*pdpb.M
ctx, cancel := context.WithTimeout(context.Background(), clientTimeout)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s%s", cURL, healthURL), nil)
if err != nil {
log.Error("failed to new request", zap.Error(err))
log.Error("failed to new request", errs.ZapError(errs.ErrNewHTTPRequest, err))
cancel()
continue
}
Expand Down

0 comments on commit 5cfb2ed

Please sign in to comment.