Skip to content

Commit

Permalink
Merge branch 'master' into refactor-mcs-server
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Aug 31, 2023
2 parents 50ea886 + 39cff3b commit f112d15
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ linters-settings:
excludes:
- G402
- G404
- G601
5 changes: 5 additions & 0 deletions client/resource_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,16 @@ func (c *client) createTokenDispatcher() {
tokenBatchController: newTokenBatchController(
make(chan *tokenRequest, 1)),
}
c.wg.Add(1)
go c.handleResourceTokenDispatcher(dispatcherCtx, dispatcher.tokenBatchController)
c.tokenDispatcher = dispatcher
}

func (c *client) handleResourceTokenDispatcher(dispatcherCtx context.Context, tbc *tokenBatchController) {
defer func() {
log.Info("[resource manager] exit resource token dispatcher")
c.wg.Done()
}()
var (
connection resourceManagerConnectionContext
firstRequest *tokenRequest
Expand Down
8 changes: 2 additions & 6 deletions pkg/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -1660,15 +1660,11 @@ func DiffRegionKeyInfo(origin *RegionInfo, other *RegionInfo) string {
}

// String converts slice of bytes to string without copy.
func String(b []byte) (s string) {
func String(b []byte) string {
if len(b) == 0 {
return ""
}
pbytes := (*reflect.SliceHeader)(unsafe.Pointer(&b))
pstring := (*reflect.StringHeader)(unsafe.Pointer(&s))
pstring.Data = pbytes.Data
pstring.Len = pbytes.Len
return
return unsafe.String(unsafe.SliceData(b), len(b))
}

// ToUpperASCIIInplace bytes.ToUpper but zero-cost
Expand Down
2 changes: 1 addition & 1 deletion pkg/election/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (l *lease) keepAliveWorker(ctx context.Context, interval time.Duration) <-c
}
res, err := l.lease.KeepAliveOnce(ctx1, leaseID)
if err != nil {
log.Warn("lease keep alive failed", zap.String("purpose", l.Purpose), errs.ZapError(err))
log.Warn("lease keep alive failed", zap.String("purpose", l.Purpose), zap.Time("start", start), errs.ZapError(err))
return
}
if res.TTL > 0 {
Expand Down
1 change: 1 addition & 0 deletions pkg/encryption/key_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"go.etcd.io/etcd/embed"
)

// #nosec G101
const (
testMasterKey = "8fd7e3e917c170d92f3e51a981dd7bc8fba11f3df7d8df994842f6e86f69b530"
testMasterKey2 = "8fd7e3e917c170d92f3e51a981dd7bc8fba11f3df7d8df994842f6e86f69b531"
Expand Down
6 changes: 3 additions & 3 deletions pkg/encryption/master_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestPlaintextMasterKey(t *testing.T) {
func TestEncrypt(t *testing.T) {
t.Parallel()
re := require.New(t)
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806" // #nosec G101
key, err := hex.DecodeString(keyHex)
re.NoError(err)
masterKey := &MasterKey{key: key}
Expand All @@ -68,7 +68,7 @@ func TestEncrypt(t *testing.T) {
func TestDecrypt(t *testing.T) {
t.Parallel()
re := require.New(t)
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
keyHex := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806" // #nosec G101
key, err := hex.DecodeString(keyHex)
re.NoError(err)
plaintext := "this-is-a-plaintext"
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestNewFileMasterKeyLengthMismatch(t *testing.T) {
func TestNewFileMasterKey(t *testing.T) {
t.Parallel()
re := require.New(t)
key := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806"
key := "2f07ec61e5a50284f47f2b402a962ec672e500b26cb3aa568bb1531300c74806" // #nosec G101
dir := t.TempDir()
path := dir + "/key"
os.WriteFile(path, []byte(key), 0600)
Expand Down
3 changes: 2 additions & 1 deletion pkg/schedule/schedulers/transfer_witness_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (s *trasferWitnessLeaderScheduler) Schedule(cluster sche.SchedulerCluster,

func (s *trasferWitnessLeaderScheduler) scheduleTransferWitnessLeaderBatch(name, typ string, cluster sche.SchedulerCluster, batchSize int) []*operator.Operator {
var ops []*operator.Operator
batchLoop:
for i := 0; i < batchSize; i++ {
select {
case region := <-s.regions:
Expand All @@ -92,7 +93,7 @@ func (s *trasferWitnessLeaderScheduler) scheduleTransferWitnessLeaderBatch(name,
ops = append(ops, op)
}
default:
break
break batchLoop
}
}
return ops
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/hot_region_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ type HistoryHotRegion struct {

// HotRegionStorageHandler help hot region storage get hot region info.
type HotRegionStorageHandler interface {
// PackHistoryHotWriteRegions get read hot region info in HistoryHotRegion form.
// PackHistoryHotReadRegions get read hot region info in HistoryHotRegion form.
PackHistoryHotReadRegions() ([]HistoryHotRegion, error)
// PackHistoryHotWriteRegions get write hot region info in HistoryHotRegion form.
PackHistoryHotWriteRegions() ([]HistoryHotRegion, error)
// IsLeader return true means this server is leader.
IsLeader() bool
// GetHotRegionWriteInterval gets interval for PD to store Hot Region information..
// GetHotRegionsWriteInterval gets interval for PD to store Hot Region information.
GetHotRegionsWriteInterval() time.Duration
// GetHotRegionsReservedDays gets days hot region information is kept.
GetHotRegionsReservedDays() uint64
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/apiutil/apiutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
// PDRedirectorHeader is used to mark which PD redirected this request.
PDRedirectorHeader = "PD-Redirector"
// PDAllowFollowerHandleHeader is used to mark whether this request is allowed to be handled by the follower PD.
PDAllowFollowerHandleHeader = "PD-Allow-follower-handle"
PDAllowFollowerHandleHeader = "PD-Allow-follower-handle" // #nosec G101
// XForwardedForHeader is used to mark the client IP.
XForwardedForHeader = "X-Forwarded-For"
// XForwardedPortHeader is used to mark the client port.
Expand Down
10 changes: 5 additions & 5 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ func (s *GrpcServer) GetMinTSFromTSOService(dcLocation string) (*pdpb.Timestamp,

// Get the minimal timestamp from the TSO servers/pods
var mutex sync.Mutex
resps := make([]*tsopb.GetMinTSResponse, 0)
resps := make([]*tsopb.GetMinTSResponse, len(addrs))
wg := sync.WaitGroup{}
wg.Add(len(addrs))
for _, addr := range addrs {
go func(addr string) {
for idx, addr := range addrs {
go func(idx int, addr string) {
defer wg.Done()
resp, err := s.getMinTSFromSingleServer(s.ctx, dcLocation, addr)
if err != nil || resp == nil {
Expand All @@ -193,8 +193,8 @@ func (s *GrpcServer) GetMinTSFromTSOService(dcLocation string) (*pdpb.Timestamp,
}
mutex.Lock()
defer mutex.Unlock()
resps = append(resps, resp)
}(addr)
resps[idx] = resp
}(idx, addr)
}
wg.Wait()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ func (suite *resourceManagerClientTestSuite) TestResourcePenalty() {
c.Stop()
}

// nolint:gosec
func (suite *resourceManagerClientTestSuite) TestAcquireTokenBucket() {
re := suite.Require()
cli := suite.client
Expand Down

0 comments on commit f112d15

Please sign in to comment.