Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

install-tools:
@mkdir -p $(GO_TOOLS_BIN_PATH)
@which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.47.1
@which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.48.0
@grep '_' tools.go | sed 's/"//g' | awk '{print $$2}' | xargs go install

.PHONY: install-tools
Expand Down
51 changes: 30 additions & 21 deletions pkg/btree/btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@
// It has a flatter structure than an equivalent red-black or other binary tree,
// which in some cases yields better memory usage and/or performance.
// See some discussion on the matter here:
// http://google-opensource.blogspot.com/2013/01/c-containers-that-save-memory-and-time.html
//
// http://google-opensource.blogspot.com/2013/01/c-containers-that-save-memory-and-time.html
//
// Note, though, that this project is in no way related to the C++ B-Tree
// implementation written about there.
//
// Within this tree, each node contains a slice of items and a (possibly nil)
// slice of children. For basic numeric values or raw structs, this can cause
// efficiency differences when compared to equivalent C++ template code that
// stores values in arrays within the node:
// * Due to the overhead of storing values as interfaces (each
// - Due to the overhead of storing values as interfaces (each
// value needs to be stored as the value itself, then 2 words for the
// interface pointing to that value and its type), resulting in higher
// memory use.
// * Since interfaces can point to values anywhere in memory, values are
// - Since interfaces can point to values anywhere in memory, values are
// most likely not stored in contiguous blocks, resulting in a higher
// number of cache misses.
//
// These issues don't tend to matter, though, when working with strings or other
// heap-allocated structures, since C++-equivalent structures also must store
// pointers and also distribute their values across the heap.
Expand Down Expand Up @@ -244,8 +247,8 @@ func (s *children) truncate(index int) {
// If the node has any children, indices[i] is the index of items[i] in the subtree.
// We have following formulas:
//
// indices[i] = if i == 0 { children[0].length() }
// else { indices[i-1] + 1 + children[i].length() }
// indices[i] = if i == 0 { children[0].length() }
// else { indices[i-1] + 1 + children[i].length() }
type indices []int

func (s *indices) addAt(index int, delta int) {
Expand Down Expand Up @@ -321,8 +324,8 @@ func (s indices) find(k int) (index int, found bool) {
// node is an internal node in a tree.
//
// It must at all times maintain the invariant that either
// * len(children) == 0, len(items) unconstrained
// * len(children) == len(items) + 1
// - len(children) == 0, len(items) unconstrained
// - len(children) == len(items) + 1
type node struct {
items items
children children
Expand Down Expand Up @@ -594,15 +597,20 @@ func (n *node) remove(item Item, minItems int, typ toRemove) (out Item) {
// remove it.
//
// Most documentation says we have to do two sets of special casing:
// 1) item is in this node
// 2) item is in child
// 1. item is in this node
// 2. item is in child
//
// In both cases, we need to handle the two subcases:
// A) node has enough values that it can spare one
// B) node doesn't have enough values
//
// A) node has enough values that it can spare one
// B) node doesn't have enough values
//
// For the latter, we have to check:
// a) left sibling has node to spare
// b) right sibling has node to spare
// c) we must merge
//
// a) left sibling has node to spare
// b) right sibling has node to spare
// c) we must merge
//
// To simplify our code here, we handle cases #1 and #2 the same:
// If a node doesn't have enough items, we make sure it does (using a,b,c).
// We then simply redo our remove call, and the second time (regardless of
Expand Down Expand Up @@ -1043,13 +1051,14 @@ func (t *BTree) getRootLength() int {
// one, instead of being lost to the garbage collector.
//
// This call takes:
// O(1): when addNodesToFreelist is false, this is a single operation.
// O(1): when the freelist is already full, it breaks out immediately
// O(freelist size): when the freelist is empty and the nodes are all owned
// by this tree, nodes are added to the freelist until full.
// O(tree size): when all nodes are owned by another tree, all nodes are
// iterated over looking for nodes to add to the freelist, and due to
// ownership, none are.
//
// O(1): when addNodesToFreelist is false, this is a single operation.
// O(1): when the freelist is already full, it breaks out immediately
// O(freelist size): when the freelist is empty and the nodes are all owned
// by this tree, nodes are added to the freelist until full.
// O(tree size): when all nodes are owned by another tree, all nodes are
// iterated over looking for nodes to add to the freelist, and due to
// ownership, none are.
func (t *BTree) Clear(addNodesToFreelist bool) {
if t.root != nil && addNodesToFreelist {
t.root.reset(t.cow)
Expand Down
18 changes: 11 additions & 7 deletions pkg/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ var pads = make([]byte, encGroupSize)

// EncodeBytes guarantees the encoded value is in ascending order for comparison,
// encoding with the following rule:
// [group1][marker1]...[groupN][markerN]
// group is 8 bytes slice which is padding with 0.
// marker is `0xFF - padding 0 count`
//
// [group1][marker1]...[groupN][markerN]
// group is 8 bytes slice which is padding with 0.
// marker is `0xFF - padding 0 count`
//
// For example:
// [] -> [0, 0, 0, 0, 0, 0, 0, 0, 247]
// [1, 2, 3] -> [1, 2, 3, 0, 0, 0, 0, 0, 250]
// [1, 2, 3, 0] -> [1, 2, 3, 0, 0, 0, 0, 0, 251]
// [1, 2, 3, 4, 5, 6, 7, 8] -> [1, 2, 3, 4, 5, 6, 7, 8, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]
//
// [] -> [0, 0, 0, 0, 0, 0, 0, 0, 247]
// [1, 2, 3] -> [1, 2, 3, 0, 0, 0, 0, 0, 250]
// [1, 2, 3, 0] -> [1, 2, 3, 0, 0, 0, 0, 0, 251]
// [1, 2, 3, 4, 5, 6, 7, 8] -> [1, 2, 3, 4, 5, 6, 7, 8, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]
//
// Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format
func EncodeBytes(data []byte) Key {
// Allocate more space to avoid unnecessary slice growing.
Expand Down
2 changes: 1 addition & 1 deletion pkg/netutil/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
4 changes: 2 additions & 2 deletions plugin/scheduler_example/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ func init() {
}

// SchedulerType returns the type of the scheduler
//nolint
// nolint
func SchedulerType() string {
return EvictLeaderType
}

// SchedulerArgs returns the args for the scheduler
//nolint
// nolint
func SchedulerArgs() []string {
args := []string{"1"}
return args
Expand Down
2 changes: 1 addition & 1 deletion server/api/pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
90 changes: 45 additions & 45 deletions server/cluster/unsafe_recovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,51 @@ const (
)

// Stage transition graph: for more details, please check `unsafeRecoveryController.HandleStoreHeartbeat()`
// +-----------+ +-----------+
// +-----------+ | | | |
// | | | collect | | tombstone |
// | idle |------>| Report |-----+---->| tiflash |-----+
// | | | | | | learner | |
// +-----------+ +-----------+ | | | |
// | +-----------+ |
// | | |
// | | |
// | v |
// | +-----------+ |
// | | | |
// | | force | |
// | | LeaderFor |-----+
// | |CommitMerge| |
// | | | |
// | +-----------+ |
// | | |
// | | |
// | v |
// | +-----------+ | +-----------+
// | | | | | | +-----------+
// | | force | | | exitForce | | |
// | | Leader |-----+---->| Leader |------->| failed |
// | | | | | | | |
// | +-----------+ | +-----------+ +-----------+
// | | |
// | | |
// | v |
// | +-----------+ |
// | | | |
// | | demote | |
// +-----| Voter |-----|
// | | |
// +-----------+ |
// | |
// | |
// v |
// +-----------+ +-----------+ |
// +-----------+ | | | | |
// | | | exitForce | | create | |
// | finished |<------| Leader |<----------| Region |-----+
// | | | | | |
// +-----------+ +-----------+ +-----------+
//
// +-----------+ +-----------+
// +-----------+ | | | |
// | | | collect | | tombstone |
// | idle |------>| Report |-----+---->| tiflash |-----+
// | | | | | | learner | |
// +-----------+ +-----------+ | | | |
// | +-----------+ |
// | | |
// | | |
// | v |
// | +-----------+ |
// | | | |
// | | force | |
// | | LeaderFor |-----+
// | |CommitMerge| |
// | | | |
// | +-----------+ |
// | | |
// | | |
// | v |
// | +-----------+ | +-----------+
// | | | | | | +-----------+
// | | force | | | exitForce | | |
// | | Leader |-----+---->| Leader |------->| failed |
// | | | | | | | |
// | +-----------+ | +-----------+ +-----------+
// | | |
// | | |
// | v |
// | +-----------+ |
// | | | |
// | | demote | |
// +-----| Voter |-----|
// | | |
// +-----------+ |
// | |
// | |
// v |
// +-----------+ +-----------+ |
// +-----------+ | | | | |
// | | | exitForce | | create | |
// | finished |<------| Leader |<----------| Region |-----+
// | | | | | |
// +-----------+ +-----------+ +-----------+
const (
idle unsafeRecoveryStage = iota
collectReport
Expand Down Expand Up @@ -381,7 +381,7 @@ func (u *unsafeRecoveryController) handleErr() bool {
return false
}

/// It dispatches recovery plan if any.
// It dispatches recovery plan if any.
func (u *unsafeRecoveryController) dispatchPlan(heartbeat *pdpb.StoreHeartbeatRequest, resp *pdpb.StoreHeartbeatResponse) {
storeID := heartbeat.Stats.StoreId
now := time.Now()
Expand Down
7 changes: 4 additions & 3 deletions server/encryptionkm/key_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,10 @@ func (m *KeyManager) loadKeys() error {
}

// rotateKeyIfNeeded rotate key if one of the following condition is meet.
// * Encryption method is changed.
// * Current key is exposed.
// * Current key expired.
// - Encryption method is changed.
// - Current key is exposed.
// - Current key expired.
//
// Otherwise re-save all keys to finish master key rotation if forceUpdate = true.
// Require mu lock to be held.
func (m *KeyManager) rotateKeyIfNeeded(forceUpdate bool) error {
Expand Down
2 changes: 1 addition & 1 deletion server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (h *Handler) GetHotRegionsWriteInterval() time.Duration {
return h.opt.GetHotRegionsWriteInterval()
}

// GetHotRegionsReservedDays gets days hot region information is kept.
// GetHotRegionsReservedDays gets days hot region information is kept.
func (h *Handler) GetHotRegionsReservedDays() uint64 {
return h.opt.GetHotRegionsReservedDays()
}
Expand Down
39 changes: 20 additions & 19 deletions server/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ var listMemberRetryTimes = 20
// and returns the initial configuration of the PD cluster.
//
// TL;TR: The join functionality is safe. With data, join does nothing, w/o data
// and it is not a member of cluster, join does MemberAdd, it returns an
// error if PD tries to join itself, missing data or join a duplicated PD.
//
// and it is not a member of cluster, join does MemberAdd, it returns an
// error if PD tries to join itself, missing data or join a duplicated PD.
//
// Etcd automatically re-joins the cluster if there is a data directory. So
// first it checks if there is a data directory or not. If there is, it returns
Expand All @@ -56,29 +57,29 @@ var listMemberRetryTimes = 20
//
// If there is no data directory, there are following cases:
//
// - A new PD joins an existing cluster.
// What join does: MemberAdd, MemberList, then generate initial-cluster.
// - A new PD joins an existing cluster.
// What join does: MemberAdd, MemberList, then generate initial-cluster.
//
// - A failed PD re-joins the previous cluster.
// What join does: return an error. (etcd reports: raft log corrupted,
// truncated, or lost?)
// - A failed PD re-joins the previous cluster.
// What join does: return an error. (etcd reports: raft log corrupted,
// truncated, or lost?)
//
// - A deleted PD joins to previous cluster.
// What join does: MemberAdd, MemberList, then generate initial-cluster.
// (it is not in the member list and there is no data, so
// we can treat it as a new PD.)
// - A deleted PD joins to previous cluster.
// What join does: MemberAdd, MemberList, then generate initial-cluster.
// (it is not in the member list and there is no data, so
// we can treat it as a new PD.)
//
// If there is a data directory, there are following special cases:
//
// - A failed PD tries to join the previous cluster but it has been deleted
// during its downtime.
// What join does: return "" (etcd will connect to other peers and find
// that the PD itself has been removed.)
// - A failed PD tries to join the previous cluster but it has been deleted
// during its downtime.
// What join does: return "" (etcd will connect to other peers and find
// that the PD itself has been removed.)
//
// - A deleted PD joins the previous cluster.
// What join does: return "" (as etcd will read data directory and find
// that the PD itself has been removed, so an empty string
// is fine.)
// - A deleted PD joins the previous cluster.
// What join does: return "" (as etcd will read data directory and find
// that the PD itself has been removed, so an empty string
// is fine.)
func PrepareJoinCluster(cfg *config.Config) error {
// - A PD tries to join itself.
if cfg.Join == "" {
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/filter/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/labeler/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (rule *LabelRule) expireBefore(t time.Time) bool {
return rule.minExpire.Before(t)
}

// initKeyRangeRulesFromLabelRuleData init and adjust []KeyRangeRule from `LabelRule.Data``
// initKeyRangeRulesFromLabelRuleData init and adjust []KeyRangeRule from `LabelRule.Data
func initKeyRangeRulesFromLabelRuleData(data interface{}) ([]*KeyRangeRule, error) {
rules, ok := data.([]interface{})
if !ok {
Expand Down
12 changes: 7 additions & 5 deletions server/schedule/operator/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ type ClusterInformer interface {
}

// Builder is used to create operators. Usage:
// op, err := NewBuilder(desc, cluster, region).
// RemovePeer(store1).
// AddPeer(peer1).
// SetLeader(store2).
// Build(kind)
//
// op, err := NewBuilder(desc, cluster, region).
// RemovePeer(store1).
// AddPeer(peer1).
// SetLeader(store2).
// Build(kind)
//
// The generated Operator will choose the most appropriate execution order
// according to various constraints.
type Builder struct {
Expand Down
Loading