Recover managed process log sessions

This commit is contained in:
npc0-hue
2026-08-31 12:16:44 +08:00
parent d5f4d34e07
commit 4277791cb7
6 changed files with 165 additions and 5 deletions
+45
View File
@@ -157,6 +157,37 @@ func TestLogSpoolFlushPrioritizesNewerProcessSessions(t *testing.T) {
}
}
func TestLogSpoolSequenceGapResetsWatermarkToPlatformLatest(t *testing.T) {
logSpool, err := NewLogSpool(t.TempDir())
if err != nil {
t.Fatalf("new log spool: %v", err)
}
if err := logSpool.Enqueue(validSpoolLogBatch(10, 10)); err != nil {
t.Fatalf("enqueue gapped batch: %v", err)
}
if err := logSpool.Enqueue(validSpoolLogBatch(11, 11)); err != nil {
t.Fatalf("enqueue later gapped batch: %v", err)
}
client := &recoveringSequenceGapLogBatchClient{latestSeq: 5}
flushed, err := logSpool.Flush(context.Background(), client)
if err != nil || flushed != 2 {
t.Fatalf("recover sequence gap: flushed=%d err=%v", flushed, err)
}
if len(client.progressBatches) != 1 || client.progressBatches[0].FirstSeq != 10 {
t.Fatalf("expected one progress recovery from gapped batch, got %+v", client.progressBatches)
}
pending, err := logSpool.Pending()
if err != nil || len(pending) != 0 {
t.Fatalf("expected gapped batches rejected, pending=%+v err=%v", pending, err)
}
checksum := func(entries []protocol.LogEntry) (string, error) { return fmt.Sprintf("sha256:%d", len(entries)), nil }
next := validSpoolLogBatch(0, 0)
sequence, appended, err := logSpool.EnqueueNextAggregated(context.Background(), next, nil, nil, checksum)
if err != nil || !appended || sequence != 6 {
t.Fatalf("expected next sequence to resume after platform latest, sequence=%d appended=%t err=%v", sequence, appended, err)
}
}
func TestLogSpoolRestoresPendingAllocationWithoutWatermark(t *testing.T) {
root := t.TempDir()
first, err := NewLogSpool(root)
@@ -298,9 +329,23 @@ func (client *blockingLogBatchClient) IngestLogBatch(_ context.Context, batch pr
type permanentRejectLogBatchClient struct{}
func (permanentRejectLogBatchClient) IngestLogBatch(context.Context, protocol.LogBatchIngestRequest) (protocol.LogBatchIngestResponse, error) {
return protocol.LogBatchIngestResponse{}, PermanentLogBatchRejection("platform_not_found", nil)
}
type recoveringSequenceGapLogBatchClient struct {
latestSeq uint64
progressBatches []protocol.LogBatchIngestRequest
}
func (client *recoveringSequenceGapLogBatchClient) IngestLogBatch(context.Context, protocol.LogBatchIngestRequest) (protocol.LogBatchIngestResponse, error) {
return protocol.LogBatchIngestResponse{}, PermanentLogBatchRejection("platform_sequence_gap", nil)
}
func (client *recoveringSequenceGapLogBatchClient) LogStreamLatestSeq(_ context.Context, batch protocol.LogBatchIngestRequest) (uint64, error) {
client.progressBatches = append(client.progressBatches, batch)
return client.latestSeq, nil
}
type recordingLogBatchClient struct {
batches []protocol.LogBatchIngestRequest
}