Skip to content
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

PubSub: Message ordering no longer being honored #1889

Closed
turneand opened this issue Feb 2, 2024 · 0 comments · Fixed by #1903
Closed

PubSub: Message ordering no longer being honored #1889

turneand opened this issue Feb 2, 2024 · 0 comments · Fixed by #1903
Assignees
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release.

Comments

@turneand
Copy link

turneand commented Feb 2, 2024

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    General, Core, and Other are also allowed as types
  2. OS type and version: Windows/unix
  3. Java version: 17
  4. version(s): 1.125.11 (works), 1.125.12(broken), 1.126.2(broken)

Steps to reproduce

  1. create a new pubsub topic and subscription with message ordering enabled (and exactly once delivery)
  2. publish 100 messages in a loop, with a simple text message containing the counter, and the ordering key of "defabc"
  3. start a single subscriber to receive the messages
  4. The messages should be received in order (and were in 1.125.11), but are now received only "mostly" in order

Code example

var project =
var topicName = TopicName.of(project, "andrew_test");
var publisher = Publisher.newBuilder(topicName).setEnableMessageOrdering(true).build();

try {
    for (int i = 0; i < 100; i++) {
        var data = ByteString.copyFromUtf8("hello #" + i);
        var message = PubsubMessage.newBuilder().setData(data).setOrderingKey("defabc").build();
        publisher.publish(message);
    }
} finally {
    publisher.shutdown();
    publisher.awaitTermination(1, TimeUnit.MINUTES);
}

var subscriptionName = ProjectSubscriptionName.of(project, "andrew-test-sub");
var subscriber = Subscriber.newBuilder(subscriptionName, (PubsubMessage message, AckReplyConsumer consumer) -> {
    System.out.println("Id: " + message.getMessageId() + " Data: " + message.getData().toStringUtf8());
    consumer.ack();
}).build();

try {
    subscriber.startAsync().awaitRunning();
    subscriber.awaitTerminated(30, TimeUnit.SECONDS);
} catch (TimeoutException e) {
    subscriber.stopAsync();
}

Stack trace

This also seems to lead to more frequent occurrences of this stack trace

io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Some acknowledgement ids in the request were sent out of order.

External references such as API reference guides

n/a

Any additional information below

The above code snippet works fine in 1.125.11, but in 1.125.12 and 1.126.2 (the latest as of raise date) we are getting messages delivered out of order.

I believe the root cause is the change from #1778 where under #1807 the LinkedHashSet was changed to a ConcurrentHashMap. When the notifyAckSuccess method is called, we are iterating over the outstandingReceipts to put into the outstandingBatch. Unfortunately this change switched it from insertion order to hash based ordering.

I can mitigate all of these issues by setting the max-outstanding-element-count down to 1, but then we lose the ability to parallel process, or the benefits of batching.

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/java-pubsub API. label Feb 2, 2024
michaelpri10 pushed a commit that referenced this issue Feb 7, 2024
…1804)

Source-Link: googleapis/synthtool@1547f9a
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:bc2bf47c7370f1b1a8a46b0c104ce7e43644ac58902c9de265fe1f253fcc2506

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
@kamalaboulhosn kamalaboulhosn added priority: p0 Highest priority. Critical issue. P0 implies highest priority. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed priority: p0 Highest priority. Critical issue. P0 implies highest priority. labels Feb 8, 2024
michaelpri10 added a commit that referenced this issue Feb 9, 2024
* chore: change assignees for issues and PRs to michaelpri10

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* fix: Revert PR#1807 and use a LinkedHasMap in the MessageDispatcher

* fix: Make processedReceivedMessages thread-safe

* fix: Only synchronize on the outstandingReceipts object in the MessageDispatcher

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants