Skip to content

Fallback to use v3 protocol for some types of requests if they are not implemented in v2 - #2085

Merged
sijie merged 9 commits into
apache:masterfrom
zymap:compatible_protocol
May 20, 2019
Merged

sijie merged 9 commits into
apache:masterfrom
zymap:compatible_protocol

Conversation

@zymap

@zymap zymap commented May 6, 2019 •

Copy link
Copy Markdown
Member

Descriptions of the changes in this PR:

Motivation

#2071

Changes

  • Add a client pool use v3 wire protocol
  • Obtain client by version
  • Currently only support writeLac and readLac

Master Issue: #2071

zymap added 2 commits May 5, 2019 15:36
---

Fixes apache#2071

*Motivation*

A bookkeeper should fallback to use v3 protocol for some types of requests if they are not implemented in v2

*Modifications*

- Add a client pool use v3 wire protocol
- Obtain client by version

@sijie sijie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I made a few suggestions. PTAL

*/
byte CURRENT_PROTOCOL_VERSION = 2;

/**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is only for v2 protocol. I would suggest not touching this file. You can use ProtocolVersion instead. ProtocolVersion already defines the version numbers from 1 to 3.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

*/
PerChannelBookieClient create(BookieSocketAddress address,
PerChannelBookieClientPool pcbcPool, SecurityHandlerFactory shFactory) throws SecurityException;
PerChannelBookieClient create(BookieSocketAddress address, PerChannelBookieClientPool pcbcPool,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using ProtocolVersion in this method.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

* @param version
* get specify version channel from pool
*/
void obtain(GenericCallback<PerChannelBookieClient> callback, long key, int version);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void obtain(GenericCallback<PerChannelBookieClient> callback, long key, int version);
void obtain(GenericCallback<PerChannelBookieClient> callback, long key, ProtocolVersion version);

}
return new PerChannelBookieClient(conf, executor, eventLoopGroup, allocator, address, statsLoggerForPCBC,
authProviderFactory, registry, pcbcPool, shFactory);
ClientConfiguration clientConfiguration = conf;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you need to clone the clientConfiguration.

So I would suggest having a variable in BookieClientImpl v3Conf then use v3Conf if ProtocolVersion is V3.

if (v3Conf == null) {
    v3Conf = new ClientConfiguration(conf);
    v3Conf.setUseV2WriteProtocol(false);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that my mistake. I shouldn't copy it directly. Thanks, fix it later

@zymap

zymap commented May 6, 2019

Copy link
Copy Markdown
Member Author

run bookkeeper-server tls tests

zymap added 2 commits May 6, 2019 18:14
---

*Modifications*

- If use protocol version directly will confuse people, so I use a boolean var to control
  whether or not use v3 protocol to connect server.
- All operation of clients need operate v3 clients too
@zymap

zymap commented May 8, 2019

Copy link
Copy Markdown
Member Author

run integration tests

@zymap

zymap commented May 8, 2019

Copy link
Copy Markdown
Member Author

@sijie All test is passed, PTAL

.getSecurityProviderFactory(conf.getTLSProviderFactoryClass());
this.shFactory = SecurityProviderFactoryFactory.getSecurityProviderFactory(conf.getTLSProviderFactoryClass());

this.clients = new PerChannelBookieClient[coreSize];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to always create v2 clients even if I am using only v3 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't. I should make it as optional. Fix it later

public class BKStandaloneContainer<SelfT extends BKStandaloneContainer<SelfT>> extends ChaosContainer<SelfT> {

private static final int ZK_PORT = 2181;
public static final int ZK_PORT = 2181;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you making this variable 'public'?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. oh, That's my mistake. I will fix it.

@zymap

zymap commented May 8, 2019

Copy link
Copy Markdown
Member Author

@eolivelli Fixed, PTAL

@sijie sijie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zymap overall looks good. left comments there.


toSend.release();
}, ledgerId);
}, ledgerId, conf.getUseV2WireProtocol());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the value here should be conf.getUseV2WireProtocol(). It should be true /* forceUseV3 *, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. will fix

pcbc.readLac(ledgerId, cb, ctx);
}
}, ledgerId);
}, ledgerId, conf.getUseV2WireProtocol());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the value here should be conf.getUseV2WireProtocol(). It should be true /* forceUseV3 *, right?

pcbc.getBookieInfo(requested, cb, ctx);
}
}, requested);
}, requested, conf.getUseV2WireProtocol());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the value here should be conf.getUseV2WireProtocol(). It should be true /* forceUseV3 *, right?

final BookieSocketAddress address;

final PerChannelBookieClient[] clients;
final PerChannelBookieClient[] clientsV3;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to call it clientsV3Enforced. otherwise it becomes a bit confused, because clients can be v3 as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

this.clientsV3[i] = factory.create(address, this, shFactory, true);
}
} else {
this.clientsV3 = null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assign clients to clientsV3 here. try to avoid having a field to be null.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

public void checkTimeoutOnPendingOperations() {
for (int i = 0; i < clients.length; i++) {
clients[i].checkTimeoutOnPendingOperations();
if (null != clientsV3) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (null != clientsV3) {
if (clients != clientsV3) {

pcbc.disconnect(wait);
for (int i = 0; i < clients.length; i++) {
clients[i].disconnect();
if (null != clientsV3) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (null != clientsV3) {
if (clients != clientsV3) {

pcbc.close(wait);
for (int i = 0; i < clients.length; i++) {
clients[i].close(wait);
if (null != clientsV3) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (null != clientsV3) {
if (clients != clientsV3) {

for (PerChannelBookieClient pcbc : clients) {
numPending += pcbc.getNumPendingCompletionRequests();
}
if (null != clientsV3) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (null != clientsV3) {
if (clients != clientsV3) {

@zymap

zymap commented May 13, 2019

Copy link
Copy Markdown
Member Author

@sijie @eolivelli I do some changes PTAL. :)

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great !

+1

@zymap

zymap commented May 13, 2019

Copy link
Copy Markdown
Member Author

run bookkeeper-server replication tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants