Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,57 +143,61 @@ public void publishResults(BeamContextWrapper context) {
long minFailed = Long.MAX_VALUE;
long maxFailed = 0;

Queue<PublishResult> publishResultsQueue =
solaceSessionServiceWithProducer().getPublishedResultsQueue();
Solace.PublishResult result = publishResultsQueue.poll();

if (result != null) {
if (getCurrentBundleTimestamp() == null) {
setCurrentBundleTimestamp(Instant.now());
for (int producerIndex = 0; producerIndex < producersMapCardinality; producerIndex++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered potential perf implications due to all bundles going through all queues ? I would still merge this to fix the correctness issue. But I would at least file a bug to improve perf if this is a concern.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a unit test ?

SessionService session =
SolaceWriteSessionsHandler.getSessionServiceWithProducer(
producerIndex, sessionServiceFactory, writerTransformUuid);
Queue<PublishResult> publishResultsQueue = session.getPublishedResultsQueue();
Solace.PublishResult result = publishResultsQueue.poll();

if (result != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this can result in data duplication. What if two competing bundles get access to the same queue with data and push them. Does the underlying library guarantee that data only get pushed once ?

if (getCurrentBundleTimestamp() == null) {
setCurrentBundleTimestamp(Instant.now());
}
}
}

while (result != null) {
Long latency = result.getLatencyNanos();
while (result != null) {
Long latency = result.getLatencyNanos();

if (latency == null && shouldPublishLatencyMetrics()) {
LOG.error(
"SolaceIO.Write: Latency is null but user asked for latency metrics."
+ " This may be a bug.");
}
if (latency == null && shouldPublishLatencyMetrics()) {
LOG.error(
"SolaceIO.Write: Latency is null but user asked for latency metrics."
+ " This may be a bug.");
}

if (latency != null) {
if (latency != null) {
if (result.getPublished()) {
sumPublish += latency;
countPublish++;
minPublish = Math.min(minPublish, latency);
maxPublish = Math.max(maxPublish, latency);
} else {
sumFailed += latency;
countFailed++;
minFailed = Math.min(minFailed, latency);
maxFailed = Math.max(maxFailed, latency);
}
}
if (result.getPublished()) {
sumPublish += latency;
countPublish++;
minPublish = Math.min(minPublish, latency);
maxPublish = Math.max(maxPublish, latency);
context.output(
SUCCESSFUL_PUBLISH_TAG, result, getCurrentBundleTimestamp(), GlobalWindow.INSTANCE);
} else {
sumFailed += latency;
countFailed++;
minFailed = Math.min(minFailed, latency);
maxFailed = Math.max(maxFailed, latency);
try {
BadRecord b =
BadRecord.fromExceptionInformation(
result,
null,
null,
Optional.ofNullable(result.getError()).orElse("SolaceIO.Write: unknown error."));
context.output(FAILED_PUBLISH_TAG, b, getCurrentBundleTimestamp(), GlobalWindow.INSTANCE);
} catch (IOException e) {
// ignore, the exception is thrown when the exception argument in the
// `BadRecord.fromExceptionInformation` is not null.
}
}
}
if (result.getPublished()) {
context.output(
SUCCESSFUL_PUBLISH_TAG, result, getCurrentBundleTimestamp(), GlobalWindow.INSTANCE);
} else {
try {
BadRecord b =
BadRecord.fromExceptionInformation(
result,
null,
null,
Optional.ofNullable(result.getError()).orElse("SolaceIO.Write: unknown error."));
context.output(FAILED_PUBLISH_TAG, b, getCurrentBundleTimestamp(), GlobalWindow.INSTANCE);
} catch (IOException e) {
// ignore, the exception is thrown when the exception argument in the
// `BadRecord.fromExceptionInformation` is not null.
}
}

result = publishResultsQueue.poll();
result = publishResultsQueue.poll();
}
}

if (shouldPublishLatencyMetrics()) {
Expand Down
Loading