Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion samples/EntglDb.Test.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public static MauiApp CreateMauiApp()
{
NodeId = $"CHANGEME-{nodeId}",
TcpPort = 5001,
AuthToken = "Test-Cluster-Key"
AuthToken = "Test-Cluster-Key",
OplogRetentionHours = 2,
MaintenanceIntervalMinutes = 5
});

builder.Services.AddSingleton(peerNodeConfigurationProvider);
Expand Down
10 changes: 10 additions & 0 deletions src/EntglDb.Core/Network/PeerNodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public class PeerNodeConfiguration
/// </summary>
public int RetryDelayMs { get; set; } = 1000;

/// <summary>
/// Interval between periodic maintenance operations (Oplog pruning) in minutes. Default: 60 minutes.
/// </summary>
public int MaintenanceIntervalMinutes { get; set; } = 60;

/// <summary>
/// Oplog retention period in hours. Entries older than this will be pruned. Default: 24 hours.
/// </summary>
public int OplogRetentionHours { get; set; } = 24;

/// <summary>
/// Gets the default configuration settings for a peer node.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions src/EntglDb.Core/Storage/IPeerStore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using EntglDb.Core; // Added for ChangesAppliedEventArgs
Expand Down Expand Up @@ -107,4 +108,40 @@ public interface IPeerStore
/// <param name="nodeId">The unique identifier of the peer to remove.</param>
/// <param name="cancellationToken">Cancellation token.</param>
Task RemoveRemotePeerAsync(string nodeId, CancellationToken cancellationToken = default);

// Snapshot & Maintenance routines

/// <summary>
/// Prunes the oplog, removing entries older than the specified timestamp.
/// Preserves the latest state in SnapshotMetadata to maintain chain continuity.
/// </summary>
Task PruneOplogAsync(HlcTimestamp cutoff, CancellationToken cancellationToken = default);

/// <summary>
/// Creates a full snapshot of the underlying database and writes it to the destination stream.
/// </summary>
Task CreateSnapshotAsync(Stream destination, CancellationToken cancellationToken = default);

/// <summary>
/// Replaces the underlying database with the provided stream.
/// This is used for full sync/snapshot recovery.
/// WARNING: This will overwrite all local data.
/// </summary>
Task ReplaceDatabaseAsync(Stream databaseStream, CancellationToken cancellationToken = default);

/// <summary>
/// Merges a remote snapshot into the local database without overwriting existing data.
/// Used for Split-Brain resolution.
/// </summary>
Task MergeSnapshotAsync(Stream snapshotStream, CancellationToken cancellationToken = default);

/// <summary>
/// Clears all data from the store, resetting it to an empty state.
/// </summary>
Task ClearAllDataAsync(CancellationToken cancellationToken = default);
}

public class CorruptDatabaseException : Exception
{
public CorruptDatabaseException(string message, Exception innerException) : base(message, innerException) { }
}
Loading