Skip to content

Commit dfc8d6d

Browse files
authored
Fix commit task in standlone mode. (#540)
1 parent dd31566 commit dfc8d6d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

libs/server/StoreWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ async Task CommitTask(int commitFrequencyMs, ILogger logger = null, Cancellation
317317
if (token.IsCancellationRequested) break;
318318

319319
// if we are replica and in auto-commit - do not commit as it will clobber the AOF addresses
320-
if (serverOptions.EnableFastCommit && clusterProvider.IsReplica())
320+
if (serverOptions.EnableFastCommit && (clusterProvider?.IsReplica() ?? false))
321321
{
322322
await Task.Delay(commitFrequencyMs, token);
323323
}

test/Garnet.test/RespAofTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ public void AofUpsertStoreAutoCommitRecoverTest()
9898
}
9999
}
100100

101+
[Test]
102+
[Timeout(10_000)]
103+
public void AofUpsertStoreCommitTaskRecoverTest()
104+
{
105+
server.Dispose(false);
106+
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, tryRecover: false, enableAOF: true, commitFrequencyMs: 100);
107+
server.Start();
108+
109+
using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()))
110+
{
111+
var db = redis.GetDatabase(0);
112+
db.StringSet("SeAofUpsertRecoverTestKey1", "SeAofUpsertRecoverTestValue1");
113+
db.StringSet("SeAofUpsertRecoverTestKey2", "SeAofUpsertRecoverTestValue2");
114+
}
115+
116+
server.Store.WaitForCommit();
117+
server.Dispose(false);
118+
server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, tryRecover: true, enableAOF: true);
119+
server.Start();
120+
121+
using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()))
122+
{
123+
var db = redis.GetDatabase(0);
124+
var recoveredValue = db.StringGet("SeAofUpsertRecoverTestKey1");
125+
Assert.AreEqual("SeAofUpsertRecoverTestValue1", recoveredValue.ToString());
126+
recoveredValue = db.StringGet("SeAofUpsertRecoverTestKey2");
127+
Assert.AreEqual("SeAofUpsertRecoverTestValue2", recoveredValue.ToString());
128+
}
129+
}
130+
101131
[Test]
102132
public void AofUpsertStoreAutoCommitCommitWaitRecoverTest()
103133
{

0 commit comments

Comments
 (0)