leventov commented on a change in pull request #7038: Fix and document
concurrency of EventReceiverFirehose and TimedShutoffFirehose; Refine
concurrency specification of Firehose
URL: https://github.com/apache/incubator-druid/pull/7038#discussion_r255670437
##########
File path:
server/src/main/java/org/apache/druid/segment/realtime/firehose/EventReceiverFirehoseFactory.java
##########
@@ -453,61 +569,57 @@ public boolean isClosed()
final String producerId = req.getHeader("X-Firehose-Producer-Id");
if (producerId == null) {
- return Optional.empty();
+ return null;
}
final String sequenceValue = req.getHeader("X-Firehose-Producer-Seq");
if (sequenceValue == null) {
- return Optional.of(
- Response.status(Response.Status.BAD_REQUEST)
- .entity(ImmutableMap.<String, Object>of("error",
"Producer sequence value is missing"))
- .build()
- );
+ return Response
+ .status(Response.Status.BAD_REQUEST)
+ .entity(ImmutableMap.<String, Object>of("error", "Producer
sequence value is missing"))
+ .build();
}
Long producerSequence = producerSequences.computeIfAbsent(producerId,
key -> Long.MIN_VALUE);
if (producerSequences.size() >= MAX_FIREHOSE_PRODUCERS) {
- return Optional.of(
- Response.status(Response.Status.FORBIDDEN)
- .entity(
- ImmutableMap.<String, Object>of(
- "error",
- "Too many individual producer IDs for this
firehose. Max is " + MAX_FIREHOSE_PRODUCERS
- )
- )
- .build()
- );
+ return Response
+ .status(Response.Status.FORBIDDEN)
+ .entity(
+ ImmutableMap.of(
+ "error",
+ "Too many individual producer IDs for this firehose. Max
is " + MAX_FIREHOSE_PRODUCERS
+ )
+ )
+ .build();
}
try {
Long newSequence = Long.parseLong(sequenceValue);
- if (newSequence <= producerSequence) {
- return Optional.of(
- Response.ok(
- responseMapper.writeValueAsString(
- ImmutableMap.of("eventCount", 0, "skipped", true)
- ),
- responseContentType
- ).build()
- );
- }
- producerSequences.put(producerId, newSequence);
+ while (true) {
+ if (newSequence <= producerSequence) {
+ return Response.ok(
+
responseMapper.writeValueAsString(ImmutableMap.of("eventCount", 0, "skipped",
true)),
+ responseContentType
+ ).build();
+ }
+ if (producerSequences.replace(producerId, producerSequence,
newSequence)) {
+ return null;
+ }
+ producerSequence = producerSequences.get(producerId);
Review comment:
This method is called directly from REST method `addAll()`. I. e. anybody
could call it concurrently. Or is it possible to specify for Jersey that some
method should be called from a single web thread?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]