Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 6 additions & 10 deletions google/cloud/spanner/benchmarks/multiple_rows_cpu_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,8 @@ class ExperimentImpl {
if (!force && current_mutations < 1000) {
return {};
}
auto m = std::move(mutation).Build();
auto result = client.Commit(
[&m](spanner::Transaction const&) { return spanner::Mutations{m}; });
auto result =
client.Commit(spanner::Mutations{std::move(mutation).Build()});
if (!result) {
std::lock_guard<std::mutex> lk(mu_);
std::cout << "# Error in Commit() " << result.status() << "\n";
Expand Down Expand Up @@ -1505,13 +1504,10 @@ class MutationExperiment : public Experiment {

int row_count = 0;
auto commit_result =
client.Commit([&](spanner::Transaction const&)
-> google::cloud::StatusOr<spanner::Mutations> {
return spanner::Mutations{spanner::MakeInsertOrUpdateMutation(
table_name_, column_names, key, values[0], values[1], values[2],
values[3], values[4], values[5], values[6], values[7],
values[8], values[9])};
});
client.Commit(spanner::Mutations{spanner::MakeInsertOrUpdateMutation(
table_name_, column_names, key, values[0], values[1], values[2],
values[3], values[4], values[5], values[6], values[7], values[8],
values[9])});
timer.Stop();
samples.push_back(RowCpuSample{
client_count, thread_count, false, row_count, timer.elapsed_time(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ void FillTableTask(Config const& config, spanner::Client client, std::mutex& mu,
if (!force && current_mutations < 1000) {
return;
}
auto m = std::move(mutation).Build();
auto result = client.Commit(
[&m](spanner::Transaction const&) { return spanner::Mutations{m}; });
auto result =
client.Commit(spanner::Mutations{std::move(mutation).Build()});
if (!result) {
std::lock_guard<std::mutex> lk(mu);
std::cerr << "# Error in Commit() " << result.status() << "\n";
Expand Down Expand Up @@ -319,10 +318,9 @@ class InsertOrUpdateExperiment : public Experiment {
deadline = start + config.iteration_duration;
start < deadline; start = std::chrono::steady_clock::now()) {
auto key = key_generator();
auto m = spanner::MakeInsertOrUpdateMutation("KeyValue", {"Key", "Data"},
key, value);
auto result = client.Commit(
[&m](spanner::Transaction const&) { return spanner::Mutations{m}; });
auto result =
client.Commit(spanner::Mutations{spanner::MakeInsertOrUpdateMutation(
"KeyValue", {"Key", "Data"}, key, value)});
if (!result) {
errors.push_back(std::move(result).status());
}
Expand Down
46 changes: 17 additions & 29 deletions google/cloud/spanner/integration_tests/client_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,17 @@ class ClientIntegrationTest : public ::testing::Test {
}

void SetUp() override {
auto commit_result = client_->Commit([](Transaction const&) {
return Mutations{MakeDeleteMutation("Singers", KeySet::All())};
});
auto commit_result = client_->Commit(
Mutations{MakeDeleteMutation("Singers", KeySet::All())});
EXPECT_STATUS_OK(commit_result);
}

void InsertTwoSingers() {
auto commit_result = client_->Commit([](Transaction const&) {
return Mutations{InsertMutationBuilder(
"Singers", {"SingerId", "FirstName", "LastName"})
.EmplaceRow(1, "test-fname-1", "test-lname-1")
.EmplaceRow(2, "test-fname-2", "test-lname-2")
.Build()};
});
auto commit_result = client_->Commit(Mutations{
InsertMutationBuilder("Singers", {"SingerId", "FirstName", "LastName"})
.EmplaceRow(1, "test-fname-1", "test-lname-1")
.EmplaceRow(2, "test-fname-2", "test-lname-2")
.Build()});
ASSERT_STATUS_OK(commit_result);
}

Expand Down Expand Up @@ -98,10 +95,8 @@ TEST_F(ClientIntegrationTest, InsertAndCommit) {
TEST_F(ClientIntegrationTest, DeleteAndCommit) {
ASSERT_NO_FATAL_FAILURE(InsertTwoSingers());

auto commit_result = client_->Commit([](Transaction const&) {
return Mutations{
MakeDeleteMutation("Singers", KeySet().AddKey(MakeKey(1)))};
});
auto commit_result = client_->Commit(
Mutations{MakeDeleteMutation("Singers", KeySet().AddKey(MakeKey(1)))});
EXPECT_STATUS_OK(commit_result);

auto rows = client_->Read("Singers", KeySet::All(),
Expand Down Expand Up @@ -248,25 +243,18 @@ TEST_F(ClientIntegrationTest, TransactionRollback) {
/// @test Verify the basics of Commit().
TEST_F(ClientIntegrationTest, Commit) {
// Insert SingerIds 100, 102, and 199.
auto inserter = [](Transaction const&) {
auto isb =
InsertMutationBuilder("Singers", {"SingerId", "FirstName", "LastName"})
.EmplaceRow(100, "first-name-100", "last-name-100")
.EmplaceRow(102, "first-name-102", "last-name-102")
.EmplaceRow(199, "first-name-199", "last-name-199");
return Mutations{isb.Build()};
};
auto insert_result = client_->Commit(inserter);
auto isb =
InsertMutationBuilder("Singers", {"SingerId", "FirstName", "LastName"})
.EmplaceRow(100, "first-name-100", "last-name-100")
.EmplaceRow(102, "first-name-102", "last-name-102")
.EmplaceRow(199, "first-name-199", "last-name-199");
auto insert_result = client_->Commit(Mutations{isb.Build()});
EXPECT_STATUS_OK(insert_result);
EXPECT_NE(Timestamp{}, insert_result->commit_timestamp);

// Delete SingerId 102.
auto deleter = [](Transaction const&) {
auto mutation =
MakeDeleteMutation("Singers", KeySet().AddKey(MakeKey(102)));
return Mutations{mutation};
};
auto delete_result = client_->Commit(deleter);
auto delete_result = client_->Commit(
Mutations{MakeDeleteMutation("Singers", KeySet().AddKey(MakeKey(102)))});
EXPECT_STATUS_OK(delete_result);
EXPECT_LT(insert_result->commit_timestamp, delete_result->commit_timestamp);

Expand Down
24 changes: 10 additions & 14 deletions google/cloud/spanner/integration_tests/client_stress_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ TEST(ClientSqlStressTest, UpsertAndSelect) {
auto action = static_cast<Action>(random_action(generator));

if (action == kInsert) {
auto commit = client.Commit(
[key](Transaction const&) -> StatusOr<spanner::Mutations> {
auto s = std::to_string(key);
return Mutations{spanner::MakeInsertOrUpdateMutation(
"Singers", {"SingerId", "FirstName", "LastName"}, key,
"fname-" + s, "lname-" + s)};
});
auto s = std::to_string(key);
auto commit =
client.Commit(Mutations{spanner::MakeInsertOrUpdateMutation(
"Singers", {"SingerId", "FirstName", "LastName"}, key,
"fname-" + s, "lname-" + s)});
result.Update(commit.status());
} else {
auto size = random_limit(generator);
Expand Down Expand Up @@ -152,13 +150,11 @@ TEST(ClientStressTest, UpsertAndRead) {
auto action = static_cast<Action>(random_action(generator));

if (action == kInsert) {
auto commit = client.Commit(
[key](Transaction const&) -> StatusOr<spanner::Mutations> {
auto s = std::to_string(key);
return Mutations{spanner::MakeInsertOrUpdateMutation(
"Singers", {"SingerId", "FirstName", "LastName"}, key,
"fname-" + s, "lname-" + s)};
});
auto s = std::to_string(key);
auto commit =
client.Commit(Mutations{spanner::MakeInsertOrUpdateMutation(
"Singers", {"SingerId", "FirstName", "LastName"}, key,
"fname-" + s, "lname-" + s)});
result.Update(commit.status());
} else {
auto size = random_limit(generator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ MakeTimePoint(std::time_t sec, std::chrono::nanoseconds::rep nanos) {
template <typename T>
StatusOr<T> WriteReadData(Client& client, T const& data,
std::string const& column) {
auto commit_result = client.Commit(
[&data, &column](Transaction const&) -> StatusOr<Mutations> {
Mutations mutations;
int id = 0;
for (auto const& x : data) {
mutations.push_back(MakeInsertMutation(
"DataTypes", {"Id", column}, "Id-" + std::to_string(id++), x));
}
return mutations;
});
Mutations mutations;
int id = 0;
for (auto const& x : data) {
mutations.push_back(MakeInsertMutation("DataTypes", {"Id", column},
"Id-" + std::to_string(id++), x));
}
auto commit_result = client.Commit(std::move(mutations));
if (!commit_result) return commit_result.status();

T actual;
Expand All @@ -74,10 +71,8 @@ class DataTypeIntegrationTest : public ::testing::Test {
}

void SetUp() override {
auto commit_result = client_->Commit([](Transaction const&) {
return Mutations{
MakeDeleteMutation("DataTypes", KeySet::All()),
};
auto commit_result = client_->Commit(Mutations{
MakeDeleteMutation("DataTypes", KeySet::All()),
});
EXPECT_STATUS_OK(commit_result);
}
Expand Down
84 changes: 36 additions & 48 deletions google/cloud/spanner/samples/samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,8 @@ void InsertData(google::cloud::spanner::Client client) {
.EmplaceRow(2, 3, "Terrified")
.Build();

auto commit_result = client.Commit(
[&insert_singers, &insert_albums](spanner::Transaction const&) {
return spanner::Mutations{insert_singers, insert_albums};
});
auto commit_result =
client.Commit(spanner::Mutations{insert_singers, insert_albums});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
Expand All @@ -765,14 +763,12 @@ void InsertData(google::cloud::spanner::Client client) {
//! [update-mutation-builder] [START spanner_update_data]
void UpdateData(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
auto commit_result = client.Commit([](spanner::Transaction const&) {
return spanner::Mutations{
spanner::UpdateMutationBuilder(
"Albums", {"SingerId", "AlbumId", "MarketingBudget"})
.EmplaceRow(1, 1, 100000)
.EmplaceRow(2, 2, 500000)
.Build()};
});
auto commit_result = client.Commit(spanner::Mutations{
spanner::UpdateMutationBuilder("Albums",
{"SingerId", "AlbumId", "MarketingBudget"})
.EmplaceRow(1, 1, 100000)
.EmplaceRow(2, 2, 500000)
.Build()});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
Expand Down Expand Up @@ -800,10 +796,8 @@ void DeleteData(google::cloud::spanner::Client client) {
spanner::MakeKeyBoundClosed(5)))
.Build();

auto commit_result = client.Commit(
[&delete_albums, &delete_singers](spanner::Transaction const&) {
return spanner::Mutations{delete_albums, delete_singers};
});
auto commit_result =
client.Commit(spanner::Mutations{delete_albums, delete_singers});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
Expand All @@ -814,19 +808,17 @@ void DeleteData(google::cloud::spanner::Client client) {
// [START spanner_insert_data_with_timestamp_column]
void InsertDataWithTimestamp(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
auto commit_result = client.Commit([](spanner::Transaction const&) {
return spanner::Mutations{
spanner::InsertOrUpdateMutationBuilder(
"Performances",
{"SingerId", "VenueId", "EventDate", "Revenue", "LastUpdateTime"})
.EmplaceRow(1, 4, spanner::Date(2017, 10, 5), 11000,
spanner::CommitTimestamp{})
.EmplaceRow(1, 19, spanner::Date(2017, 11, 2), 15000,
spanner::CommitTimestamp{})
.EmplaceRow(2, 42, spanner::Date(2017, 12, 23), 7000,
spanner::CommitTimestamp{})
.Build()};
});
auto commit_result = client.Commit(spanner::Mutations{
spanner::InsertOrUpdateMutationBuilder(
"Performances",
{"SingerId", "VenueId", "EventDate", "Revenue", "LastUpdateTime"})
.EmplaceRow(1, 4, spanner::Date(2017, 10, 5), 11000,
spanner::CommitTimestamp{})
.EmplaceRow(1, 19, spanner::Date(2017, 11, 2), 15000,
spanner::CommitTimestamp{})
.EmplaceRow(2, 42, spanner::Date(2017, 12, 23), 7000,
spanner::CommitTimestamp{})
.Build()});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
Expand All @@ -838,15 +830,13 @@ void InsertDataWithTimestamp(google::cloud::spanner::Client client) {
// [START spanner_update_data_with_timestamp_column]
void UpdateDataWithTimestamp(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
auto commit_result = client.Commit([](spanner::Transaction const&) {
return spanner::Mutations{
spanner::UpdateMutationBuilder(
"Albums",
{"SingerId", "AlbumId", "MarketingBudget", "LastUpdateTime"})
.EmplaceRow(1, 1, 1000000, spanner::CommitTimestamp{})
.EmplaceRow(2, 2, 750000, spanner::CommitTimestamp{})
.Build()};
});
auto commit_result = client.Commit(spanner::Mutations{
spanner::UpdateMutationBuilder(
"Albums",
{"SingerId", "AlbumId", "MarketingBudget", "LastUpdateTime"})
.EmplaceRow(1, 1, 1000000, spanner::CommitTimestamp{})
.EmplaceRow(2, 2, 750000, spanner::CommitTimestamp{})
.Build()});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
Expand Down Expand Up @@ -1348,16 +1338,14 @@ void DmlStructs(google::cloud::spanner::Client client) {
//! [START spanner_write_data_for_struct_queries]
void WriteDataForStructQueries(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
auto commit_result = client.Commit([](spanner::Transaction const&) {
return spanner::Mutations{
spanner::InsertMutationBuilder("Singers",
{"SingerId", "FirstName", "LastName"})
.EmplaceRow(6, "Elena", "Campbell")
.EmplaceRow(7, "Gabriel", "Wright")
.EmplaceRow(8, "Benjamin", "Martinez")
.EmplaceRow(9, "Hannah", "Harris")
.Build()};
});
auto commit_result = client.Commit(
spanner::Mutations{spanner::InsertMutationBuilder(
"Singers", {"SingerId", "FirstName", "LastName"})
.EmplaceRow(6, "Elena", "Campbell")
.EmplaceRow(7, "Gabriel", "Wright")
.EmplaceRow(8, "Benjamin", "Martinez")
.EmplaceRow(9, "Hannah", "Harris")
.Build()});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
Expand Down