-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: poll publish results from all producers in SolaceIO writer #39729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) { | ||
|
|
||
There was a problem hiding this comment.
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.