-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store/tikv: resolve storeType dependency #22854
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1bf02d9
store/tikv: resolve storeType dependency
disksing cc8f76f
Merge branch 'master' into storetype
disksing cbc92bc
add comment
disksing d6ddea9
Merge branch 'master' into storetype
disksing ddbccf0
remove comments
disksing c586d2a
Merge branch 'master' into storetype
ti-srebot 42c2e7e
Merge branch 'master' into storetype
ti-srebot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,84 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// 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 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package tikv | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pingcap/kvproto/pkg/metapb" | ||
) | ||
|
||
// AccessMode uses to index stores for different region cache access requirements. | ||
type AccessMode int | ||
|
||
const ( | ||
// TiKVOnly indicates stores list that use for TiKv access(include both leader request and follower read). | ||
TiKVOnly AccessMode = iota | ||
// TiFlashOnly indicates stores list that use for TiFlash request. | ||
TiFlashOnly | ||
// NumAccessMode reserved to keep max access mode value. | ||
NumAccessMode | ||
) | ||
|
||
func (a AccessMode) String() string { | ||
switch a { | ||
case TiKVOnly: | ||
return "TiKvOnly" | ||
case TiFlashOnly: | ||
return "TiFlashOnly" | ||
default: | ||
return fmt.Sprintf("%d", a) | ||
} | ||
} | ||
|
||
// Constants to determine engine type. | ||
// They should be synced with PD. | ||
const ( | ||
engineLabelKey = "engine" | ||
engineLabelTiFlash = "tiflash" | ||
) | ||
|
||
// GetStoreTypeByMeta gets store type by store meta pb. | ||
func GetStoreTypeByMeta(store *metapb.Store) StoreType { | ||
tp := TiKV | ||
for _, label := range store.Labels { | ||
if label.Key == engineLabelKey { | ||
if label.Value == engineLabelTiFlash { | ||
tp = TiFlash | ||
} | ||
break | ||
} | ||
} | ||
return tp | ||
} | ||
|
||
// StoreType represents the type of a store. | ||
type StoreType uint8 | ||
|
||
// Store type enums. | ||
// They should be synced with tidb/kv.StoreType. | ||
const ( | ||
TiKV StoreType = iota | ||
TiFlash | ||
) | ||
|
||
// Name returns the name of store type. | ||
func (t StoreType) Name() string { | ||
if t == TiFlash { | ||
return "tiflash" | ||
} else if t == TiKV { | ||
return "tikv" | ||
} | ||
return "unspecified" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not unify these two
StoreType
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andylokandy I discover that the 2
storeType
s are actually not strict related. There is no need to keep them synced. (I even tried to changetikv.StoreType
to type string, it can still compile). So I removed the comments that declare they should be sync.