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

Idempotent binding removal #1691

Merged
merged 2 commits into from
Aug 30, 2018
Merged

Idempotent binding removal #1691

merged 2 commits into from
Aug 30, 2018

Conversation

dcorbacho
Copy link
Contributor

@dcorbacho dcorbacho commented Aug 30, 2018

Optimizations introduced in #1589 caused the removal of bindings to
be non-idempotent, as the removal of routing information with dirty
deletes did not allow for full transaction rollback. This commit
reverts that change, losing some of the performance improvements in
favour of data correctness.

Types of Changes

  • Bugfix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (correction or otherwise)
  • Cosmetics (whitespace, appearance)

Checklist

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

Optimizations introduced in #1589 caused the removal of bindings to
be non-idempotent, as the removal of routing information with dirty
deletes did not allow for full transaction rollback. This commit
reverts that change, losing some of the performance improvements in
favour of data correctness.

[#160100569]
...that we've concluded we cannot use dirty deletes in at least some areas.
The sentence left is pretty to the point.
@michaelklishin
Copy link
Member

michaelklishin commented Oct 2, 2018

Leaving this test by @acogoluegnes here so that we don't have to dig in Pivotal Tracker for it. The test must output the sum number that matches the number of published messages and have a reasonable StdDev (e.g. on my machinee it's in the 180 to 360 range vs. over 4000 with RabbitMQ 3.7.7).

After the test stops there should be no hash ring state entries left on the RabbitMQ node.

@Grab(group = 'com.rabbitmq', module = 'amqp-client', version = "5.3.0")
@Grab(group = 'org.slf4j', module = 'slf4j-simple', version = '1.7.25')
@Grab(group = 'org.apache.commons', module = 'commons-math3', version = '3.6.1')
import com.rabbitmq.client.Channel
import com.rabbitmq.client.Connection
import com.rabbitmq.client.ConnectionFactory
import org.apache.commons.math3.stat.descriptive.SummaryStatistics

import java.util.stream.IntStream

println "No binding in the middle"
iterate(5, { consistentHashExchange(20, 1) });
println "Bindings in the middle"
iterate(5, { consistentHashExchange(10, 2) });

static void consistentHashExchange(int nbQueuesInEachIteration, int nbOfIterations) {
    ConnectionFactory cf = new ConnectionFactory();
    Connection c = cf.newConnection()
    Channel ch = c.createChannel();

    String exchange = "hash-exchange-test";
    ch.exchangeDeclare(exchange, "x-consistent-hash");

    List<String> queues = new ArrayList<>();

    iterate(nbOfIterations, {
        for (int i = 0; i < nbQueuesInEachIteration; i++) {
            String queue = ch.queueDeclare().getQueue();
            queues.add(queue);
            ch.queueBind(queue, exchange, "1");
        }

        for (String queue : queues) {
            ch.queuePurge(queue);
        }

        // focus on hash ring management here, so avoid concurrent bindings and publishes
        // for now
        Thread.sleep(1000);

        List<String> rks = new ArrayList<>();
        IntStream.range(0, 10_000).forEach({ i -> rks.add(UUID.randomUUID().toString()) });

        int nbMessages = 100_000;
        int count = 0;
        ch.confirmSelect();
        Set<String> rksUsed = new HashSet<>();
        while (count < nbMessages) {
            int remaining = count % rks.size();
            String rk = rks.get(remaining);
            rksUsed.add(rk);
            ch.basicPublish(exchange, rk, null, "".getBytes());
            count++;
        }

        ch.waitForConfirmsOrDie();
    })
    List<String> counts = new ArrayList<>();
    SummaryStatistics summaryStatistics = new SummaryStatistics();
    for (String queue : queues) {
        int messageCount = ch.queueDeclarePassive(queue).getMessageCount();
        counts.add(messageCount + "");
        summaryStatistics.addValue(Integer.valueOf(messageCount).doubleValue());
    }

    println String.join(",", counts)
    println summaryStatistics

    ch.exchangeDelete(exchange);
    c.close()
}

static void iterate(int nbOfIterations, Closure action) throws Exception {
    int count = 0;
    while (count < nbOfIterations) {
        action.call();
        count++;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants