librdkafka icon indicating copy to clipboard operation
librdkafka copied to clipboard

Fix fast leader query back-off

Open larry-cdn77 opened this issue 3 years ago • 5 comments

Fix #3690: Metadata leader query timer backoff never applied

larry-cdn77 avatar Apr 19 '22 15:04 larry-cdn77

Test checks to see that after 1 second 6 triggers occur of an exponentially backed off 10ms timer (you expect triggers at 10 ms, 30, 70, 150, 310 and 630)

larry-cdn77 avatar Apr 19 '22 15:04 larry-cdn77

I don't immediately see why the rdkafka_timer symbols failed to link in the CI build

image

larry-cdn77 avatar Apr 19 '22 16:04 larry-cdn77

Use in code (src/rdtimer.c) unittests to test the private implementation, see for example unittest_broker.

Also make sure the test runs quickly, preferably in under a handful of seconds.

You can run a single unittest by: TESTS=0000 RD_UT_TEST=backoff make in the tests/ directory.

edenhill avatar Apr 26 '22 07:04 edenhill

Thank you. I had neglected the unit test framework. It is a unit test now reduced in duration to one second.

larry-cdn77 avatar May 28 '22 16:05 larry-cdn77

In order for my test to run reliably I had to round up the microsecond-millisecond conversion of sleep time in rd_kafka_timers_run. Otherwise the value is rounded down and I get a 'dribbling' effect of waiting a bit more, a bit more and a tiny bit more still...

                        sleeptime = rd_kafka_timers_next(rkts, timeout_us,
                                                         0 /*no-lock*/);

                        if (sleeptime > 0) {
                                cnd_timedwait_ms(&rkts->rkts_cond,
                                                 &rkts->rkts_lock,
                                                 (int)(sleeptime / 1000) + 1);
                        }

larry-cdn77 avatar May 29 '22 06:05 larry-cdn77

CLA assistant check
All committers have signed the CLA.

cla-assistant[bot] avatar Aug 21 '23 15:08 cla-assistant[bot]