-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[client] new API to check if Bookkeeper client is connected to metada…
…ta service (#4342) # Motivation when zookeeper disconnect, use bookkeeper api to create new ledger will fail. add a new api to check metadata driver is available, if not available, use current ledger continue and don't rollover ledger ## ** tip ** Although it may not solve all issues since it's not atomic, it will reduce the losses caused by zk unavailability. # Modification add a new api named isDriverMetadataServiceAvailable
- Loading branch information
1 parent
4ca020a
commit d92bd20
Showing
7 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
52 changes: 52 additions & 0 deletions
52
...er/src/test/java/org/apache/bookkeeper/client/api/DriverMetadataServiceAvailableTest.java
This file contains 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,52 @@ | ||
/* | ||
* | ||
* 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.api; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import org.apache.bookkeeper.conf.ClientConfiguration; | ||
import org.apache.bookkeeper.test.BookKeeperClusterTestCase; | ||
import org.awaitility.Awaitility; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Bookkeeper Client API driver metadata service available test. | ||
*/ | ||
public class DriverMetadataServiceAvailableTest extends BookKeeperClusterTestCase { | ||
|
||
public DriverMetadataServiceAvailableTest() { | ||
super(3); | ||
} | ||
|
||
@Test | ||
public void testDriverMetadataServiceAvailable() | ||
throws Exception { | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
conf.setMetadataServiceUri(zkUtil.getMetadataServiceUri()); | ||
conf.setZkTimeout(3000); | ||
try (BookKeeper bkc = BookKeeper.newBuilder(conf).build()) { | ||
Awaitility.await().until(() -> bkc.isDriverMetadataServiceAvailable().get()); | ||
zkUtil.sleepCluster(5, TimeUnit.SECONDS, new CountDownLatch(1)); | ||
Awaitility.await().until(() -> !bkc.isDriverMetadataServiceAvailable().get()); | ||
Awaitility.await().until(() -> bkc.isDriverMetadataServiceAvailable().get()); | ||
} | ||
} | ||
} |
This file contains 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