-
Notifications
You must be signed in to change notification settings - Fork 974
BP-41 Bookie Address changes tracking #2435
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
Merged
Ghatage
merged 7 commits into
apache:master
from
eolivelli:fix/bp41-client-discovery-cache
Oct 20, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
25a16be
BP-41 Follow Bookie Address changes tracking
eolivelli ec8befc
fix constant value
eolivelli dd519e8
fix javadoc
eolivelli 905a52b
fix test
eolivelli 0ba4fc5
fid checkstyle
eolivelli 06bede0
Address Anup's comment
eolivelli 99ba775
fix checkstyle
eolivelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
...per-server/src/test/java/org/apache/bookkeeper/client/BookieNetworkAddressChangeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| /* | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * | ||
| */ | ||
| package org.apache.bookkeeper.client; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.bookkeeper.client.BKException.BKBookieHandleNotAvailableException; | ||
| import org.apache.bookkeeper.client.api.BookKeeper; | ||
| import org.apache.bookkeeper.client.api.LedgerEntries; | ||
| import org.apache.bookkeeper.client.api.ReadHandle; | ||
| import org.apache.bookkeeper.client.api.WriteHandle; | ||
| import org.apache.bookkeeper.conf.ClientConfiguration; | ||
| import org.apache.bookkeeper.conf.ServerConfiguration; | ||
| import org.apache.bookkeeper.discover.ZKRegistrationClient; | ||
| import org.apache.bookkeeper.test.BookKeeperClusterTestCase; | ||
| import org.apache.bookkeeper.util.PortManager; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Tests of the main BookKeeper client and the BP-41 bookieAddressTracking feature. | ||
| */ | ||
| @Slf4j | ||
| public class BookieNetworkAddressChangeTest extends BookKeeperClusterTestCase { | ||
|
|
||
| public BookieNetworkAddressChangeTest() { | ||
| super(1); | ||
| this.useUUIDasBookieId = true; | ||
| } | ||
|
|
||
| @Test | ||
| public void testFollowBookieAddressChange() throws Exception { | ||
| ClientConfiguration conf = new ClientConfiguration(); | ||
| conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri()); | ||
| try (BookKeeper bkc = BookKeeper.newBuilder(conf) | ||
| .build();) { | ||
| long lId; | ||
| try (WriteHandle h = bkc | ||
| .newCreateLedgerOp() | ||
| .withAckQuorumSize(1) | ||
| .withEnsembleSize(1) | ||
| .withWriteQuorumSize(1) | ||
| .withPassword(new byte[0]) | ||
| .execute() | ||
| .get();) { | ||
| lId = h.getId(); | ||
| h.append("foo".getBytes("utf-8")); | ||
| } | ||
|
|
||
| // restart bookie, change port | ||
| // on metadata we have a bookieId, not the network address | ||
| ServerConfiguration thisServerConf = new ServerConfiguration(baseConf); | ||
| thisServerConf.setBookiePort(PortManager.nextFreePort()); | ||
| restartBookies(thisServerConf); | ||
|
|
||
| try (ReadHandle h = bkc | ||
| .newOpenLedgerOp() | ||
| .withLedgerId(lId) | ||
| .withRecovery(true) | ||
| .withPassword(new byte[0]) | ||
| .execute() | ||
| .get()) { | ||
| assertEquals(0, h.getLastAddConfirmed()); | ||
| try (LedgerEntries entries = h.read(0, 0);) { | ||
| assertEquals("foo", new String(entries.getEntry(0).getEntryBytes(), "utf-8")); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testFollowBookieAddressChangeTrckingDisabled() throws Exception { | ||
| ClientConfiguration conf = new ClientConfiguration(); | ||
| conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri()); | ||
| conf.setEnableBookieAddressTracking(false); | ||
| try (BookKeeper bkc = BookKeeper.newBuilder(conf) | ||
| .build();) { | ||
| long lId; | ||
| try (WriteHandle h = bkc | ||
| .newCreateLedgerOp() | ||
| .withAckQuorumSize(1) | ||
| .withEnsembleSize(1) | ||
| .withWriteQuorumSize(1) | ||
| .withPassword(new byte[0]) | ||
| .execute() | ||
| .get();) { | ||
| lId = h.getId(); | ||
| h.append("foo".getBytes("utf-8")); | ||
| } | ||
|
|
||
| // restart bookie, change port | ||
| // on metadata we have a bookieId, not the network address | ||
| ServerConfiguration thisServerConf = new ServerConfiguration(baseConf); | ||
| thisServerConf.setBookiePort(PortManager.nextFreePort()); | ||
| restartBookies(thisServerConf); | ||
|
|
||
| try (ReadHandle h = bkc | ||
| .newOpenLedgerOp() | ||
| .withLedgerId(lId) | ||
| .withRecovery(true) | ||
| .withPassword(new byte[0]) | ||
| .execute() | ||
| .get()) { | ||
| try (LedgerEntries entries = h.read(0, 0);) { | ||
| fail("Should not be able to connect to the bookie with Bookie Address Tracking Disabled"); | ||
| } catch (BKBookieHandleNotAvailableException expected) { | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testFollowBookieAddressChangeZkSessionExpire() throws Exception { | ||
| ClientConfiguration conf = new ClientConfiguration(); | ||
| conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri()); | ||
| try (BookKeeper bkc = BookKeeper.newBuilder(conf) | ||
| .build();) { | ||
| long lId; | ||
| try (WriteHandle h = bkc | ||
| .newCreateLedgerOp() | ||
| .withAckQuorumSize(1) | ||
| .withEnsembleSize(1) | ||
| .withWriteQuorumSize(1) | ||
| .withPassword(new byte[0]) | ||
| .execute() | ||
| .get();) { | ||
| lId = h.getId(); | ||
| h.append("foo".getBytes("utf-8")); | ||
| } | ||
|
|
||
| log.error("expiring ZK session!"); | ||
| // expire zk session | ||
| ZKRegistrationClient regClient = (ZKRegistrationClient) ((org.apache.bookkeeper.client.BookKeeper) bkc) | ||
| .getMetadataClientDriver() | ||
| .getRegistrationClient(); | ||
|
|
||
| regClient.getZk().getTestable().injectSessionExpiration(); | ||
|
|
||
| // restart bookie, change port | ||
| // on metadata we have a bookieId, not the network address | ||
| ServerConfiguration thisServerConf = new ServerConfiguration(baseConf); | ||
| thisServerConf.setBookiePort(PortManager.nextFreePort()); | ||
| restartBookies(thisServerConf); | ||
|
|
||
| try (ReadHandle h = bkc | ||
| .newOpenLedgerOp() | ||
| .withLedgerId(lId) | ||
| .withRecovery(true) | ||
| .withPassword(new byte[0]) | ||
| .execute() | ||
| .get()) { | ||
| assertEquals(0, h.getLastAddConfirmed()); | ||
| try (LedgerEntries entries = h.read(0, 0);) { | ||
| assertEquals("foo", new String(entries.getEntry(0).getEntryBytes(), "utf-8")); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How frequently can a bookieID change? What factors drive its change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see these known cases:
So basically I think they won't change very ofter