|
11 | 11 |
|
12 | 12 | namespace Garnet.cluster
|
13 | 13 | {
|
14 |
| - internal sealed class ReplicationLogCheckpointManager( |
15 |
| - INamedDeviceFactoryCreator deviceFactoryCreator, |
16 |
| - ICheckpointNamingScheme checkpointNamingScheme, |
17 |
| - bool isMainStore, |
18 |
| - bool removeOutdated = false, |
19 |
| - int fastCommitThrottleFreq = 0, |
20 |
| - ILogger logger = null) : DeviceLogCommitCheckpointManager(deviceFactoryCreator, checkpointNamingScheme, removeOutdated: false, fastCommitThrottleFreq, logger), IDisposable |
| 14 | + internal sealed class ReplicationLogCheckpointManager : DeviceLogCommitCheckpointManager, IDisposable |
21 | 15 | {
|
22 | 16 | public long CurrentSafeAofAddress = 0;
|
23 | 17 | public long RecoveredSafeAofAddress = 0;
|
24 | 18 |
|
25 | 19 | public string CurrentReplicationId = string.Empty;
|
26 | 20 | public string RecoveredReplicationId = string.Empty;
|
27 | 21 |
|
28 |
| - readonly bool isMainStore = isMainStore; |
| 22 | + readonly bool isMainStore; |
29 | 23 | public Action<bool, long, long, bool> checkpointVersionShiftStart;
|
30 | 24 | public Action<bool, long, long, bool> checkpointVersionShiftEnd;
|
31 | 25 |
|
32 |
| - readonly bool safelyRemoveOutdated = removeOutdated; |
| 26 | + readonly bool safelyRemoveOutdated; |
33 | 27 |
|
34 |
| - readonly ILogger logger = logger; |
| 28 | + readonly ILogger logger; |
| 29 | + |
| 30 | + public ReplicationLogCheckpointManager( |
| 31 | + INamedDeviceFactoryCreator deviceFactoryCreator, |
| 32 | + ICheckpointNamingScheme checkpointNamingScheme, |
| 33 | + bool isMainStore, |
| 34 | + bool safelyRemoveOutdated = false, |
| 35 | + int fastCommitThrottleFreq = 0, |
| 36 | + ILogger logger = null) |
| 37 | + : base(deviceFactoryCreator, checkpointNamingScheme, removeOutdated: false, fastCommitThrottleFreq, logger) |
| 38 | + { |
| 39 | + this.isMainStore = isMainStore; |
| 40 | + this.safelyRemoveOutdated = safelyRemoveOutdated; |
| 41 | + this.createCookieDelegate = CreateCookie; |
| 42 | + this.logger = logger; |
| 43 | + |
| 44 | + // Pre-append cookie in commitMetadata. |
| 45 | + // cookieMetadata 52 bytes |
| 46 | + // 1. 4 bytes to track size of cookie |
| 47 | + // 2. 8 bytes for checkpointCoveredAddress |
| 48 | + // 3. 40 bytes for primaryReplicationId |
| 49 | + unsafe byte[] CreateCookie() |
| 50 | + { |
| 51 | + var cookie = new byte[sizeof(int) + sizeof(long) + CurrentReplicationId.Length]; |
| 52 | + var primaryReplIdBytes = Encoding.ASCII.GetBytes(CurrentReplicationId); |
| 53 | + fixed (byte* ptr = cookie) |
| 54 | + fixed (byte* pridPtr = primaryReplIdBytes) |
| 55 | + { |
| 56 | + *(int*)ptr = sizeof(long) + CurrentReplicationId.Length; |
| 57 | + *(long*)(ptr + 4) = CurrentSafeAofAddress; |
| 58 | + Buffer.MemoryCopy(pridPtr, ptr + 12, primaryReplIdBytes.Length, primaryReplIdBytes.Length); |
| 59 | + } |
| 60 | + return cookie; |
| 61 | + } |
| 62 | + } |
35 | 63 |
|
36 | 64 | public override void CheckpointVersionShiftStart(long oldVersion, long newVersion, bool isStreaming)
|
37 | 65 | => checkpointVersionShiftStart?.Invoke(isMainStore, oldVersion, newVersion, isStreaming);
|
@@ -63,31 +91,6 @@ public IDevice GetDevice(CheckpointFileType retStateType, Guid fileToken)
|
63 | 91 |
|
64 | 92 | #region ICheckpointManager
|
65 | 93 |
|
66 |
| - /// <summary> |
67 |
| - /// Pre-append cookie in commitMetadata. |
68 |
| - /// cookieMetadata 52 bytes |
69 |
| - /// 1. 4 bytes to track size of cookie |
70 |
| - /// 2. 8 bytes for checkpointCoveredAddress |
71 |
| - /// 3. 40 bytes for primaryReplicationId |
72 |
| - /// </summary> |
73 |
| - /// <returns></returns> |
74 |
| - private unsafe byte[] CreateCookie() |
75 |
| - { |
76 |
| - var cookie = new byte[sizeof(int) + sizeof(long) + CurrentReplicationId.Length]; |
77 |
| - var primaryReplIdBytes = Encoding.ASCII.GetBytes(CurrentReplicationId); |
78 |
| - fixed (byte* ptr = cookie) |
79 |
| - fixed (byte* pridPtr = primaryReplIdBytes) |
80 |
| - { |
81 |
| - *(int*)ptr = sizeof(long) + CurrentReplicationId.Length; |
82 |
| - *(long*)(ptr + 4) = CurrentSafeAofAddress; |
83 |
| - Buffer.MemoryCopy(pridPtr, ptr + 12, primaryReplIdBytes.Length, primaryReplIdBytes.Length); |
84 |
| - } |
85 |
| - return cookie; |
86 |
| - } |
87 |
| - |
88 |
| - /// <inheritdoc /> |
89 |
| - public override byte[] GetCookie() => CreateCookie(); |
90 |
| - |
91 | 94 | private HybridLogRecoveryInfo ConverMetadata(byte[] checkpointMetadata)
|
92 | 95 | {
|
93 | 96 | var success = true;
|
|
0 commit comments