Skip to content

Commit ff619f7

Browse files
committed
---
yaml --- r: 35375 b: refs/heads/pubsub-ordering-keys c: da6dd3c h: refs/heads/master i: 35373: cb6b5ac 35371: 3d4cec9 35367: 139bd26 35359: 425cbd7
1 parent 18f162c commit ff619f7

2 files changed

Lines changed: 11 additions & 19 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: 30879687cce9936a6f7ee43af9110af2e2884625
158+
refs/heads/pubsub-ordering-keys: da6dd3ca83cab33f15f8a122c774487b325cdef7
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: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ public ApiFuture<String> publish(PubsubMessage message) {
220220
List<OutstandingBatch> batchesToSend;
221221
messagesBatchLock.lock();
222222
try {
223-
// Check if the next message makes the current batch exceed the max batch byte size.
224223
MessagesBatch messagesBatch = messagesBatches.get(orderingKey);
225224
if (messagesBatch == null) {
226225
messagesBatch = new MessagesBatch(batchingSettings, orderingKey);
@@ -232,23 +231,21 @@ public ApiFuture<String> publish(PubsubMessage message) {
232231
messagesBatches.remove(orderingKey);
233232
}
234233
setupAlarm();
234+
if (!batchesToSend.isEmpty()) {
235+
// TODO: if this is not an ordering keys scenario, will this do anything?
236+
publishAllWithoutInflight();
237+
238+
// TODO: if this is an ordering keys scenario, is this safe without messagesBatchLock?
239+
for (final OutstandingBatch batch : batchesToSend) {
240+
logger.log(Level.FINER, "Scheduling a batch for immediate sending.");
241+
publishOutstandingBatch(batch);
242+
}
243+
}
235244
} finally {
236245
messagesBatchLock.unlock();
237246
}
238247

239248
messagesWaiter.incrementPendingMessages(1);
240-
241-
if (!batchesToSend.isEmpty()) {
242-
// TODO: if this is not an ordering keys scenario, will this do anything?
243-
publishAllWithoutInflight();
244-
245-
// TODO: if this is an ordering keys scenario, is this safe without messagesBatchLock?
246-
for (final OutstandingBatch batch : batchesToSend) {
247-
logger.log(Level.FINER, "Scheduling a batch for immediate sending.");
248-
publishOutstandingBatch(batch);
249-
}
250-
}
251-
252249
return outstandingPublish.publishResult;
253250
}
254251

@@ -331,11 +328,6 @@ private void publishAllWithoutInflight() {
331328
if (batch.isEmpty()) {
332329
it.remove();
333330
} else if (key.isEmpty() || !sequentialExecutor.hasTasksInflight(key)) {
334-
// TODO(kimkyung-goog): Do not release `messagesBatchLock` when publishing a batch. If
335-
// it's released, the order of publishing cannot be guaranteed if `publish()` is called
336-
// while this function is running. This locking mechanism needs to be improved if it
337-
// causes any performance degradation.
338-
339331
// TODO: Will this cause a performance problem for non-ordering keys scenarios?
340332
publishOutstandingBatch(batch.popOutstandingBatch());
341333
it.remove();

0 commit comments

Comments
 (0)