/// <summary> /// TransactionId and CommandPartition are serializable. /// </summary> private async Task DistributedReadWorkerAsync(CommandPartition readPartition, TransactionId id) { //note: we only use state provided by the arguments here. using (var connection = new SpannerConnection(id.ConnectionString)) using (var transaction = connection.BeginReadOnlyTransaction(id)) { using (var cmd = connection.CreateCommandWithPartition(readPartition, transaction)) { using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) { while (await reader.ReadAsync()) { Interlocked.Increment(ref _rowsRead); } } } } }
private async Task DistributedReadWorkerAsync(CommandPartition readPartition, TransactionId id) { var localId = Interlocked.Increment(ref _partitionCount); using var connection = new SpannerConnection(id.ConnectionString); using var transaction = connection.BeginReadOnlyTransaction(id); using var cmd = connection.CreateCommandWithPartition(readPartition, transaction); using var reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { Interlocked.Increment(ref _rowsRead); Console.WriteLine($"Partition ({localId}) " + $"{reader.GetFieldValue<int>("SingerId")}" + $" {reader.GetFieldValue<string>("FirstName")}" + $" {reader.GetFieldValue<string>("LastName")}"); } Console.WriteLine($"Done with single reader {localId}."); }