forked from microsoft/FASTER
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncTests.cs
More file actions
181 lines (146 loc) · 6.1 KB
/
AsyncTests.cs
File metadata and controls
181 lines (146 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using FASTER.core;
using System.IO;
using NUnit.Framework;
using FASTER.test.recovery.sumstore;
namespace FASTER.test.async
{
[TestFixture]
public class RecoveryTests
{
private FasterKV<AdId, NumClicks, AdInput, Output, Empty, SimpleFunctions> fht1;
private FasterKV<AdId, NumClicks, AdInput, Output, Empty, SimpleFunctions> fht2;
private IDevice log;
[TestCase(CheckpointType.FoldOver)]
[TestCase(CheckpointType.Snapshot)]
public async Task AsyncRecoveryTest1(CheckpointType checkpointType)
{
log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\SimpleRecoveryTest2.log", deleteOnClose: true);
Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "\\checkpoints4");
fht1 = new FasterKV
<AdId, NumClicks, AdInput, Output, Empty, SimpleFunctions>
(128, new SimpleFunctions(),
logSettings: new LogSettings { LogDevice = log, MutableFraction = 0.1, PageSizeBits = 10, MemorySizeBits = 13 },
checkpointSettings: new CheckpointSettings { CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints4", CheckPointType = checkpointType }
);
fht2 = new FasterKV
<AdId, NumClicks, AdInput, Output, Empty, SimpleFunctions>
(128, new SimpleFunctions(),
logSettings: new LogSettings { LogDevice = log, MutableFraction = 0.1, PageSizeBits = 10, MemorySizeBits = 13 },
checkpointSettings: new CheckpointSettings { CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints4", CheckPointType = checkpointType }
);
int numOps = 5000;
var inputArray = new AdId[numOps];
for (int i = 0; i < numOps; i++)
{
inputArray[i].adId = i;
}
NumClicks value;
AdInput inputArg = default;
Output output = default;
var s0 = fht1.NewSession();
var s1 = fht1.NewSession();
var s2 = fht1.NewSession();
for (int key = 0; key < numOps; key++)
{
value.numClicks = key;
s1.Upsert(ref inputArray[key], ref value, Empty.Default, key);
}
for (int key = 0; key < numOps; key++)
{
value.numClicks = key;
s2.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, key);
}
// does not require session
fht1.TakeFullCheckpoint(out _);
await fht1.CompleteCheckpointAsync();
s2.CompletePending(true);
fht1.TakeFullCheckpoint(out Guid token);
await fht1.CompleteCheckpointAsync();
s2.Dispose();
s1.Dispose();
s0.Dispose();
fht1.Dispose();
fht2.Recover(token); // sync, does not require session
var guid = s1.ID;
using (var s3 = fht2.ResumeSession(guid, out CommitPoint lsn))
{
Assert.IsTrue(lsn.UntilSerialNo == numOps - 1);
for (int key = 0; key < numOps; key++)
{
var status = s3.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, 0);
if (status == Status.PENDING)
s3.CompletePending(true);
else
{
Assert.IsTrue(output.value.numClicks == key);
}
}
}
fht2.Dispose();
log.Close();
new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "\\checkpoints4").Delete(true);
}
}
public class SimpleFunctions : IFunctions<AdId, NumClicks, AdInput, Output, Empty>
{
public void RMWCompletionCallback(ref AdId key, ref AdInput input, Empty ctx, Status status)
{
}
public void ReadCompletionCallback(ref AdId key, ref AdInput input, ref Output output, Empty ctx, Status status)
{
Assert.IsTrue(status == Status.OK);
Assert.IsTrue(output.value.numClicks == key.adId);
}
public void UpsertCompletionCallback(ref AdId key, ref NumClicks input, Empty ctx)
{
}
public void DeleteCompletionCallback(ref AdId key, Empty ctx)
{
}
public void CheckpointCompletionCallback(string sessionId, CommitPoint commitPoint)
{
Console.WriteLine("Session {0} reports persistence until {1}", sessionId, commitPoint.UntilSerialNo);
}
// Read functions
public void SingleReader(ref AdId key, ref AdInput input, ref NumClicks value, ref Output dst)
{
dst.value = value;
}
public void ConcurrentReader(ref AdId key, ref AdInput input, ref NumClicks value, ref Output dst)
{
dst.value = value;
}
// Upsert functions
public void SingleWriter(ref AdId key, ref NumClicks src, ref NumClicks dst)
{
dst = src;
}
public bool ConcurrentWriter(ref AdId key, ref NumClicks src, ref NumClicks dst)
{
dst = src;
return true;
}
// RMW functions
public void InitialUpdater(ref AdId key, ref AdInput input, ref NumClicks value)
{
value = input.numClicks;
}
public bool InPlaceUpdater(ref AdId key, ref AdInput input, ref NumClicks value)
{
Interlocked.Add(ref value.numClicks, input.numClicks.numClicks);
return true;
}
public void CopyUpdater(ref AdId key, ref AdInput input, ref NumClicks oldValue, ref NumClicks newValue)
{
newValue.numClicks += oldValue.numClicks + input.numClicks.numClicks;
}
}
}