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

Do not move protobuf from TValue during BulkUpsert execution. #1809

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ TAsyncBulkUpsertResult TTableClient::TImpl::BulkUpsert(const TString& table, TVa
auto request = MakeOperationRequest<Ydb::Table::BulkUpsertRequest>(settings);
request.set_table(table);
*request.mutable_rows()->mutable_type() = TProtoAccessor::GetProto(rows.GetType());
*request.mutable_rows()->mutable_value() = std::move(rows.GetProto());
*request.mutable_rows()->mutable_value() = rows.GetProto();

auto promise = NewPromise<TBulkUpsertResult>();

Expand Down
69 changes: 69 additions & 0 deletions ydb/services/ydb/ydb_bulk_upsert_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,75 @@ Y_UNIT_TEST_SUITE(YdbTableBulkUpsert) {
UNIT_ASSERT_VALUES_EQUAL(count, BATCH_COUNT * BATCH_SIZE);
}

Y_UNIT_TEST(ValidRetry) {
TKikimrWithGrpcAndRootSchema server;
ui16 grpc = server.GetPort();

TString location = TStringBuilder() << "localhost:" << grpc;

auto connection = NYdb::TDriver(TDriverConfig().SetEndpoint(location));

NYdb::NTable::TTableClient client(connection);
auto session = client.GetSession().ExtractValueSync().GetSession();

{
auto tableBuilder = client.GetTableBuilder();
tableBuilder
.AddNullableColumn("Shard", EPrimitiveType::Uint64)
.AddNullableColumn("Message", EPrimitiveType::Utf8);
tableBuilder.SetPrimaryKeyColumns({"Shard"});
NYdb::NTable::TCreateTableSettings tableSettings;
tableSettings.PartitioningPolicy(NYdb::NTable::TPartitioningPolicy().UniformPartitions(32));
auto result = session.CreateTable("/Root/Logs", tableBuilder.Build(), tableSettings).ExtractValueSync();

UNIT_ASSERT_EQUAL(result.GetStatus(), EStatus::SUCCESS);
}

TValueBuilder rows;
rows.BeginList();
rows.AddListItem()
.BeginStruct()
.AddMember("Shard").Uint64(1)
.AddMember("Message").Utf8("message")
.EndStruct();
rows.EndList();

auto v1 = rows.Build();
auto v2 = v1;

ui32 limit = 100;
while (true && --limit) {
NYdb::NTable::TBulkUpsertSettings upsertSettings;
upsertSettings.ClientTimeout(TDuration::MicroSeconds(10));
auto res = client.BulkUpsert("/Root/Logs", std::move(v2), upsertSettings).GetValueSync();

Cerr << res.GetStatus() << Endl;
if (res.GetStatus() == EStatus::CLIENT_DEADLINE_EXCEEDED)
break;
}

UNIT_ASSERT_C(limit, "Unable to get client error response");

{
auto res = client.BulkUpsert("/Root/Logs", std::move(v1)).GetValueSync();
UNIT_ASSERT_EQUAL(res.GetStatus(), EStatus::SUCCESS);
}

{
auto res = session.ExecuteDataQuery(
"SELECT Message as col FROM `/Root/Logs`;",
NYdb::NTable::TTxControl::BeginTx().CommitTx()
).ExtractValueSync();

UNIT_ASSERT_EQUAL(res.GetStatus(), EStatus::SUCCESS);

auto rs = NYdb::TResultSetParser(res.GetResultSet(0));
UNIT_ASSERT(rs.TryNextRow());
auto msg = rs.ColumnParser("col").GetOptionalUtf8();
UNIT_ASSERT_VALUES_EQUAL(msg, "message");
}
}

void TestNull(NYdb::TDriver& connection, EPrimitiveType valueType, bool inKey) {
TString tableName = Sprintf("/Root/TestNulls_0x%04x", valueType);

Expand Down
Loading