Skip to content

Commit 1d7b52b

Browse files
committed
fix-write
1 parent 2414fb7 commit 1d7b52b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ydb/core/kqp/runtime/kqp_write_table.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,17 @@ class TShardsInfo {
889889

890890
void MakeNextBatches(i64 maxDataSize, ui64 maxCount) {
891891
YQL_ENSURE(BatchesInFlight == 0);
892+
YQL_ENSURE(!IsEmpty());
892893
i64 dataSize = 0;
894+
// For columnshard batch can be slightly larger than the limit.
893895
while (BatchesInFlight < maxCount
894896
&& BatchesInFlight < Batches.size()
895-
&& dataSize + GetBatch(BatchesInFlight)->GetMemory() <= maxDataSize) {
897+
&& (dataSize + GetBatch(BatchesInFlight)->GetMemory() <= maxDataSize || BatchesInFlight == 0)) {
896898
dataSize += GetBatch(BatchesInFlight)->GetMemory();
897899
++BatchesInFlight;
898900
}
899-
YQL_ENSURE(BatchesInFlight == Batches.size() || GetBatch(BatchesInFlight)->GetMemory() <= maxDataSize);
901+
YQL_ENSURE(BatchesInFlight != 0);
902+
YQL_ENSURE(BatchesInFlight == maxCount || BatchesInFlight == Batches.size() || dataSize + GetBatch(BatchesInFlight)->GetMemory() >= maxDataSize);
900903
}
901904

902905
const IPayloadSerializer::IBatchPtr& GetBatch(size_t index) const {
@@ -1200,18 +1203,19 @@ class TShardedWriteController : public IShardedWriteController {
12001203
if (force) {
12011204
for (auto& [shardId, batches] : Serializer->FlushBatchesForce()) {
12021205
for (auto& batch : batches) {
1203-
ShardsInfo.GetShard(shardId).PushBatch(std::move(batch));
1206+
if (batch && !batch->IsEmpty()) {
1207+
ShardsInfo.GetShard(shardId).PushBatch(std::move(batch));
1208+
}
12041209
}
12051210
}
12061211
} else {
12071212
for (const ui64 shardId : Serializer->GetShardIds()) {
12081213
auto& shard = ShardsInfo.GetShard(shardId);
12091214
while (true) {
12101215
auto batch = Serializer->FlushBatch(shardId);
1211-
if (!batch || batch->IsEmpty()) {
1212-
break;
1216+
if (batch && !batch->IsEmpty()) {
1217+
shard.PushBatch(std::move(batch));
12131218
}
1214-
shard.PushBatch(std::move(batch));
12151219
}
12161220
}
12171221
}

0 commit comments

Comments
 (0)