-
Notifications
You must be signed in to change notification settings - Fork 974
autorecovery-use-metadata-driver (part 4) : provide an AuditorSelector interface to abstract leader election logic for AuditorElector
#1701
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
base: master
Are you sure you want to change the base?
Changes from all commits
1b1f0b9
71698ee
1f42804
a9bce35
60b2387
83bc459
c3b3a91
b92b0ab
0bff99a
3ed0aa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * 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.meta; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.concurrent.Future; | ||
| import org.apache.bookkeeper.meta.exceptions.MetadataException; | ||
| import org.apache.bookkeeper.net.BookieSocketAddress; | ||
|
|
||
| /** | ||
| * Interface for selecting an auditor. | ||
| */ | ||
| public interface AuditorSelector extends AutoCloseable { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reviewing the whole patch I suggest calling this interface 'AuditorElectionManager' |
||
|
|
||
| /** | ||
| * Selector listener to listen on auditor changes. | ||
| */ | ||
| interface SelectorListener { | ||
|
|
||
| /** | ||
| * Trigger when it is selected as a leader. | ||
| */ | ||
| void onLeaderSelected() throws IOException; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better 'election' over 'selection'
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is already and selector is pretty standard in curator : https://curator.apache.org/curator-recipes/leader-election.html |
||
|
|
||
| /** | ||
| * Trigger on each selection attempt. | ||
| */ | ||
| void onSelectionAttempt(); | ||
|
|
||
| /** | ||
| * Trigger when it lost its leadership. | ||
| */ | ||
| void onLeaderExpired(); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Whether the selector is running or not. | ||
| * | ||
| * @return true if the selector is running, otherwise false. | ||
| */ | ||
| boolean isRunning(); | ||
|
|
||
| /** | ||
| * Trigger the selecting process with the provided <tt>listener</tt>. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Election' |
||
| * | ||
| * @param listener the listener to listen on events triggered by selection. | ||
| * @return a future when the selector is running | ||
| */ | ||
| Future<?> select(SelectorListener listener) | ||
| throws MetadataException; | ||
|
|
||
| /** | ||
| * Get the current auditor. | ||
| * | ||
| * @return current auditor. | ||
| */ | ||
| BookieSocketAddress getCurrentAuditor() throws MetadataException; | ||
|
|
||
| @Override | ||
| void close(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.meta.exceptions; | ||
|
|
||
| /** | ||
| * Metadata Runtime Exception. | ||
| */ | ||
| public class MetadataRuntimeException extends RuntimeException { | ||
|
|
||
| private static final long serialVersionUID = -7833758146152388503L; | ||
|
|
||
| private final Code code; | ||
|
|
||
| public MetadataRuntimeException(Code code, String message) { | ||
| super(message); | ||
| this.code = code; | ||
| } | ||
|
|
||
| public MetadataRuntimeException(Code code, String message, Throwable cause) { | ||
| super(message, cause); | ||
| this.code = code; | ||
| } | ||
|
|
||
| public MetadataRuntimeException(Code code, Throwable cause) { | ||
| super(cause); | ||
| this.code = code; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ public void close() { | |
| if (null != rmToClose) { | ||
| rmToClose.close(); | ||
| } | ||
|
|
||
| super.close(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,9 @@ | |
| import lombok.SneakyThrows; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.bookkeeper.conf.AbstractConfiguration; | ||
| import org.apache.bookkeeper.conf.ServerConfiguration; | ||
| import org.apache.bookkeeper.meta.AbstractZkLedgerManagerFactory; | ||
| import org.apache.bookkeeper.meta.AuditorSelector; | ||
| import org.apache.bookkeeper.meta.HierarchicalLedgerManagerFactory; | ||
| import org.apache.bookkeeper.meta.LayoutManager; | ||
| import org.apache.bookkeeper.meta.LedgerManagerFactory; | ||
|
|
@@ -250,16 +252,26 @@ public synchronized LedgerManagerFactory getLedgerManagerFactory() | |
| return lmFactory; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| if (null != lmFactory) { | ||
| public AuditorSelector getAuditorSelector(String bookieId) { | ||
| return new ZkAuditorSelector(bookieId, zk, new ServerConfiguration(conf)); | ||
| } | ||
|
|
||
| protected void closeLedgerManagerFactory() { | ||
| LedgerManagerFactory lmToClose; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: lmFactoryToClose ? |
||
| synchronized (this) { | ||
| lmToClose = lmFactory; | ||
| lmFactory = null; | ||
| } | ||
| if (null != lmToClose) { | ||
| try { | ||
| lmFactory.close(); | ||
| lmToClose.close(); | ||
| } catch (IOException e) { | ||
| log.warn("Failed to close zookeeper based ledger manager", e); | ||
| } | ||
| lmFactory = null; | ||
| } | ||
| } | ||
|
|
||
| protected void closeZooKeeper() { | ||
| if (ownZKHandle && null != zk) { | ||
| try { | ||
| zk.close(); | ||
|
|
@@ -270,4 +282,10 @@ public void close() { | |
| zk = null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| closeLedgerManagerFactory(); | ||
| closeZooKeeper(); | ||
| } | ||
| } | ||
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.
Is it better give a name to the thread?