Repository navigation
Connection pool for kafka group client - #438
Conversation
| } | ||
|
|
||
| final int remaining = maxLength - length; | ||
| final int remaining = Math.min(reserved - initialPad, length); |
There was a problem hiding this comment.
Does this always buffer everything that was omitted?
| option zilla:window ${networkConnectWindow} | ||
| option zilla:transmission "duplex" | ||
| option zilla:byteorder "network" | ||
| option zilla:affinity 0xb1 |
There was a problem hiding this comment.
Can we remove this affinity now?
| port = 0; | ||
| } | ||
|
|
||
| final KafkaClientConnectionApp kafkaClientConnectionApp = connectionPool.computeIfAbsent(address, s -> |
There was a problem hiding this comment.
Rename KafkaClientConnectionApp to KafkaClientConnection.
Rename kafkaClientConnectionApp to connection.
| } | ||
| } | ||
|
|
||
| private void onConnectionInitialBegin( |
There was a problem hiding this comment.
Please remove Initial and Reply from method names, that is old style before we unified on single on...Message callback for both initial stream and reply throttle.
|
|
||
| final KafkaClientConnectionApp kafkaClientConnectionApp = connectionPool.computeIfAbsent(address, s -> | ||
| new KafkaClientConnectionApp(originId, routedId, initialId, authorization, affinity, host, port)); | ||
| kafkaClientConnectionApp.doAddReceiver(initialId, sender); |
There was a problem hiding this comment.
Rename doAddReceiver to onNewStream(BeginFW, MessageConsumer).
| option zilla:window 8192 | ||
| option zilla:transmission "duplex" | ||
| option zilla:byteorder "network" | ||
| option zilla:budgetId 2 |
There was a problem hiding this comment.
Is it actually necessary to have a budgetId in the scripts, or is it implicit inside the connection pool implementation?
There was a problem hiding this comment.
Not necessary forgot to remove it
|
|
||
| public Signaler signaler() | ||
| { | ||
| return new KafkaClientSignaler(); |
There was a problem hiding this comment.
Please initialize in the constructor.
| connection.doConnectionSignalNow(initialId, signalId); | ||
| } | ||
|
|
||
| private long signalAt( |
There was a problem hiding this comment.
Rename to doStreamSignalAt.
| streamsByInitialIds.remove(initialId); | ||
| } | ||
|
|
||
| private void signalNow( |
There was a problem hiding this comment.
Rename to doStreamSignalNow.
| long timeMillis, | ||
| int signalId) | ||
| { | ||
| nextSignalerRequestId++; |
There was a problem hiding this comment.
Please rename to nextContextId.
| } | ||
|
|
||
| private long doConnectionSignalAt( | ||
| long initialId, |
| } | ||
|
|
||
| private void doConnectionSignalNow( | ||
| long initialId, |
| if (!clientConnectionPool) | ||
| { | ||
| newStream = streamFactory; | ||
| } |
There was a problem hiding this comment.
This check should be in KafkaClientFactory so we pass the correct streamFactory and signaler to KafkaClientGroupFactory instead of this approach.
| this.encodeBuffer = new UnsafeBuffer(new byte[context.writeBuffer().capacity()]); | ||
| this.bufferPool = context.bufferPool(); | ||
| this.signaler = context.signaler(); | ||
| this.connectionSignaler = new KafkaClientSignaler(); |
There was a problem hiding this comment.
Recommend passing regular signaler to KafkaClientSignaler constructor, then call this local field signaler instead of connectionSignaler.
| if (!clientConnectionPool) | ||
| { | ||
| newConnectionSignaler = signaler; | ||
| } |
There was a problem hiding this comment.
This will move out too when the check is in KafkaClientFactory instead.
| else if (responseBytes > 0) | ||
| { | ||
| newFlags = FLAG_NONE; | ||
| } |
There was a problem hiding this comment.
I think the flags calculation here is pretending the complete response is a single fragmented message spanning multiple DATA frames.
But instead, I think we want to preserve the flags sent by the response stream, with the exception of a minor adjustment when DATA frame does not belong to a single response.
| requestBytes = requestHeader.length() + KAFKA_FRAME_LENGTH_FIELD_OFFSET; | ||
| } | ||
|
|
||
| requestBytes -= payload.sizeof(); |
There was a problem hiding this comment.
Strictly speaking a stream could send multiple requests in the same DATA frame.
Here we are assuming that they don't with the assert.
| } | ||
| else | ||
| { | ||
| state = KafkaState.closingReply(state); |
There was a problem hiding this comment.
Please move this above if statement, so we are always closing and then conditionally also closed.
| } | ||
| else | ||
| { | ||
| state = KafkaState.closingReply(state); |
There was a problem hiding this comment.
Please move state assignment above if.
| } | ||
|
|
||
| stream.doStreamData(traceId, newFlags, sequence, acknowledge, reserved, | ||
| stream.doStreamData(traceId, flags, sequence, acknowledge, reserved, |
There was a problem hiding this comment.
I think the safest thing to do is always set INIT and FIN flags here, just to make sure we never send inconsistent flags to any stream sharing the connection.
| stream.doStreamData(traceId, flags, sequence, acknowledge, reserved, | |
| stream.doStreamData(traceId, flags | FLAG_INIT | FLAG_FIN, sequence, acknowledge, reserved, |
|
|
||
| this.connectionPool = new KafkaClientConnectionPool( | ||
| config, context, bindings::get, accountant.creditor()); | ||
| this.connectionPool = new KafkaClientConnectionPool(config, context, accountant.creditor()); |
There was a problem hiding this comment.
Local variable is sufficient, no need for field.
| this.connectionPool = new KafkaClientConnectionPool(config, context, accountant.creditor()); | |
| KafkaClientConnectionPool connectionPool = new KafkaClientConnectionPool(config, context, accountant.creditor()); |
| requestBytes -= payload.sizeof(); | ||
| connection.doConnectionData(initialId, traceId, authorization, budgetId, | ||
| flags, reserved, payload, extension); | ||
| assert requestBytes >= 0; |
| final KafkaClientConnectionPool connectionPool = new KafkaClientConnectionPool( | ||
| config, context, accountant.creditor()); | ||
|
|
||
| final BindingHandler newStream = config.clientConnectionPool() ? connectionPool.streamFactory() : |
There was a problem hiding this comment.
Please rename newStream to streamFactory.
Description
Implements connection pool abstraction for
kafkaclient request-response protocol with minimal impact on existing code.Fixes #462