Skip to content

Commit e83455c

Browse files
committed
chore: cleanup
1 parent 56d667e commit e83455c

File tree

27 files changed

+239
-692
lines changed

27 files changed

+239
-692
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
on:
2+
workflow_dispatch:
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
name: Build and Release Google.Cloud.SpannerLib.Native
7+
jobs:
8+
build-linux-x64:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Install Go
12+
uses: actions/setup-go@v5
13+
with:
14+
go-version: 1.24
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
- name: Build shared library
18+
working-directory: spannerlib
19+
run: go build -o spannerlib.so -buildmode=c-shared
20+
- name: Upload linux-x64
21+
uses: actions/upload-artifact@v4
22+
with:
23+
name: spannerlib-linux-x64
24+
path: spannerlib/spannerlib.so
25+
build-osx-arm64:
26+
runs-on: macos-latest
27+
steps:
28+
- name: Install Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version: 1.24
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
- name: Build shared library
35+
working-directory: spannerlib
36+
run: go build -o spannerlib.dylib -buildmode=c-shared
37+
- name: Upload osx-arm64
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: spannerlib-osx-arm64
41+
path: spannerlib/spannerlib.dylib
42+
build-and-package:
43+
needs: [build-linux-x64, build-osx-arm64]
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
- name: Download and copy linux-x64
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: spannerlib-linux-x64
52+
path: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native/libraries/linux-x64/
53+
- name: Download and copy osx-arm64
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: spannerlib-osx-arm64
57+
path: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native/libraries/osx-arm64/
58+
- name: Install dotnet
59+
uses: actions/setup-dotnet@v4
60+
with:
61+
dotnet-version: '9.0.x'
62+
- name: dotnet version
63+
run: dotnet --version
64+
- name: Build native library package
65+
run: dotnet pack
66+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native
67+
- name: Add package source
68+
run: dotnet nuget add source "$PWD"/bin/Release --name local
69+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native
70+
- name: Restore dependencies
71+
run: dotnet restore
72+
working-directory: spannerlib/dotnet-spannerlib
73+
- name: Build
74+
run: dotnet build --no-restore
75+
working-directory: spannerlib/dotnet-spannerlib
76+
- name: Unit Tests
77+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Tests
78+
run: dotnet test --no-build --verbosity normal
79+
- name: Publish SpannerLib.Native to nuget
80+
run: dotnet nuget push bin/Release/Experimental.SpannerLib.Native.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
81+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native
82+
- name: Build SpannerLib
83+
run: dotnet pack
84+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib
85+
- name: Publish SpannerLib to nuget
86+
run: dotnet nuget push bin/Release/Experimental.SpannerLib.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
87+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib

.github/workflows/spanner-lib-tests.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go-version: [1.23.x, 1.24.x]
13+
go-version: [1.24.x]
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515
runs-on: ${{ matrix.os }}
1616
steps:
@@ -27,7 +27,7 @@ jobs:
2727
build-lib:
2828
strategy:
2929
matrix:
30-
go-version: [1.23.x, 1.24.x]
30+
go-version: [1.24.x]
3131
os: [ubuntu-latest, macos-latest, windows-latest]
3232
runs-on: ${{ matrix.os }}
3333
steps:
@@ -41,7 +41,7 @@ jobs:
4141
working-directory: spannerlib
4242
run: go build -o spannerlib.so -buildmode=c-shared
4343

44-
test-dotnet:
44+
test-dotnet-ubuntu:
4545
runs-on: ubuntu-latest
4646
steps:
4747
- name: Install Go
@@ -55,13 +55,21 @@ jobs:
5555
run: go build -o spannerlib.so -buildmode=c-shared
5656
- name: Copy lib to dotnet folder
5757
working-directory: spannerlib
58-
run: cp spannerlib.so dotnet-spannerlib/Google.Cloud.SpannerLib/native/linux-x64/spannerlib.so
58+
run: |
59+
mkdir -p dotnet-spannerlib/Google.Cloud.SpannerLib.Native/libraries/any
60+
cp spannerlib.so dotnet-spannerlib/Google.Cloud.SpannerLib.Native/libraries/any/spannerlib.so
5961
- name: Install dotnet
6062
uses: actions/setup-dotnet@v4
6163
with:
6264
dotnet-version: '9.0.x'
6365
- name: dotnet version
6466
run: dotnet --version
67+
- name: Build native library package
68+
run: dotnet pack
69+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native
70+
- name: Add package source
71+
run: dotnet nuget add source "$PWD"/bin/Release --name local
72+
working-directory: spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native
6573
- name: Restore dependencies
6674
run: dotnet restore
6775
working-directory: spannerlib/dotnet-spannerlib

conn.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"google.golang.org/api/iterator"
3131
"google.golang.org/grpc/codes"
3232
"google.golang.org/grpc/status"
33+
"google.golang.org/protobuf/types/known/timestamppb"
3334
)
3435

3536
// SpannerConn is the public interface for the raw Spanner connection for the
@@ -173,6 +174,10 @@ type SpannerConn interface {
173174
// was executed on the connection, or an error if the connection has not executed a read/write transaction
174175
// that committed successfully. The timestamp is in the local timezone.
175176
CommitTimestamp() (commitTimestamp time.Time, err error)
177+
// CommitResponse returns the commit response of the last implicit or explicit read/write transaction that
178+
// was executed on the connection, or an error if the connection has not executed a read/write transaction
179+
// that committed successfully.
180+
CommitResponse() (*spannerpb.CommitResponse, error)
176181

177182
// UnderlyingClient returns the underlying Spanner client for the database.
178183
// The client cannot be used to access the current transaction or batch on
@@ -278,6 +283,15 @@ func (c *conn) CommitTimestamp() (time.Time, error) {
278283
return *c.commitTs, nil
279284
}
280285

286+
func (c *conn) CommitResponse() (*spannerpb.CommitResponse, error) {
287+
if c.commitTs == nil {
288+
return nil, spanner.ToSpannerError(status.Error(codes.FailedPrecondition, "this connection has not executed a read/write transaction that committed successfully"))
289+
}
290+
// TODO: Return the complete commit response
291+
ts := timestamppb.New(*c.commitTs)
292+
return &spannerpb.CommitResponse{CommitTimestamp: ts}, nil
293+
}
294+
281295
func (c *conn) RetryAbortsInternally() bool {
282296
return c.retryAborts
283297
}

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Native/Google.Cloud.SpannerLib.Native.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
<PackageId>Experimental.SpannerLib.Native</PackageId>
99
<Title>Experimental native library for Spanner</Title>
1010
<Authors />
11+
<Version>1.0.3</Version>
1112
</PropertyGroup>
1213

1314
<ItemGroup>
14-
<None Include="libraries/linux-x64/spannerlib.so" Pack="true" PackagePath="runtimes/linux-x64/native/" />
15-
<None Include="libraries/osx-arm64/spannerlib.dylib" Pack="true" PackagePath="runtimes/osx-arm64/native/" />
15+
<None Include="libraries/any/*" Pack="true" PackagePath="runtimes/any/native/" />
16+
<None Include="libraries/linux-x64/*" Pack="true" PackagePath="runtimes/linux-x64/native/" />
17+
<None Include="libraries/osx-arm64/*" Pack="true" PackagePath="runtimes/osx-arm64/native/" />
1618
</ItemGroup>
1719

1820
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# Determine OS + Arch
3+
export DEST=libraries/any/spannerlib
4+
mkdir -p libraries/any
5+
6+
# Clear all local nuget cache
7+
dotnet nuget locals --clear all
8+
go build -o ../../spannerlib.so -buildmode=c-shared ../../
9+
cp ../../spannerlib.so $DEST
10+
dotnet pack
11+
dotnet nuget remove source local 2>/dev/null
12+
dotnet nuget add source "$PWD"/bin/Release --name local
Binary file not shown.
Binary file not shown.

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Tests/BasicTests.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ public void Teardown()
2525
[Test]
2626
public void TestCreatePool()
2727
{
28-
var pool = LibPool.Create(ConnectionString);
28+
var pool = Pool.Create(ConnectionString);
2929
pool.Close();
3030
}
3131

3232
[Test]
3333
public void TestCreateConnection()
3434
{
35-
using var pool = LibPool.Create(ConnectionString);
35+
using var pool = Pool.Create(ConnectionString);
3636
var connection = pool.CreateConnection();
3737
connection.Close();
3838
}
3939

4040
[Test]
4141
public void TestExecuteQuery()
4242
{
43-
using var pool = LibPool.Create(ConnectionString);
43+
using var pool = Pool.Create(ConnectionString);
4444
using var connection = pool.CreateConnection();
4545
using var rows = connection.Execute(new ExecuteSqlRequest { Sql = "SELECT 1" });
4646
for (var row = rows.Next(); row != null; row = rows.Next())
@@ -54,7 +54,7 @@ public void TestExecuteQuery()
5454
[Test]
5555
public void TestReadOnlyTransaction()
5656
{
57-
using var pool = LibPool.Create(ConnectionString);
57+
using var pool = Pool.Create(ConnectionString);
5858
using var connection = pool.CreateConnection();
5959
using var transaction = connection.BeginTransaction(new TransactionOptions
6060
{ ReadOnly = new TransactionOptions.Types.ReadOnly() });
@@ -65,19 +65,22 @@ public void TestReadOnlyTransaction()
6565
Assert.That(row.Values[0].HasStringValue);
6666
Assert.That(row.Values[0].StringValue, Is.EqualTo("1"));
6767
}
68+
var commitResponse = transaction.Commit();
69+
Assert.That(commitResponse, Is.Not.Null);
6870
}
6971

7072
[Test]
7173
public void TestReadWriteTransaction()
7274
{
7375
var sql = "update table1 set value='one' where id=1";
7476
_fixture.SpannerMock.AddOrUpdateStatementResult(sql, StatementResult.CreateUpdateCount(1));
75-
using var pool = LibPool.Create(ConnectionString);
77+
using var pool = Pool.Create(ConnectionString);
7678
using var connection = pool.CreateConnection();
7779
using var transaction = connection.BeginTransaction(new TransactionOptions
7880
{ ReadWrite = new TransactionOptions.Types.ReadWrite() });
7981
using var rows = transaction.Execute(new ExecuteSqlRequest { Sql = sql });
8082
Assert.That(rows.UpdateCount, Is.EqualTo(1));
81-
transaction.Commit();
83+
var commitResponse = transaction.Commit();
84+
Assert.That(commitResponse, Is.Not.Null);
8285
}
8386
}

spannerlib/dotnet-spannerlib/Google.Cloud.SpannerLib.Tests/MockServer/MockSpannerServer.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ public class MockSpannerService : V1.Spanner.SpannerBase
224224
{
225225
private class PartialResultSetsEnumerable : IEnumerable<PartialResultSet>
226226
{
227-
private readonly Transaction _transaction;
227+
private readonly V1.Transaction _transaction;
228228
private readonly ResultSet _resultSet;
229-
public PartialResultSetsEnumerable(Transaction transaction, ResultSet resultSet)
229+
public PartialResultSetsEnumerable(V1.Transaction transaction, ResultSet resultSet)
230230
{
231231
_transaction = transaction;
232232
_resultSet = resultSet;
@@ -247,13 +247,13 @@ private class PartialResultSetsEnumerator : IEnumerator<PartialResultSet>
247247
{
248248
private static readonly int s_maxRowsInChunk = 1;
249249

250-
private readonly Transaction _transaction;
250+
private readonly V1.Transaction _transaction;
251251
private readonly ResultSet _resultSet;
252252
private bool _first = true;
253253
private int _currentRow;
254254
private PartialResultSet _current;
255255

256-
public PartialResultSetsEnumerator(Transaction transaction, ResultSet resultSet)
256+
public PartialResultSetsEnumerator(V1.Transaction transaction, ResultSet resultSet)
257257
{
258258
_transaction = transaction;
259259
_resultSet = resultSet;
@@ -315,7 +315,7 @@ public void Dispose()
315315
private int _sessionCounter;
316316
private int _transactionCounter;
317317
private readonly ConcurrentDictionary<SessionName, Session> _sessions = new();
318-
private readonly ConcurrentDictionary<ByteString, Transaction> _transactions = new();
318+
private readonly ConcurrentDictionary<ByteString, V1.Transaction> _transactions = new();
319319
private readonly ConcurrentDictionary<ByteString, TransactionOptions> _transactionOptions = new();
320320
private readonly ConcurrentDictionary<ByteString, bool> _abortedTransactions = new();
321321
private bool _abortNextStatement;
@@ -387,13 +387,13 @@ public void Reset()
387387
AddDialectResult();
388388
}
389389

390-
public override Task<Transaction> BeginTransaction(BeginTransactionRequest request, ServerCallContext context)
390+
public override Task<V1.Transaction> BeginTransaction(BeginTransactionRequest request, ServerCallContext context)
391391
{
392392
_requests.Enqueue(request);
393393
_contexts.Enqueue(context);
394394
_headers.Enqueue(context.RequestHeaders);
395395
TryFindSession(request.SessionAsSessionName);
396-
Transaction tx = new Transaction();
396+
V1.Transaction tx = new V1.Transaction();
397397
var id = Interlocked.Increment(ref _transactionCounter);
398398
tx.Id = ByteString.CopyFromUtf8($"{request.SessionAsSessionName}/transactions/{id}");
399399
_transactions.TryAdd(tx.Id, tx);
@@ -463,7 +463,7 @@ internal static RpcException CreateDatabaseNotFoundException(string name)
463463
return rpc;
464464
}
465465

466-
private Transaction TryFindTransaction(ByteString id, Boolean remove = false)
466+
private V1.Transaction TryFindTransaction(ByteString id, Boolean remove = false)
467467
{
468468
if (_abortedTransactions.TryGetValue(id, out bool aborted) && aborted)
469469
{
@@ -477,14 +477,14 @@ private Transaction TryFindTransaction(ByteString id, Boolean remove = false)
477477
throw CreateAbortedException("Next statement was aborted");
478478
}
479479
}
480-
if (remove ? _transactions.TryRemove(id, out Transaction tx) : _transactions.TryGetValue(id, out tx))
480+
if (remove ? _transactions.TryRemove(id, out V1.Transaction tx) : _transactions.TryGetValue(id, out tx))
481481
{
482482
return tx;
483483
}
484484
throw new RpcException(new Grpc.Core.Status(StatusCode.NotFound, $"Transaction not found: {id.ToBase64()}"));
485485
}
486486

487-
private Transaction FindOrBeginTransaction(SessionName session, TransactionSelector selector)
487+
private V1.Transaction FindOrBeginTransaction(SessionName session, TransactionSelector selector)
488488
{
489489
if (selector == null)
490490
{
@@ -500,9 +500,9 @@ private Transaction FindOrBeginTransaction(SessionName session, TransactionSelec
500500
};
501501
}
502502

503-
private Transaction BeginTransaction(SessionName session, TransactionOptions options, bool singleUse)
503+
private V1.Transaction BeginTransaction(SessionName session, TransactionOptions options, bool singleUse)
504504
{
505-
Transaction tx = new Transaction();
505+
V1.Transaction tx = new V1.Transaction();
506506
var id = Interlocked.Increment(ref _transactionCounter);
507507
tx.Id = ByteString.CopyFromUtf8($"{session}/transactions/{id}");
508508
if (options.ModeCase == TransactionOptions.ModeOneofCase.ReadOnly && options.ReadOnly.ReturnReadTimestamp)
@@ -662,7 +662,7 @@ public override async Task ExecuteStreamingSql(ExecuteSqlRequest request, IServe
662662
}
663663
executionTime?.SimulateExecutionTime();
664664
TryFindSession(request.SessionAsSessionName);
665-
Transaction returnTransaction = null;
665+
V1.Transaction returnTransaction = null;
666666
var transaction = FindOrBeginTransaction(request.SessionAsSessionName, request.Transaction);
667667
if (request.Transaction != null && (request.Transaction.SelectorCase == TransactionSelector.SelectorOneofCase.Begin || request.Transaction.SelectorCase == TransactionSelector.SelectorOneofCase.SingleUse))
668668
{
@@ -690,7 +690,7 @@ public override async Task ExecuteStreamingSql(ExecuteSqlRequest request, IServe
690690
}
691691
}
692692

693-
private async Task WriteResultSet(Transaction transaction, ResultSet resultSet, IServerStreamWriter<PartialResultSet> responseStream, ExecutionTime executionTime)
693+
private async Task WriteResultSet(V1.Transaction transaction, ResultSet resultSet, IServerStreamWriter<PartialResultSet> responseStream, ExecutionTime executionTime)
694694
{
695695
int index = 0;
696696
PartialResultSetsEnumerable enumerator = new PartialResultSetsEnumerable(transaction, resultSet);
@@ -712,7 +712,7 @@ private async Task WriteResultSet(Transaction transaction, ResultSet resultSet,
712712
}
713713
}
714714

715-
private async Task WriteUpdateCount(Transaction transaction, long updateCount, IServerStreamWriter<PartialResultSet> responseStream)
715+
private async Task WriteUpdateCount(V1.Transaction transaction, long updateCount, IServerStreamWriter<PartialResultSet> responseStream)
716716
{
717717
PartialResultSet prs = new PartialResultSet
718718
{

0 commit comments

Comments
 (0)