Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -165,16 +165,19 @@ public async Task<MembershipTableData> ReadAllAsync(CancellationToken cancellati
try
{
var collection = this._storage.GetCollection();
// A single RunQuery stream includes rows and version in one strongly consistent snapshot.
var snapshot = await FirestoreDataManager.ExecuteWithCancellation(
collection.GetSnapshotAsync(cancellationToken), cancellationToken);
var versionSnapshot = snapshot.Documents.SingleOrDefault(document => document.Id == this._partitionId)
?? throw new KeyNotFoundException($"Could not find cluster version entry for {this._partitionId}");
var silos = snapshot.Documents
.Where(document => document.Id != this._partitionId)
.Select(document => document.ConvertTo<SiloInstanceEntity>())
.ToArray();
var data = Convert((silos, versionSnapshot.ConvertTo<ClusterVersionEntity>()));
var entries = await this._storage.ExecuteTransaction(async transaction =>
{
// The transaction binds every streamed document to one serializable snapshot.
var snapshot = await transaction.GetSnapshotAsync(collection, transaction.CancellationToken);
var versionSnapshot = snapshot.Documents.SingleOrDefault(document => document.Id == this._partitionId)
?? throw new KeyNotFoundException($"Could not find cluster version entry for {this._partitionId}");
var silos = snapshot.Documents
.Where(document => document.Id != this._partitionId)
.Select(document => document.ConvertTo<SiloInstanceEntity>())
.ToArray();
return (silos, versionSnapshot.ConvertTo<ClusterVersionEntity>());
}, cancellationToken);
var data = Convert(entries);
LogReadAll(data);

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,16 +838,22 @@ public async Task MembershipReadsUseOneStrongNativeSnapshot(bool readAll)
Assert.Equal(7, result.Version.Version);
Assert.Equal(entry.SiloAddress, Assert.Single(result.Members).Item1.SiloAddress);
Assert.Equal(Now, Assert.Single(result.Members).Item1.IAmAliveTime);
Assert.Equal(0, client.Transactions);
Assert.Empty(client.Commits);
if (readAll)
{
AssertSingleStrongQuery(client);
Assert.Equal(1, client.Transactions);
var query = Assert.Single(client.Queries);
Assert.Equal(RunQueryRequest.ConsistencySelectorOneofCase.Transaction, query.ConsistencySelectorCase);
Assert.False(query.Transaction.IsEmpty);
Assert.Equal(2, client.QueryDocumentReads);
Assert.Empty(client.Reads);
var commit = Assert.Single(client.Commits);
Assert.Equal(query.Transaction, commit.Transaction);
Assert.Empty(commit.Writes);
}
else
{
Assert.Equal(0, client.Transactions);
Assert.Empty(client.Commits);
var read = Assert.Single(client.Reads);
Assert.Equal(new[] { VersionPath, RowPath(entry) }, read.Documents);
Assert.Equal(BatchGetDocumentsRequest.ConsistencySelectorOneofCase.None, read.ConsistencySelectorCase);
Expand All @@ -867,8 +873,15 @@ public async Task MembershipReadsConsumeOneSnapshotDuringStreamedChanges(bool re
document.UpdateTime = Timestamp.FromDateTime(DateTime.UnixEpoch.AddSeconds(2));
var rowETag = ETag(document);
var token = ETag(client.Documents[VersionPath]);
var changed = false;
client.AfterFirstReadResponse = () =>
{
if (changed)
{
return;
}

changed = true;
client.Change(document.Name, nameof(SiloInstanceEntity.ProxyPort), new Value { IntegerValue = 8 });
client.Change(document.Name, nameof(SiloInstanceEntity.MembershipVersion), new Value { IntegerValue = 8 });
client.Change(VersionPath, nameof(ClusterVersionEntity.MembershipVersion), new Value { IntegerValue = 8 });
Expand All @@ -879,15 +892,35 @@ public async Task MembershipReadsConsumeOneSnapshotDuringStreamedChanges(bool re
? await table.ReadAllAsync(TestContext.Current.CancellationToken)
: await table.ReadRowAsync(entry.SiloAddress, TestContext.Current.CancellationToken);

Assert.Equal(7, result.Version.Version);
Assert.Equal(token, result.Version.VersionEtag);
var row = Assert.Single(result.Members);
Assert.Equal(7, row.Item1.ProxyPort);
Assert.Equal(rowETag, row.Item2);
Assert.Equal(8, client.Documents[VersionPath].Fields[nameof(ClusterVersionEntity.MembershipVersion)].IntegerValue);
Assert.Equal(0, client.Transactions);
Assert.Empty(client.Commits);
Assert.Equal(1, client.Reads.Count + client.Queries.Count);
if (readAll)
{
Assert.Equal(8, result.Version.Version);
Assert.Equal(8, row.Item1.ProxyPort);
Assert.Equal(2, client.Transactions);
Assert.Equal(2, client.Queries.Count);
Assert.Equal(2, client.Commits.Count);
Assert.Empty(client.Reads);
Comment thread
ReubenBond marked this conversation as resolved.
Resolved
Assert.All(client.Queries, query =>
{
Assert.Equal(RunQueryRequest.ConsistencySelectorOneofCase.Transaction, query.ConsistencySelectorCase);
Assert.False(query.Transaction.IsEmpty);
});
Assert.Equal(client.Queries.Select(query => query.Transaction), client.Commits.Select(commit => commit.Transaction));
Assert.All(client.Commits, commit => Assert.Empty(commit.Writes));
}
else
{
Assert.Equal(7, result.Version.Version);
Assert.Equal(token, result.Version.VersionEtag);
Assert.Equal(7, row.Item1.ProxyPort);
Assert.Equal(rowETag, row.Item2);
Assert.Equal(0, client.Transactions);
Assert.Empty(client.Commits);
Assert.Single(client.Reads);
Assert.Empty(client.Queries);
}
}

[Theory]
Expand All @@ -905,9 +938,14 @@ await Assert.ThrowsAsync<KeyNotFoundException>(() => readAll
? table.ReadAllAsync(TestContext.Current.CancellationToken)
: table.ReadRowAsync(entry.SiloAddress, TestContext.Current.CancellationToken));

Assert.Equal(0, client.Transactions);
Assert.Empty(client.Commits);
Assert.Equal(1, client.Reads.Count + client.Queries.Count);
Assert.Equal(readAll ? 1 : 0, client.Transactions);
if (readAll)
{
var query = Assert.Single(client.Queries);
Assert.Equal(RunQueryRequest.ConsistencySelectorOneofCase.Transaction, query.ConsistencySelectorCase);
}
}

[Fact]
Expand Down Expand Up @@ -943,7 +981,7 @@ public async Task MembershipReadsPropagateNativeFailures(bool readAll, StatusCod
: table.ReadRowAsync(Entry().SiloAddress, TestContext.Current.CancellationToken));

Assert.Same(failure, exception);
Assert.Equal(0, client.Transactions);
Assert.Equal(readAll ? 1 : 0, client.Transactions);
Assert.Empty(client.Commits);
Assert.Equal(1, client.Reads.Count + client.Queries.Count);
}
Expand All @@ -969,7 +1007,7 @@ public async Task NativeMembershipOperationsNormalizeCallerCancellation(string o

Assert.Same(failure, exception.InnerException);
Assert.Equal(cancellation.Token, exception.CancellationToken);
Assert.Equal(0, client.Transactions);
Assert.Equal(operation == "ReadAll" ? 1 : 0, client.Transactions);
Assert.Equal(1, client.Reads.Count + client.Queries.Count + client.Commits.Count);
Assert.Empty(client.CommittedWrites);

Expand Down
Loading