Skip to content

Commit 63fdc08

Browse files
authored
Safe tail refresh for scanning uncommitted TsavoriteLog (#687)
* Periodic safe tail refresh for scanning uncommitted TsavoriteLog * nit * fix * use SWARE * Improve logic and clean up names, add config for pub-sub * Fix tsavorite * fixes * fix ScanUncommittedTest * SafeTail refresh is needed only if replication is enabled * added comments * nit
1 parent ec5a46a commit 63fdc08

File tree

9 files changed

+219
-100
lines changed

9 files changed

+219
-100
lines changed

libs/host/Configuration/Options.cs

+9
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ internal sealed class Options
194194
[Option("aof-size-limit", Required = false, HelpText = "Maximum size of AOF (rounds down to power of 2) after which unsafe truncation will be applied. Left empty AOF will grow without bound unless a checkpoint is taken")]
195195
public string AofSizeLimit { get; set; }
196196

197+
[IntRangeValidation(0, int.MaxValue)]
198+
[Option("aof-refresh-freq", Required = false, HelpText = "AOF replication (safe tail address) refresh frequency in milliseconds. 0 = auto refresh after every enqueue.")]
199+
public int AofReplicationRefreshFrequencyMs { get; set; }
200+
201+
[IntRangeValidation(0, int.MaxValue)]
202+
[Option("subscriber-refresh-freq", Required = false, HelpText = "Subscriber (safe tail address) refresh frequency in milliseconds (for pub-sub). 0 = auto refresh after every enqueue.")]
203+
public int SubscriberRefreshFrequencyMs { get; set; }
204+
197205
[IntRangeValidation(0, int.MaxValue)]
198206
[Option("compaction-freq", Required = false, HelpText = "Background hybrid log compaction frequency in seconds. 0 = disabled (compaction performed before checkpointing instead)")]
199207
public int CompactionFrequencySecs { get; set; }
@@ -588,6 +596,7 @@ public GarnetServerOptions GetServerOptions(ILogger logger = null)
588596
LuaTransactionMode = LuaTransactionMode.GetValueOrDefault(),
589597
AofMemorySize = AofMemorySize,
590598
AofPageSize = AofPageSize,
599+
AofReplicationRefreshFrequencyMs = AofReplicationRefreshFrequencyMs,
591600
CommitFrequencyMs = CommitFrequencyMs,
592601
WaitForCommit = WaitForCommit.GetValueOrDefault(),
593602
AofSizeLimit = AofSizeLimit,

libs/host/GarnetServer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private void InitializeServer()
190190
CreateObjectStore(clusterFactory, customCommandManager, checkpointDir, out var objectStoreSizeTracker);
191191

192192
if (!opts.DisablePubSub)
193-
subscribeBroker = new SubscribeBroker<SpanByte, SpanByte, IKeySerializer<SpanByte>>(new SpanByteKeySerializer(), null, opts.PubSubPageSizeBytes(), true);
193+
subscribeBroker = new SubscribeBroker<SpanByte, SpanByte, IKeySerializer<SpanByte>>(new SpanByteKeySerializer(), null, opts.PubSubPageSizeBytes(), opts.SubscriberRefreshFrequencyMs, true);
194194

195195
CreateAOF();
196196

libs/host/defaults.conf

+6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@
123123
/* Size of each AOF page in bytes(rounds down to power of 2) */
124124
"AofPageSize" : "4m",
125125

126+
/* AOF replication (safe tail address) refresh frequency in milliseconds. 0 = auto refresh after every enqueue. */
127+
"AofReplicationRefreshFrequencyMs": 10,
128+
129+
/* Subscriber (safe tail address) refresh frequency in milliseconds (for pub-sub). 0 = auto refresh after every enqueue. */
130+
"SubscriberRefreshFrequencyMs": 0,
131+
126132
/* Write ahead logging (append-only file) commit issue frequency in milliseconds. 0 = issue an immediate commit per operation, -1 = manually issue commits using COMMITAOF command */
127133
"CommitFrequencyMs" : 0,
128134

libs/server/PubSub/SubscribeBroker.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ public sealed class SubscribeBroker<TKey, TValue, TKeyValueSerializer> : IDispos
3939
/// <param name="keySerializer">Serializer for Prefix Match and serializing Key</param>
4040
/// <param name="logDir">Directory where the log will be stored</param>
4141
/// <param name="pageSize">Page size of log used for pub/sub</param>
42+
/// <param name="subscriberRefreshFrequencyMs">Subscriber log refresh frequency</param>
4243
/// <param name="startFresh">start the log from scratch, do not continue</param>
43-
public SubscribeBroker(IKeySerializer<TKey> keySerializer, string logDir, long pageSize, bool startFresh = true)
44+
public SubscribeBroker(IKeySerializer<TKey> keySerializer, string logDir, long pageSize, int subscriberRefreshFrequencyMs, bool startFresh = true)
4445
{
4546
this.keySerializer = keySerializer;
4647
device = logDir == null ? new NullDevice() : Devices.CreateLogDevice(logDir + "/pubsubkv", preallocateFile: false);
4748
device.Initialize((long)(1 << 30) * 64);
48-
log = new TsavoriteLog(new TsavoriteLogSettings { LogDevice = device, PageSize = pageSize, MemorySize = pageSize * 4, AutoRefreshSafeTailAddress = true });
49+
log = new TsavoriteLog(new TsavoriteLogSettings { LogDevice = device, PageSize = pageSize, MemorySize = pageSize * 4, SafeTailRefreshFrequencyMs = subscriberRefreshFrequencyMs });
4950
if (startFresh)
5051
log.TruncateUntil(log.CommittedUntilAddress);
5152
}

libs/server/Servers/GarnetServerOptions.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ public class GarnetServerOptions : ServerOptions
9292
/// </summary>
9393
public string AofPageSize = "4m";
9494

95+
/// <summary>
96+
/// AOF replication (safe tail address) refresh frequency in milliseconds. 0 = auto refresh after every enqueue.
97+
/// </summary>
98+
public int AofReplicationRefreshFrequencyMs = 10;
99+
100+
/// <summary>
101+
/// Subscriber (safe tail address) refresh frequency in milliseconds (for pub-sub). 0 = auto refresh after every enqueue.
102+
/// </summary>
103+
public int SubscriberRefreshFrequencyMs = 0;
104+
95105
/// <summary>
96106
/// Write ahead logging (append-only file) commit issue frequency in milliseconds.
97107
/// 0 = issue an immediate commit per operation
@@ -616,7 +626,7 @@ public void GetAofSettings(out TsavoriteLogSettings tsavoriteLogSettings)
616626
PageSizeBits = AofPageSizeBits(),
617627
LogDevice = GetAofDevice(),
618628
TryRecoverLatest = false,
619-
AutoRefreshSafeTailAddress = true,
629+
SafeTailRefreshFrequencyMs = EnableCluster ? AofReplicationRefreshFrequencyMs : -1,
620630
FastCommitMode = EnableFastCommit,
621631
AutoCommit = CommitFrequencyMs == 0,
622632
MutableFraction = 0.9,

0 commit comments

Comments
 (0)