-
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
executor,util: Stat inner/inter zone network traffic for MPP tasks #58683
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
78c1575
Add SameZoneFlag attribute for tiflash exchange executors
68dcc06
update format
cca1260
Fill sameZoneFlag in local_mpp_coordinator instead of plan_2_pb
yibin87 5fea743
Revert useless changes
yibin87 ccea07e
add tiflash execution summary merge code
yibin87 0261110
update tikv execdetails using tiflash network stats
yibin87 8e2b438
Little refact
yibin87 61251d0
little refact
yibin87 2b8aa5d
Little refact
yibin87 9e7b994
Add ut for execution summary changes
yibin87 63b1f47
update go.mod
yibin87 9c1f771
update bazel file
yibin87 a152c49
Fix bazel issue
yibin87 d33b2e1
fix lint issue
yibin87 46f323a
add some logs to help debug
yibin87 1f0da7b
little fix
yibin87 baece4a
Refact and optimize
yibin87 261b38b
Little refact
yibin87 25e7247
little fix
yibin87 8a855a4
another fix
yibin87 82dc253
Align fields
yibin87 4161a63
Add back removed comments
yibin87 b9c4d35
Little change
yibin87 f9e35c4
Add ut for tryQuickFill
yibin87 873cf6c
Address comments
yibin87 383b889
Fix a little issue
yibin87 058bad1
Address comments
yibin87 67cf51d
Address comments for CTE cases
yibin87 8877c6d
update
yibin87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5906,13 +5906,13 @@ def go_deps(): | |
name = "com_github_pingcap_tipb", | ||
build_file_proto_mode = "disable_global", | ||
importpath = "github.com/pingcap/tipb", | ||
sha256 = "923efe448355ba420cfbd82e93df2f99b08c3fb36191b1f2cabdd3bf32904852", | ||
strip_prefix = "github.com/pingcap/[email protected]20241105053214-f91fdb81a69e", | ||
sha256 = "87ef3f28a30822c9e2a4966bfb573025ae332ac2a045be1026641e121fccb7e6", | ||
strip_prefix = "github.com/pingcap/[email protected]20241212101007-246f91188357", | ||
urls = [ | ||
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241105053214-f91fdb81a69e.zip", | ||
"http://ats.apps.svc/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241105053214-f91fdb81a69e.zip", | ||
"https://cache.hawkingrei.com/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241105053214-f91fdb81a69e.zip", | ||
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241105053214-f91fdb81a69e.zip", | ||
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241212101007-246f91188357.zip", | ||
"http://ats.apps.svc/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241212101007-246f91188357.zip", | ||
"https://cache.hawkingrei.com/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241212101007-246f91188357.zip", | ||
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20241212101007-246f91188357.zip", | ||
], | ||
) | ||
go_repository( | ||
|
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
"github.com/pingcap/failpoint" | ||
"github.com/pingcap/kvproto/pkg/mpp" | ||
"github.com/pingcap/tidb/pkg/config" | ||
"github.com/pingcap/tidb/pkg/ddl/placement" | ||
"github.com/pingcap/tidb/pkg/distsql" | ||
"github.com/pingcap/tidb/pkg/executor/internal/builder" | ||
"github.com/pingcap/tidb/pkg/executor/internal/util" | ||
|
@@ -40,11 +41,13 @@ import ( | |
"github.com/pingcap/tidb/pkg/store/copr" | ||
"github.com/pingcap/tidb/pkg/store/driver/backoff" | ||
derr "github.com/pingcap/tidb/pkg/store/driver/error" | ||
"github.com/pingcap/tidb/pkg/store/helper" | ||
util2 "github.com/pingcap/tidb/pkg/util" | ||
"github.com/pingcap/tidb/pkg/util/execdetails" | ||
"github.com/pingcap/tidb/pkg/util/logutil" | ||
"github.com/pingcap/tidb/pkg/util/memory" | ||
"github.com/pingcap/tipb/go-tipb" | ||
"github.com/tikv/client-go/v2/tikv" | ||
clientutil "github.com/tikv/client-go/v2/util" | ||
"go.uber.org/zap" | ||
) | ||
|
@@ -189,7 +192,7 @@ func NewLocalMPPCoordinator(ctx context.Context, sctx sessionctx.Context, is inf | |
return coord | ||
} | ||
|
||
func (c *localMppCoordinator) appendMPPDispatchReq(pf *plannercore.Fragment) error { | ||
func (c *localMppCoordinator) appendMPPDispatchReq(pf *plannercore.Fragment, allTiFlashZoneInfo map[string]string) error { | ||
dagReq, err := builder.ConstructDAGReq(c.sessionCtx, []base.PhysicalPlan{pf.ExchangeSender}, kv.TiFlash) | ||
if err != nil { | ||
return errors.Trace(err) | ||
|
@@ -202,6 +205,8 @@ func (c *localMppCoordinator) appendMPPDispatchReq(pf *plannercore.Fragment) err | |
} else { | ||
dagReq.EncodeType = tipb.EncodeType_TypeChunk | ||
} | ||
zoneHelper := taskZoneInfoHelper{} | ||
zoneHelper.init(allTiFlashZoneInfo) | ||
for _, mppTask := range pf.ExchangeSender.Tasks { | ||
if mppTask.PartitionTableIDs != nil { | ||
err = util.UpdateExecutorTableID(context.Background(), dagReq.RootExecutor, true, mppTask.PartitionTableIDs) | ||
|
@@ -217,6 +222,9 @@ func (c *localMppCoordinator) appendMPPDispatchReq(pf *plannercore.Fragment) err | |
if err != nil { | ||
return err | ||
} | ||
zoneHelper.isRoot = pf.IsRoot | ||
zoneHelper.currentTaskZone = zoneHelper.allTiFlashZoneInfo[mppTask.Meta.GetAddress()] | ||
zoneHelper.fillSameZoneFlagForExchange(dagReq.RootExecutor) | ||
pbData, err := dagReq.Marshal() | ||
if err != nil { | ||
return errors.Trace(err) | ||
|
@@ -343,6 +351,127 @@ func (c *localMppCoordinator) fixTaskForCTEStorageAndReader(exec *tipb.Executor, | |
return nil | ||
} | ||
|
||
// taskZoneInfoHelper used to help reset exchange executor's same zone flags | ||
type taskZoneInfoHelper struct { | ||
allTiFlashZoneInfo map[string]string | ||
// exchangeZoneInfo is used to cache one mpp task's zone info: | ||
// key is executor id, value is zone info array | ||
// for ExchangeSender, it's target tiflash nodes' zone info; for ExchangeReceiver, it's source tiflash nodes' zone info | ||
exchangeZoneInfo map[string][]string | ||
tidbZone string | ||
currentTaskZone string | ||
isRoot bool | ||
} | ||
|
||
func (h *taskZoneInfoHelper) init(allTiFlashZoneInfo map[string]string) { | ||
h.tidbZone = config.GetGlobalConfig().Labels[placement.DCLabelKey] | ||
h.allTiFlashZoneInfo = allTiFlashZoneInfo | ||
// initial capacity to 2, for one exchange sender and one exchange receiver | ||
h.exchangeZoneInfo = make(map[string][]string, 2) | ||
} | ||
|
||
func (h *taskZoneInfoHelper) tryQuickFillWithUncertainZones(exec *tipb.Executor, slots int, sameZoneFlags []bool) (bool, []bool) { | ||
if exec.ExecutorId == nil || len(h.currentTaskZone) == 0 { | ||
for i := 0; i < slots; i++ { | ||
sameZoneFlags = append(sameZoneFlags, true) | ||
} | ||
return true, sameZoneFlags | ||
} | ||
if h.isRoot && exec.Tp == tipb.ExecType_TypeExchangeSender { | ||
sameZoneFlags = append(sameZoneFlags, len(h.tidbZone) == 0 || h.currentTaskZone == h.tidbZone) | ||
return true, sameZoneFlags | ||
} | ||
|
||
// For CTE exchange nodes, data is passed locally, set all to true | ||
if (exec.Tp == tipb.ExecType_TypeExchangeSender && len(exec.ExchangeSender.UpstreamCteTaskMeta) != 0) || | ||
(exec.Tp == tipb.ExecType_TypeExchangeReceiver && len(exec.ExchangeReceiver.OriginalCtePrdocuerTaskMeta) != 0) { | ||
for i := 0; i < slots; i++ { | ||
sameZoneFlags = append(sameZoneFlags, true) | ||
} | ||
return true, sameZoneFlags | ||
} | ||
|
||
return false, sameZoneFlags | ||
} | ||
|
||
func (h *taskZoneInfoHelper) collectExchangeZoneInfos(encodedTaskMeta [][]byte, slots int) []string { | ||
zoneInfos := make([]string, 0, slots) | ||
for _, taskBytes := range encodedTaskMeta { | ||
taskMeta := &mpp.TaskMeta{} | ||
err := taskMeta.Unmarshal(taskBytes) | ||
if err != nil { | ||
zoneInfos = append(zoneInfos, "") | ||
continue | ||
} | ||
zoneInfos = append(zoneInfos, h.allTiFlashZoneInfo[taskMeta.GetAddress()]) | ||
} | ||
return zoneInfos | ||
} | ||
|
||
func (h *taskZoneInfoHelper) inferSameZoneFlag(exec *tipb.Executor, encodedTaskMeta [][]byte) []bool { | ||
slots := len(encodedTaskMeta) | ||
sameZoneFlags := make([]bool, 0, slots) | ||
filled := false | ||
if filled, sameZoneFlags = h.tryQuickFillWithUncertainZones(exec, slots, sameZoneFlags); filled { | ||
return sameZoneFlags | ||
} | ||
zoneInfos, exist := h.exchangeZoneInfo[*exec.ExecutorId] | ||
if !exist { | ||
zoneInfos = h.collectExchangeZoneInfos(encodedTaskMeta, slots) | ||
h.exchangeZoneInfo[*exec.ExecutorId] = zoneInfos | ||
} | ||
|
||
if len(zoneInfos) != slots { | ||
// This branch is for safety purpose, not expected | ||
for i := 0; i < slots; i++ { | ||
sameZoneFlags = append(sameZoneFlags, true) | ||
} | ||
return sameZoneFlags | ||
} | ||
|
||
for i := 0; i < slots; i++ { | ||
sameZoneFlags = append(sameZoneFlags, len(zoneInfos[i]) == 0 || h.currentTaskZone == zoneInfos[i]) | ||
} | ||
return sameZoneFlags | ||
} | ||
|
||
func (h *taskZoneInfoHelper) fillSameZoneFlagForExchange(exec *tipb.Executor) { | ||
children := make([]*tipb.Executor, 0, 2) | ||
switch exec.Tp { | ||
case tipb.ExecType_TypeTableScan, tipb.ExecType_TypePartitionTableScan, tipb.ExecType_TypeIndexScan: | ||
case tipb.ExecType_TypeSelection: | ||
children = append(children, exec.Selection.Child) | ||
case tipb.ExecType_TypeAggregation, tipb.ExecType_TypeStreamAgg: | ||
children = append(children, exec.Aggregation.Child) | ||
case tipb.ExecType_TypeTopN: | ||
children = append(children, exec.TopN.Child) | ||
case tipb.ExecType_TypeLimit: | ||
children = append(children, exec.Limit.Child) | ||
case tipb.ExecType_TypeExchangeSender: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of codes in sender and receiver are similiar, I think wemay create a function to unify them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'll try |
||
children = append(children, exec.ExchangeSender.Child) | ||
exec.ExchangeSender.SameZoneFlag = h.inferSameZoneFlag(exec, exec.ExchangeSender.EncodedTaskMeta) | ||
case tipb.ExecType_TypeExchangeReceiver: | ||
exec.ExchangeReceiver.SameZoneFlag = h.inferSameZoneFlag(exec, exec.ExchangeReceiver.EncodedTaskMeta) | ||
case tipb.ExecType_TypeJoin: | ||
children = append(children, exec.Join.Children...) | ||
case tipb.ExecType_TypeProjection: | ||
children = append(children, exec.Projection.Child) | ||
case tipb.ExecType_TypeWindow: | ||
children = append(children, exec.Window.Child) | ||
case tipb.ExecType_TypeSort: | ||
children = append(children, exec.Sort.Child) | ||
case tipb.ExecType_TypeExpand: | ||
children = append(children, exec.Expand.Child) | ||
case tipb.ExecType_TypeExpand2: | ||
children = append(children, exec.Expand2.Child) | ||
default: | ||
logutil.BgLogger().Warn(fmt.Sprintf("unknown new tipb protocol %d", exec.Tp)) | ||
} | ||
for _, child := range children { | ||
h.fillSameZoneFlagForExchange(child) | ||
} | ||
} | ||
|
||
func getActualPhysicalPlan(plan base.Plan) base.PhysicalPlan { | ||
if plan == nil { | ||
return nil | ||
|
@@ -788,8 +917,24 @@ func (c *localMppCoordinator) Execute(ctx context.Context) (kv.Response, []kv.Ke | |
} | ||
c.nodeCnt = len(nodeInfo) | ||
|
||
var allTiFlashZoneInfo map[string]string | ||
if c.sessionCtx.GetStore() == nil { | ||
allTiFlashZoneInfo = make(map[string]string) | ||
} else if tikvStore, ok := c.sessionCtx.GetStore().(helper.Storage); ok { | ||
cache := tikvStore.GetRegionCache() | ||
allTiFlashStores := cache.GetTiFlashStores(tikv.LabelFilterNoTiFlashWriteNode) | ||
allTiFlashZoneInfo = make(map[string]string, len(allTiFlashStores)) | ||
for _, tiflashStore := range allTiFlashStores { | ||
tiflashStoreAddr := tiflashStore.GetAddr() | ||
if tiflashZone, isSet := tiflashStore.GetLabelValue(placement.DCLabelKey); isSet { | ||
allTiFlashZoneInfo[tiflashStoreAddr] = tiflashZone | ||
} | ||
} | ||
} else { | ||
allTiFlashZoneInfo = make(map[string]string) | ||
} | ||
for _, frag := range frags { | ||
err = c.appendMPPDispatchReq(frag) | ||
err = c.appendMPPDispatchReq(frag, allTiFlashZoneInfo) | ||
if err != nil { | ||
return nil, nil, errors.Trace(err) | ||
} | ||
|
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.
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 we can dirctly return when
tiflashNetworkStats == nil
without setting tikv detail?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.
Set tikv details here to record mpp network traffic. When tiflashNetworkStats is nil, which means there is no mpp network traffic recorded, thus no need to set a default value tikv detail.