Skip to content
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

*: fix crash issue #6957

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Changes from all commits
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
43 changes: 31 additions & 12 deletions dbms/src/Flash/Mpp/MPPTunnelSetWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static void broadcastOrPassThroughWriteImpl(
FuncIsLocalTunnel && isLocalTunnel,
FuncWriteToTunnel && writeToTunnel)
{
assert(tunnel_cnt > 0);
assert(ori_packet_bytes > 0);

const size_t remote_tunnel_cnt = tunnel_cnt - local_tunnel_cnt;
Expand All @@ -127,23 +128,41 @@ static void broadcastOrPassThroughWriteImpl(
}

// TODO avoid copy packet for broadcast.
for (size_t i = 0, local_cnt = 0, remote_cnt = 0; i < tunnel_cnt; ++i)

if (local_tracked_packet == remote_tracked_packet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about assert(local_tracked_packet != remote_tracked_packet) and copy packet in

remote_tracked_packet = ori_tracked_packet;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or

if (local_tracked_packet != nullptr && local_tracked_packet == remote_tracked_packet)
    local_tracked_packet = local_tracked_packet->copy();

It looks like the total number of copies is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current way is aimed to reduce maximum memory usage.

{
if (isLocalTunnel(i))
// `TrackedMppDataPacket` in `TrackedMppDataPacketPtr` is mutable.
// If `local_tracked_packet` and `remote_tracked_packet` share same object, there is also another optional way to copy `remote_tracked_packet` early.
// Use this fast path to reduce maximum memory usage
auto tracked_packet = std::move(local_tracked_packet);
remote_tracked_packet = nullptr;

for (size_t i = 1; i < tunnel_cnt; ++i)
{
local_cnt++;
if (local_cnt == local_tunnel_cnt)
writeToTunnel(std::move(local_tracked_packet), i);
else
writeToTunnel(local_tracked_packet->copy(), i); // NOLINT
writeToTunnel(tracked_packet->copy(), i);
}
else
writeToTunnel(std::move(tracked_packet), 0);
}
else
{
for (size_t i = 0, local_cnt = 0, remote_cnt = 0; i < tunnel_cnt; ++i)
{
remote_cnt++;
if (remote_cnt == remote_tunnel_cnt)
writeToTunnel(std::move(remote_tracked_packet), i);
if (isLocalTunnel(i))
{
local_cnt++;
if (local_cnt == local_tunnel_cnt)
writeToTunnel(std::move(local_tracked_packet), i);
else
writeToTunnel(local_tracked_packet->copy(), i); // NOLINT
}
else
writeToTunnel(remote_tracked_packet->copy(), i); // NOLINT
{
remote_cnt++;
if (remote_cnt == remote_tunnel_cnt)
writeToTunnel(std::move(remote_tracked_packet), i);
else
writeToTunnel(remote_tracked_packet->copy(), i); // NOLINT
}
}
}

Expand Down