Skip to content

Commit 423e6be

Browse files
committed
Add more testing around Gapfiller
1 parent 65d523d commit 423e6be

File tree

8 files changed

+855
-59
lines changed

8 files changed

+855
-59
lines changed

artio-core/src/main/java/uk/co/real_logic/artio/engine/EngineContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,12 @@ private AbstractReplayer replayer()
362362

363363
replayer = new GapFiller(
364364
replayGatewayPublication,
365+
new BufferClaim(),
365366
configuration.agentNamePrefix(),
366367
senderSequenceNumbers,
367368
replayerCommandQueue,
368369
new FixSessionCodecsFactory(clock, configuration.sessionEpochFractionFormat()),
370+
fixCounters.currentReplayCount(),
369371
clock,
370372
fixCounters.getIndexerDutyCycleTracker(configuration.indexerCycleThresholdNs()));
371373
}

artio-core/src/main/java/uk/co/real_logic/artio/engine/logger/AbstractReplayer.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
import org.agrona.concurrent.EpochNanoClock;
2525
import uk.co.real_logic.artio.DebugLogger;
2626
import uk.co.real_logic.artio.LogTag;
27-
import uk.co.real_logic.artio.Pressure;
2827
import uk.co.real_logic.artio.engine.SenderSequenceNumbers;
2928
import uk.co.real_logic.artio.messages.*;
30-
import uk.co.real_logic.artio.util.AsciiBuffer;
3129
import uk.co.real_logic.artio.util.CharFormatter;
32-
import uk.co.real_logic.artio.util.MutableAsciiBuffer;
3330

3431
import java.util.function.Consumer;
3532

@@ -38,12 +35,11 @@
3835

3936
public abstract class AbstractReplayer implements Agent, FragmentHandler
4037
{
41-
private static final int REPLAY_COMPLETE_LEN =
38+
static final int REPLAY_COMPLETE_LEN =
4239
MessageHeaderEncoder.ENCODED_LENGTH + ReplayCompleteEncoder.BLOCK_LENGTH;
4340
static final int START_REPLAY_LENGTH =
4441
MessageHeaderEncoder.ENCODED_LENGTH + StartReplayEncoder.BLOCK_LENGTH;
4542

46-
final AsciiBuffer asciiBuffer = new MutableAsciiBuffer();
4743
final MessageHeaderDecoder messageHeader = new MessageHeaderDecoder();
4844
final ValidResendRequestDecoder validResendRequest = new ValidResendRequestDecoder();
4945
final StartReplayEncoder startReplayEncoder = new StartReplayEncoder();
@@ -88,26 +84,25 @@ public abstract class AbstractReplayer implements Agent, FragmentHandler
8884

8985
boolean trySendStartReplay(final long sessionId, final long connectionId, final long correlationId)
9086
{
91-
final long position = publication.tryClaim(START_REPLAY_LENGTH, bufferClaim);
92-
if (Pressure.isBackPressured(position))
87+
if (publication.tryClaim(START_REPLAY_LENGTH, bufferClaim) > 0)
9388
{
94-
return false;
95-
}
89+
final MutableDirectBuffer buffer = bufferClaim.buffer();
90+
final int offset = bufferClaim.offset();
9691

97-
final MutableDirectBuffer buffer = bufferClaim.buffer();
98-
final int offset = bufferClaim.offset();
92+
startReplayEncoder
93+
.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder)
94+
.session(sessionId)
95+
.connection(connectionId)
96+
.correlationId(correlationId);
9997

100-
startReplayEncoder
101-
.wrapAndApplyHeader(buffer, offset, messageHeaderEncoder)
102-
.session(sessionId)
103-
.connection(connectionId)
104-
.correlationId(correlationId);
98+
DebugLogger.logSbeMessage(REPLAY, startReplayEncoder);
10599

106-
DebugLogger.logSbeMessage(REPLAY, startReplayEncoder);
100+
bufferClaim.commit();
107101

108-
bufferClaim.commit();
102+
return true;
103+
}
109104

110-
return true;
105+
return false;
111106
}
112107

113108
public void onStart()

artio-core/src/main/java/uk/co/real_logic/artio/engine/logger/GapFiller.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.agrona.DirectBuffer;
2222
import org.agrona.collections.Long2ObjectHashMap;
2323
import org.agrona.concurrent.EpochNanoClock;
24+
import org.agrona.concurrent.status.AtomicCounter;
2425
import uk.co.real_logic.artio.builder.Encoder;
2526
import uk.co.real_logic.artio.decoder.AbstractResendRequestDecoder;
2627
import uk.co.real_logic.artio.decoder.SessionHeaderDecoder;
@@ -30,6 +31,7 @@
3031
import uk.co.real_logic.artio.messages.MessageStatus;
3132
import uk.co.real_logic.artio.messages.ValidResendRequestDecoder;
3233
import uk.co.real_logic.artio.protocol.GatewayPublication;
34+
import uk.co.real_logic.artio.util.MutableAsciiBuffer;
3335

3436
import java.util.ArrayDeque;
3537

@@ -45,21 +47,25 @@ public class GapFiller extends AbstractReplayer
4547
private final GatewayPublication publication;
4648
private final String agentNamePrefix;
4749
private final ReplayTimestamper timestamper;
50+
private final AtomicCounter gapfillerCounter;
4851

4952
public GapFiller(
5053
final GatewayPublication publication,
54+
final BufferClaim bufferClaim,
5155
final String agentNamePrefix,
5256
final SenderSequenceNumbers senderSequenceNumbers,
5357
final ReplayerCommandQueue replayerCommandQueue,
5458
final FixSessionCodecsFactory fixSessionCodecsFactory,
59+
final AtomicCounter gapfillerCounter,
5560
final EpochNanoClock clock,
5661
final DutyCycleTracker dutyCycleTracker)
5762
{
58-
super(publication.dataPublication(), fixSessionCodecsFactory, new BufferClaim(), senderSequenceNumbers,
63+
super(publication.dataPublication(), fixSessionCodecsFactory, bufferClaim, senderSequenceNumbers,
5964
clock, dutyCycleTracker);
6065
this.publication = publication;
6166
this.agentNamePrefix = agentNamePrefix;
6267
this.replayerCommandQueue = replayerCommandQueue;
68+
this.gapfillerCounter = gapfillerCounter;
6369

6470
timestamper = new ReplayTimestamper(publication.dataPublication(), clock);
6571
}
@@ -92,27 +98,30 @@ public void onFragment(final DirectBuffer buffer, final int start, final int len
9298
final int endSeqNo = (int)validResendRequest.endSequenceNumber();
9399
final int sequenceIndex = validResendRequest.sequenceIndex();
94100
final long correlationId = validResendRequest.correlationId();
95-
validResendRequest.wrapBody(asciiBuffer);
101+
102+
final MutableAsciiBuffer copiedBuffer = new MutableAsciiBuffer(new byte[validResendRequest.bodyLength()]);
103+
validResendRequest.getBody(copiedBuffer, 0, validResendRequest.bodyLength());
96104

97105
onResendRequest(
98-
sessionId, connectionId, beginSeqNo, endSeqNo, sequenceIndex, correlationId);
106+
sessionId, connectionId, beginSeqNo, endSeqNo, sequenceIndex, correlationId, copiedBuffer);
99107
}
100108
else
101109
{
102110
fixSessionCodecsFactory.onFragment(buffer, start, length, header);
103111
}
104112
}
105113

106-
private void onResendRequest(
114+
void onResendRequest(
107115
final long sessionId,
108116
final long connectionId,
109117
final int beginSeqNo,
110118
final int endSeqNo,
111119
final int sequenceIndex,
112-
final long correlationId)
120+
final long correlationId,
121+
final MutableAsciiBuffer copiedBuffer)
113122
{
114123
final GapFillerSession gapFillerSession = new GapFillerSession(
115-
sessionId, connectionId, beginSeqNo, endSeqNo, sequenceIndex, correlationId);
124+
sessionId, connectionId, beginSeqNo, endSeqNo, sequenceIndex, correlationId, copiedBuffer);
116125

117126
if (gapFillerChannels.containsKey(connectionId))
118127
{
@@ -124,6 +133,7 @@ private void onResendRequest(
124133
final GapFillerChannel gapFillerChannel = new GapFillerChannel();
125134
gapFillerChannel.currentSession(gapFillerSession);
126135
gapFillerChannels.put(connectionId, gapFillerChannel);
136+
gapfillerCounter.increment();
127137
}
128138
}
129139

@@ -157,6 +167,7 @@ private int sendGapfills()
157167
if (checkDisconnected(connectionId))
158168
{
159169
gapFillerChannelIterator.remove();
170+
gapfillerCounter.decrement();
160171
}
161172
else
162173
{
@@ -169,6 +180,7 @@ private int sendGapfills()
169180
if (null == queuedSession)
170181
{
171182
gapFillerChannelIterator.remove();
183+
gapfillerCounter.decrement();
172184
}
173185
else
174186
{
@@ -237,6 +249,7 @@ private enum State
237249
final int endSeqNo;
238250
final int sequenceIndex;
239251
final long correlationId;
252+
final MutableAsciiBuffer copiedBuffer;
240253
private State state;
241254
private FixReplayerCodecs fixReplayerCodecs;
242255

@@ -246,14 +259,16 @@ private enum State
246259
final int beginSeqNo,
247260
final int endSeqNo,
248261
final int sequenceIndex,
249-
final long correlationId)
262+
final long correlationId,
263+
final MutableAsciiBuffer copiedBuffer)
250264
{
251265
this.sessionId = sessionId;
252266
this.connectionId = connectionId;
253267
this.beginSeqNo = beginSeqNo;
254268
this.endSeqNo = endSeqNo;
255269
this.sequenceIndex = sequenceIndex;
256270
this.correlationId = correlationId;
271+
this.copiedBuffer = copiedBuffer;
257272
this.state = State.INIT;
258273
}
259274

@@ -308,7 +323,7 @@ int doWork()
308323
final AbstractResendRequestDecoder resendRequest = fixReplayerCodecs.resendRequest();
309324
final GapFillEncoder encoder = fixReplayerCodecs.gapFillEncoder();
310325

311-
resendRequest.decode(asciiBuffer, 0, asciiBuffer.capacity());
326+
resendRequest.decode(copiedBuffer, 0, copiedBuffer.capacity());
312327

313328
final SessionHeaderDecoder reqHeader = resendRequest.header();
314329

artio-core/src/main/java/uk/co/real_logic/artio/engine/logger/Replayer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class Replayer extends AbstractReplayer
8282
final FixMessageDecoder fixMessageDecoder = new FixMessageDecoder();
8383
final ThrottleRejectDecoder throttleRejectDecoder = new ThrottleRejectDecoder();
8484
final AsciiBuffer sessionAsciiBuffer = new MutableAsciiBuffer();
85+
final AsciiBuffer asciiBuffer = new MutableAsciiBuffer();
8586

8687
// Binary FIXP specific state
8788
private final IntHashSet gapfillOnRetransmitILinkTemplateIds;

0 commit comments

Comments
 (0)