Skip to content

Commit 88ba46e

Browse files
committed
fix: Leaderboard samples that were misusing Spanner.
Fixes b/411692913
1 parent 68a229b commit 88ba46e

File tree

8 files changed

+69
-27
lines changed

8 files changed

+69
-27
lines changed

applications/leaderboard/Leaderboard.sln

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommandLineUtil", "..\..\co
1010
EndProject
1111
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "testutil", "..\..\testutil\testutil.csproj", "{FCB84A33-4D8F-4721-91C0-30A411A14486}"
1212
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeaderboardStep4", "step4\LeaderboardStep4.csproj", "{95B6A630-5912-CBFA-3FA9-A73ED825ED03}"
14+
EndProject
15+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeaderboardStep5", "step5\LeaderboardStep5.csproj", "{8F9E72F4-0D70-7794-35FF-1FDD43498A88}"
16+
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeaderboardStep6", "step6\LeaderboardStep6.csproj", "{2246F57D-81CD-2F41-E9E8-723816A109FB}"
18+
EndProject
1319
Global
1420
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1521
Debug|Any CPU = Debug|Any CPU
@@ -68,6 +74,42 @@ Global
6874
{FCB84A33-4D8F-4721-91C0-30A411A14486}.Release|x64.Build.0 = Release|Any CPU
6975
{FCB84A33-4D8F-4721-91C0-30A411A14486}.Release|x86.ActiveCfg = Release|Any CPU
7076
{FCB84A33-4D8F-4721-91C0-30A411A14486}.Release|x86.Build.0 = Release|Any CPU
77+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
78+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Debug|Any CPU.Build.0 = Debug|Any CPU
79+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Debug|x64.ActiveCfg = Debug|Any CPU
80+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Debug|x64.Build.0 = Debug|Any CPU
81+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Debug|x86.ActiveCfg = Debug|Any CPU
82+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Debug|x86.Build.0 = Debug|Any CPU
83+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Release|Any CPU.ActiveCfg = Release|Any CPU
84+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Release|Any CPU.Build.0 = Release|Any CPU
85+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Release|x64.ActiveCfg = Release|Any CPU
86+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Release|x64.Build.0 = Release|Any CPU
87+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Release|x86.ActiveCfg = Release|Any CPU
88+
{95B6A630-5912-CBFA-3FA9-A73ED825ED03}.Release|x86.Build.0 = Release|Any CPU
89+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
90+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Debug|Any CPU.Build.0 = Debug|Any CPU
91+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Debug|x64.ActiveCfg = Debug|Any CPU
92+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Debug|x64.Build.0 = Debug|Any CPU
93+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Debug|x86.ActiveCfg = Debug|Any CPU
94+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Debug|x86.Build.0 = Debug|Any CPU
95+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Release|Any CPU.ActiveCfg = Release|Any CPU
96+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Release|Any CPU.Build.0 = Release|Any CPU
97+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Release|x64.ActiveCfg = Release|Any CPU
98+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Release|x64.Build.0 = Release|Any CPU
99+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Release|x86.ActiveCfg = Release|Any CPU
100+
{8F9E72F4-0D70-7794-35FF-1FDD43498A88}.Release|x86.Build.0 = Release|Any CPU
101+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Debug|x64.ActiveCfg = Debug|Any CPU
104+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Debug|x64.Build.0 = Debug|Any CPU
105+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Debug|x86.ActiveCfg = Debug|Any CPU
106+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Debug|x86.Build.0 = Debug|Any CPU
107+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
108+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Release|Any CPU.Build.0 = Release|Any CPU
109+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Release|x64.ActiveCfg = Release|Any CPU
110+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Release|x64.Build.0 = Release|Any CPU
111+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Release|x86.ActiveCfg = Release|Any CPU
112+
{2246F57D-81CD-2F41-E9E8-723816A109FB}.Release|x86.Build.0 = Release|Any CPU
71113
EndGlobalSection
72114
GlobalSection(SolutionProperties) = preSolution
73115
HideSolutionNode = FALSE

applications/leaderboard/Leaderboard/Leaderboard.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Google.Cloud.Spanner.Data" Version="4.6.0" />
9+
<PackageReference Include="Google.Cloud.Spanner.Data" Version="5.0.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

applications/leaderboard/Leaderboard/Program.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -223,9 +223,10 @@ await connection.RunWithRetriableTransactionAsync(async (transaction) =>
223223
// for each PlayerName to be inserted.
224224
var cmd = connection.CreateSelectCommand(
225225
@"SELECT Count(PlayerId) as PlayerCount FROM Players");
226+
cmd.Transaction = transaction;
226227
numberOfPlayers = await cmd.ExecuteScalarAsync<long>();
227228
// Insert 100 player records into the Players table.
228-
SpannerBatchCommand cmdBatch = connection.CreateBatchDmlCommand();
229+
SpannerBatchCommand cmdBatch = transaction.CreateBatchDmlCommand();
229230
for (int i = 0; i < 100; i++)
230231
{
231232
numberOfPlayers++;
@@ -264,10 +265,9 @@ await connection.RunWithRetriableTransactionAsync(async (transaction) =>
264265
{
265266
Random r = new Random();
266267
bool playerRecordsFound = false;
267-
SpannerBatchCommand cmdBatch =
268-
connection.CreateBatchDmlCommand();
269-
var cmdLookup =
270-
connection.CreateSelectCommand("SELECT * FROM Players");
268+
SpannerBatchCommand cmdBatch = transaction.CreateBatchDmlCommand();
269+
var cmdLookup = connection.CreateSelectCommand("SELECT * FROM Players");
270+
cmdLookup.Transaction = transaction;
271271
using (var reader = await cmdLookup.ExecuteReaderAsync())
272272
{
273273
while (await reader.ReadAsync())
@@ -395,9 +395,9 @@ public static object Delete(string projectId,
395395
private static async Task DeleteAsync(string projectId,
396396
string instanceId, string databaseId)
397397
{
398-
string AdminConnectionString = $"Data Source=projects/{projectId}/"
398+
string adminConnectionString = $"Data Source=projects/{projectId}/"
399399
+ $"instances/{instanceId}";
400-
using (var connection = new SpannerConnection(AdminConnectionString))
400+
using (var connection = new SpannerConnection(adminConnectionString))
401401
using (var cmd = connection.CreateDdlCommand(
402402
$@"DROP DATABASE {databaseId}"))
403403
{

applications/leaderboard/step4/Leaderboard.csproj renamed to applications/leaderboard/step4/LeaderboardStep4.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Google.Cloud.Spanner.Data" Version="4.6.0" />
9+
<PackageReference Include="Google.Cloud.Spanner.Data" Version="5.0.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

applications/leaderboard/step5/Leaderboard.csproj renamed to applications/leaderboard/step5/LeaderboardStep5.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Google.Cloud.Spanner.Data" Version="4.6.0" />
9+
<PackageReference Include="Google.Cloud.Spanner.Data" Version="5.0.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

applications/leaderboard/step5/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ await connection.RunWithRetriableTransactionAsync(async (transaction) =>
161161
// for each PlayerName to be inserted.
162162
var cmd = connection.CreateSelectCommand(
163163
@"SELECT Count(PlayerId) as PlayerCount FROM Players");
164+
cmd.Transaction = transaction;
164165
numberOfPlayers = await cmd.ExecuteScalarAsync<long>();
165166
// Insert 100 player records into the Players table.
166-
SpannerBatchCommand cmdBatch = connection.CreateBatchDmlCommand();
167+
SpannerBatchCommand cmdBatch = transaction.CreateBatchDmlCommand();
167168
for (int i = 0; i < 100; i++)
168169
{
169170
numberOfPlayers++;
@@ -202,10 +203,9 @@ await connection.RunWithRetriableTransactionAsync(async (transaction) =>
202203
{
203204
Random r = new Random();
204205
bool playerRecordsFound = false;
205-
SpannerBatchCommand cmdBatch =
206-
connection.CreateBatchDmlCommand();
207-
var cmdLookup =
208-
connection.CreateSelectCommand("SELECT * FROM Players");
206+
SpannerBatchCommand cmdBatch = transaction.CreateBatchDmlCommand();
207+
var cmdLookup = connection.CreateSelectCommand("SELECT * FROM Players");
208+
cmdLookup.Transaction = transaction;
209209
using (var reader = await cmdLookup.ExecuteReaderAsync())
210210
{
211211
while (await reader.ReadAsync())
@@ -270,4 +270,4 @@ public static int Main(string[] args)
270270
return (int)verbMap.Run(args);
271271
}
272272
}
273-
}
273+
}

applications/leaderboard/step6/Leaderboard.csproj renamed to applications/leaderboard/step6/LeaderboardStep6.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Google.Cloud.Spanner.Data" Version="4.6.0" />
9+
<PackageReference Include="Google.Cloud.Spanner.Data" Version="5.0.0" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

applications/leaderboard/step6/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,10 @@ await connection.RunWithRetriableTransactionAsync(async (transaction) =>
180180
// for each PlayerName to be inserted.
181181
var cmd = connection.CreateSelectCommand(
182182
@"SELECT Count(PlayerId) as PlayerCount FROM Players");
183+
cmd.Transaction = transaction;
183184
numberOfPlayers = await cmd.ExecuteScalarAsync<long>();
184185
// Insert 100 player records into the Players table.
185-
SpannerBatchCommand cmdBatch = connection.CreateBatchDmlCommand();
186+
SpannerBatchCommand cmdBatch = transaction.CreateBatchDmlCommand();
186187
for (int i = 0; i < 100; i++)
187188
{
188189
numberOfPlayers++;
@@ -221,10 +222,9 @@ await connection.RunWithRetriableTransactionAsync(async (transaction) =>
221222
{
222223
Random r = new Random();
223224
bool playerRecordsFound = false;
224-
SpannerBatchCommand cmdBatch =
225-
connection.CreateBatchDmlCommand();
226-
var cmdLookup =
227-
connection.CreateSelectCommand("SELECT * FROM Players");
225+
SpannerBatchCommand cmdBatch = transaction.CreateBatchDmlCommand();
226+
var cmdLookup = connection.CreateSelectCommand("SELECT * FROM Players");
227+
cmdLookup.Transaction = transaction;
228228
using (var reader = await cmdLookup.ExecuteReaderAsync())
229229
{
230230
while (await reader.ReadAsync())
@@ -350,4 +350,4 @@ public static int Main(string[] args)
350350
return (int)verbMap.Run(args);
351351
}
352352
}
353-
}
353+
}

0 commit comments

Comments
 (0)