forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preparation for add index acceleration, handle 'import cycle'(pingcap…
- Loading branch information
1 parent
5484002
commit 705793d
Showing
29 changed files
with
1,243 additions
and
1,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package util | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/kvproto/pkg/metapb" | ||
berrors "github.com/pingcap/tidb/br/pkg/errors" | ||
"github.com/pingcap/tidb/util/engine" | ||
pd "github.com/tikv/pd/client" | ||
) | ||
|
||
// StoreBehavior is the action to do in GetAllTiKVStores when a non-TiKV | ||
// store (e.g. TiFlash store) is found. | ||
type StoreBehavior uint8 | ||
|
||
const ( | ||
// ErrorOnTiFlash causes GetAllTiKVStores to return error when the store is | ||
// found to be a TiFlash node. | ||
ErrorOnTiFlash StoreBehavior = 0 | ||
// SkipTiFlash causes GetAllTiKVStores to skip the store when it is found to | ||
// be a TiFlash node. | ||
SkipTiFlash StoreBehavior = 1 | ||
// TiFlashOnly caused GetAllTiKVStores to skip the store which is not a | ||
// TiFlash node. | ||
TiFlashOnly StoreBehavior = 2 | ||
) | ||
|
||
// GetAllTiKVStores returns all TiKV stores registered to the PD client. The | ||
// stores must not be a tombstone and must never contain a label `engine=tiflash`. | ||
func GetAllTiKVStores( | ||
ctx context.Context, | ||
pdClient pd.Client, | ||
storeBehavior StoreBehavior, | ||
) ([]*metapb.Store, error) { | ||
// get all live stores. | ||
stores, err := pdClient.GetAllStores(ctx, pd.WithExcludeTombstone()) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
// filter out all stores which are TiFlash. | ||
j := 0 | ||
for _, store := range stores { | ||
isTiFlash := false | ||
if engine.IsTiFlash(store) { | ||
if storeBehavior == SkipTiFlash { | ||
continue | ||
} else if storeBehavior == ErrorOnTiFlash { | ||
return nil, errors.Annotatef(berrors.ErrPDInvalidResponse, | ||
"cannot restore to a cluster with active TiFlash stores (store %d at %s)", store.Id, store.Address) | ||
} | ||
isTiFlash = true | ||
} | ||
if !isTiFlash && storeBehavior == TiFlashOnly { | ||
continue | ||
} | ||
stores[j] = store | ||
j++ | ||
} | ||
return stores[:j], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.