Skip to content

Commit 21c6dc7

Browse files
committed
---
yaml --- r: 28255 b: refs/heads/pubsub-ordering-keys c: fd07e9e h: refs/heads/master i: 28253: 828e8cd 28251: dfe09bc 28247: ad2befe 28239: c59f551 28223: f81a5ad
1 parent 849c31a commit 21c6dc7

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

  • branches/pubsub-ordering-keys/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ refs/tags/v0.72.0: a7703f2593ba312c0b2dde6fdfd4f5c764bb55ac
155155
refs/tags/v0.73.0: 21241ea8be9439cc5764c4944cdce21d34ce4f9e
156156
refs/tags/v0.74.0: 9d1f733dbbf790de7b494418523b69c4a9a57638
157157
refs/heads/ignoretest: 23c412ae07af3d0ab1caa2d44d5bc5c0ccb8b31d
158-
refs/heads/pubsub-ordering-keys: 42697e29d13bf388508328b6bc444efdbb1c121b
158+
refs/heads/pubsub-ordering-keys: fd07e9e34c822418a7ba335313b2a8312cb9fbf3
159159
refs/tags/v0.75.0: c3673089ae09a897c1b4cf7dfe167fe4f8ab32fb
160160
refs/tags/v0.76.0: 395b016826d3ddf9cb8b34919636df15a4dbd032
161161
refs/tags/v0.77.0: 28a85a77883ccf5d48f297fd0ef3b3dca6ce01f0

branches/pubsub-ordering-keys/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,22 @@ public void run() {
313313
*/
314314
public void publishAllOutstanding() {
315315
messagesBatchLock.lock();
316+
List<MessagesBatch> toSend;
316317
try {
317-
for (MessagesBatch batch : messagesBatches.values()) {
318-
if (!batch.isEmpty()) {
319-
// TODO(kimkyung-goog): Do not release `messagesBatchLock` when publishing a batch. If
320-
// it's released, the order of publishing cannot be guaranteed if `publish()` is called
321-
// while this function is running. This locking mechanism needs to be improved if it
322-
// causes any performance degradation.
323-
publishOutstandingBatch(batch.popOutstandingBatch());
324-
}
325-
}
318+
toSend = new ArrayList<>(messagesBatches.values());
326319
messagesBatches.clear();
327320
} finally {
328321
messagesBatchLock.unlock();
329322
}
323+
for (MessagesBatch batch : toSend) {
324+
if (!batch.isEmpty()) {
325+
// TODO(kimkyung-goog): Do not release `messagesBatchLock` when publishing a batch. If
326+
// it's released, the order of publishing cannot be guaranteed if `publish()` is called
327+
// while this function is running. This locking mechanism needs to be improved if it
328+
// causes any performance degradation.
329+
publishOutstandingBatch(batch.popOutstandingBatch());
330+
}
331+
}
330332
}
331333

332334
private ApiFuture<PublishResponse> publishCall(OutstandingBatch outstandingBatch) {

0 commit comments

Comments
 (0)