Skip to content

Commit 7dd983c

Browse files
committed
Join text-generation retirement before exposing the physical census
Remove the retired manager entry under the existing physical gate after native close, directory deletion and shared-reservation settlement. Exercise a real current search at that lifecycle boundary; the case failed with Corruption before the repair. Observe surviving Orleans membership before healthy post-kill time-series reads. Preserve the failed-write assertions and all-copy restart receipts. Validated on .NET SDK 10.0.403: format and verification, complete Debug build with warnings as errors, governance, 16 focused search cases, the real time-series kill/restart case, all 2986 compiled functional identities and five selectors, and seven compiled CI inventory checks. Fresh ONE and the competing-owner three-node scenario continue separately; Linux qualification remains required.
1 parent ddd478a commit 7dd983c

7 files changed

Lines changed: 116 additions & 3 deletions

File tree

‎docs/Features/Search/OnlineGenerationLifetime.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ publication, cancellation of one reader while another completes, and invalidatio
2424
with a held reader followed by repeated healthy rebuilds under a one-generation
2525
physical bound. These are local operation checks, not competitor measurements.
2626

27+
Successful retirement removes the retired manager entry while still holding the existing physical gate that deleted its directory and settled its shared reservation. A current-generation read can overlap retirement, but its physical census never observes a deleted directory through a stale retired entry. The real `RetiredGenerationDeleted` boundary is observed after that joined transition, outside the gate. `TextGenerationRetirementTests` starts a current SearchEngine read at that boundary, checks the exact replacement result, joined old-reader cleanup, one retained current generation and healthy continuation. A failed close, delete or reservation settlement still retains its actual unsettled owner.
28+
2729

2830
Capacity preflight must not reopen the published WAL while its index still owns that file. Inside the physical gate it captures only the manager's at most three actual generation references. An exact manager-owned, published generation with a still-open index receives a bounded live ownership/layout/size preflight without reopening payload files: root, leaf, source node and scope are verified against the retained generation and owner/manifest metadata, unknown, linked, nonregular or foreign paths are rejected, and all file, depth, generation and aggregate-byte ceilings are kept. Every tracked file is inspected without reopening, a current file over MaximumDiskBytes is rejected, and a live file length is not compared with its closed manifest length. Runtime generation references cannot be supplied by a caller, inferred from a sharing exception or replaced by a trusted-leaf list; every other generation keeps the complete checksum validation, and publication, reopen, retirement, deletion and restart keep exact lengths and checksums. The final aggregate census in `RuntimeTextProjection.Release` follows the same completed-operation rule as `TextSettlement.Refresh`: an incomplete or cancelled operation settles without consulting its exhausted caller budget while keeping all real file, byte and generation ceilings and distinct cleanup errors.
2931

‎docs/Features/TimeSeries.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ normative contract remains the ADR and this Feature.
7575
| REQ-SERIES-009: complete raw half-open aggregate using published library | AC-SERIES-009: count/sum/min/max/raw average match independent reference for late/dedup/negative/empty/offset/date edges; null end includes MaxValue; finite overflow rejects safely | SampleAggregateTests and cluster SDK/MCP oracle; /CLUSTER-W8 |
7676
| REQ-SERIES-010: bounded dense UTC windows | AC-SERIES-010: anchor From, positive fixed Width, empty windows, final clamping, raw weighted average, date-edge arithmetic and caller/server window cap checked before allocation | SampleAggregateWindowTests and SDK/MCP windows; /CLUSTER-W8 |
7777
| REQ-SERIES-011: one complete operation/security budget | AC-SERIES-011: positive caller caps, a sample lookahead beyond the cap fails the whole aggregate, metadata/raw reads and deadline/cancel share one view; current SeriesRead, projected latest tags and revocation; failures preserve data and healthy next reads | SampleAggregateBudgetTests, SampleAggregateAuthorizationTests and real cluster persisted-authority cases; /CLUSTER-W8 |
78-
| REQ-SERIES-012: typed public operations preserve real cluster request isolation | AC-SERIES-012.NET/HTTP/official MCP same results/errors/discovery schemas; old enum values preserved; genuine follower kill/restart retains results across all live replicas | TimeSeries cluster integration, typed round trips and official MCP discovery; /CLUSTER-W8 |
78+
| REQ-SERIES-012: typed public operations preserve real cluster request isolation | AC-SERIES-012.NET/HTTP/official MCP same results/errors/discovery schemas; old enum values preserved; genuine follower kill/restart retains results across all live replicas; healthy survivor reads begin after the existing membership observer sees the surviving silos, and post-restart writes wait for every configured copy | TimeSeries cluster integration, typed round trips and official MCP discovery; `TimeSeriesClusterReplicaRestartTests`; /CLUSTER-W8 |
7979

8080
Slice map: Abstractions/Features/TimeSeries read/result DTOs;
8181
Core/Features/TimeSeries private readers/accumulator and public static

‎scripts/Features/CodeQuality/functional-coverage.unit-test-inventory.json‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43776,6 +43776,26 @@
4377643776
"AC-LEASE-004"
4377743777
]
4377843778
},
43779+
{
43780+
"className": "KeyLoad.FunctionalTests.Search.TextGenerationRetirementTests",
43781+
"reportClassName": "KeyLoad.FunctionalTests.Search.TextGenerationRetirementTests",
43782+
"methodName": "CurrentSearchRemainsReadableAtTheRetiredDirectoryDeletionBoundary",
43783+
"instanceName": "CurrentSearchRemainsReadableAtTheRetiredDirectoryDeletionBoundary",
43784+
"sourcePath": "tests/KeyLoad.FunctionalTests/Search/Cases/RuntimeText/ReadCuts/TextGenerationRetirementTests.cs",
43785+
"sourceSha256": "785d26acb56209042a85876a1e17e1d721f44ea9c37dc5fa2fba4113575fd4ca",
43786+
"lineNumber": 15,
43787+
"endLineNumber": 61,
43788+
"classification": "functional",
43789+
"exclusionReason": null,
43790+
"requirements": [
43791+
"REQ-LEASE-002",
43792+
"REQ-LEASE-003"
43793+
],
43794+
"acceptance": [
43795+
"AC-LEASE-002",
43796+
"AC-LEASE-003"
43797+
]
43798+
},
4377943799
{
4378043800
"className": "KeyLoad.FunctionalTests.Search.TextIncrementalCorruptionTests",
4378143801
"reportClassName": "KeyLoad.FunctionalTests.Search.TextIncrementalCorruptionTests",
@@ -63141,6 +63161,7 @@
6314163161
"KeyLoad.FunctionalTests.Search.TextGenerationAdmissionTests",
6314263162
"KeyLoad.FunctionalTests.Search.TextGenerationCapacityTests",
6314363163
"KeyLoad.FunctionalTests.Search.TextGenerationLifetimeTests",
63164+
"KeyLoad.FunctionalTests.Search.TextGenerationRetirementTests",
6314463165
"KeyLoad.FunctionalTests.Search.TextProjectionLeaseTests",
6314563166
"KeyLoad.FunctionalTests.Search.ThreeWayHybridFusionTests",
6314663167
"KeyLoad.FunctionalTests.StorageRecovery.ActionStagingTests",
@@ -63614,6 +63635,7 @@
6361463635
"KeyLoad.FunctionalTests.Search.TextGenerationLifetimeTests|InvalidatedCurrentCanRebuildWhileItsRetiredLeaseRemainsBorrowed|InvalidatedCurrentCanRebuildWhileItsRetiredLeaseRemainsBorrowed",
6361563636
"KeyLoad.FunctionalTests.Search.TextGenerationLifetimeTests|LivePreflightRejectsUnknownEntryAndPreservesTheBorrowedGeneration|LivePreflightRejectsUnknownEntryAndPreservesTheBorrowedGeneration",
6361663637
"KeyLoad.FunctionalTests.Search.TextGenerationLifetimeTests|PublishedReplacementKeepsOldReaderUntilItsLastLeaseSettles|PublishedReplacementKeepsOldReaderUntilItsLastLeaseSettles",
63638+
"KeyLoad.FunctionalTests.Search.TextGenerationRetirementTests|CurrentSearchRemainsReadableAtTheRetiredDirectoryDeletionBoundary|CurrentSearchRemainsReadableAtTheRetiredDirectoryDeletionBoundary",
6361763639
"KeyLoad.FunctionalTests.Search.TextProjectionLeaseTests|CancellingOnePublishedReaderPreservesAnotherAndFollowingSearch|CancellingOnePublishedReaderPreservesAnotherAndFollowingSearch",
6361863640
"KeyLoad.FunctionalTests.Search.TextProjectionLeaseTests|InvalidatingOneReaderRetainsOthersAndReleasesThePhysicalReservation|InvalidatingOneReaderRetainsOthersAndReleasesThePhysicalReservation",
6361963641
"KeyLoad.FunctionalTests.Search.TextProjectionLeaseTests|PublishedReadersOverlapWithoutClosingAnotherLeaseOrRewritingItsManifest|PublishedReadersOverlapWithoutClosingAnotherLeaseOrRewritingItsManifest",

‎src/KeyLoad/Search/Contracts/FullText/TextFaultStage.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ internal enum TextFaultStage
2626
/// <summary>The actual retained original canonical35 receipt has joined.</summary>
2727
CanonicalOnlinePublicationAcknowledged = 10,
2828
/// <summary>The exact online catalog pending envelope has flushed and passed readback.</summary>
29-
OnlineCatalogPendingFlushed = 11
29+
OnlineCatalogPendingFlushed = 11,
30+
/// <summary>The retired generation's owned files have been deleted.</summary>
31+
RetiredGenerationDeleted = 12
3032
}

‎src/KeyLoad/Search/Storage/FullText/Projections/RuntimeTextProjectionLifecycle.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ internal void Publish(TextGeneration generation, ReadExecutionBudget budget)
9898
internal void Retire(TextGenerationSlot slot)
9999
{
100100
Exception? failure = null;
101+
var retirementRecorded = false;
101102
try
102103
{
103104
var generation = slot.Generation ?? throw TextErrors.Corrupt();
@@ -110,7 +111,10 @@ internal void Retire(TextGenerationSlot slot)
110111
generation.DisposeIndex();
111112
TextFiles.DeleteOwnedGeneration(Root, generation.Leaf, SourceNodeId, executionOptions: executionOptions, resources: resources);
112113
slot.SharedReservation?.CompleteAfterJoinedCleanup();
114+
retirementRecorded = true;
115+
state.CompleteRetirement(slot, null);
113116
});
117+
faultObserver?.Invoke(TextFaultStage.RetiredGenerationDeleted);
114118
}
115119
catch (Exception error)
116120
{
@@ -119,7 +123,10 @@ internal void Retire(TextGenerationSlot slot)
119123
}
120124
finally
121125
{
122-
state.CompleteRetirement(slot, failure);
126+
if (!retirementRecorded)
127+
{
128+
state.CompleteRetirement(slot, failure);
129+
}
123130
}
124131
}
125132

‎tests/KeyLoad.ClusterTests/TimeSeries/Cases/TimeSeriesClusterReplicaRestartTests.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ [new AppendSamples(TimeSeriesClusterScenario.Set, TimeSeriesClusterScenario.Seri
5656
await Assert.That(unavailable.Problem?.ErrorCode is nameof(ErrorCode.OwnershipLost)
5757
or nameof(ErrorCode.UnknownWriteOutcome)).IsTrue();
5858

59+
await ClusterMembershipReadiness.WaitForActiveSilosAsync(
60+
[.. clients.Where((_, index) => index != selectedIndex)], deadline.Token);
5961
var initial = ClusterReplicationTestSupport.Success(await clients[survivorIndex].ReadLatestSampleAsync(
6062
scenario.Latest(), deadline.Token));
6163
// OwnershipLost refuses before any copy applies the batch; UnknownWriteOutcome means the surviving copies may
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using KeyLoad.Query;
2+
using KeyLoad.Query.Search;
3+
using KeyLoad.Server.Search;
4+
using KeyLoad.Storage;
5+
6+
namespace KeyLoad.FunctionalTests.Search;
7+
8+
internal sealed class TextGenerationRetirementTests
9+
{
10+
private const string Collection = "text-retirement-publication";
11+
private const string Field = "/text";
12+
private const string Term = "needle";
13+
private const string Revised = """{"text":"needle revised"}""";
14+
15+
[Test]
16+
public async Task CurrentSearchRemainsReadableAtTheRetiredDirectoryDeletionBoundary()
17+
{
18+
using var database = new TestDatabase();
19+
database.Configure(Collection, ResourceKind.Collection);
20+
database.Commit(new PutDocument(Collection, "one", """{"text":"needle original"}"""));
21+
var cleanup = new TextGenerationFixtureLifetime();
22+
await cleanup.RunAsync(async () =>
23+
{
24+
var root = Path.Combine(database.Directory, "text-retirement-publication");
25+
var token = TestContext.Current!.Execution.CancellationToken;
26+
var request = new SearchRequest(database.Partition, Collection, Field, Term);
27+
SearchEngine? engine = null;
28+
Task<RankedDocument[]>? overlapping = null;
29+
var observed = 0;
30+
var projection = cleanup.TrackProjection(new(root, database.Store.Identity.NodeId, UnitTextOptions.Execution(),
31+
faultObserver: stage =>
32+
{
33+
if (stage == TextFaultStage.RetiredGenerationDeleted)
34+
{
35+
observed++;
36+
overlapping = engine!.SearchAsync("root", request, token);
37+
}
38+
}));
39+
engine = new(database.Database, UnitExecutionOptions.QueryExecution(), projection);
40+
var original = await engine.SearchAsync("root", request, token);
41+
var retired = GenerationPaths(root).Single();
42+
var oldBudget = new ReadExecutionBudget();
43+
var retained = cleanup.TrackLease(projection.Acquire(CaptureScope(database), oldBudget));
44+
retained.BeginRecord(original[0].Document.Reference, original[0].Document.Revision);
45+
retained.ObserveToken(Term);
46+
database.Commit(new PutDocument(Collection, "one", Revised));
47+
var replacement = await engine.SearchAsync("root", request, token);
48+
retained.VerifyCandidates([Term], [original[0].Document.Reference], oldBudget);
49+
cleanup.SettleLease(retained);
50+
await Assert.That(observed).IsEqualTo(1);
51+
var actual = await (overlapping ?? throw new InvalidOperationException("The retirement boundary did not start its current read."));
52+
await Assert.That(actual).HasSingleItem();
53+
await Assert.That(actual[0].Document.Revision).IsEqualTo(2L);
54+
await Assert.That(actual[0].Document.Json).IsEqualTo(Revised);
55+
await Assert.That(JsonDefaults.Serialize(actual).AsSpan().SequenceEqual(JsonDefaults.Serialize(replacement))).IsTrue();
56+
await Assert.That(Directory.Exists(retired)).IsFalse();
57+
await Assert.That(GenerationPaths(root).Length).IsEqualTo(1);
58+
var healthy = await engine.SearchAsync("root", request, token);
59+
await Assert.That(JsonDefaults.Serialize(healthy).AsSpan().SequenceEqual(JsonDefaults.Serialize(replacement))).IsTrue();
60+
});
61+
}
62+
63+
private static string[] GenerationPaths(string root)
64+
=> Directory.EnumerateDirectories(root)
65+
.Where(path => Path.GetFileName(path).StartsWith(TextProtocol.GenerationPrefix, StringComparison.Ordinal))
66+
.Order(StringComparer.Ordinal).ToArray();
67+
68+
private static TextProjectionScope CaptureScope(TestDatabase database)
69+
{
70+
var identity = database.Store.Identity;
71+
var principal = database.Store.Read(view => view.GetRecord<PrincipalRecord>(KeySpace.Principal("root")))!;
72+
var resource = database.Store.Read(view => view.GetRecord<ResourceDefinition>(KeySpace.Resource(
73+
database.Partition.TenantId, database.Partition.DatabaseId, Collection)))!;
74+
return new(identity.NodeId, identity.Incarnation, identity.FormatVersion, identity.ReadGeneration,
75+
database.Store.Position, database.Partition, Collection, Field, principal.Id, principal.PolicyEpoch,
76+
resource.SchemaVersion);
77+
}
78+
}

0 commit comments

Comments
 (0)