-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
PIP-121: Pulsar cluster level auto failover on client side #13316
Changes from all commits
cc97bd7
a8f75d5
37fd325
f362c00
5ef9265
f1f569e
04abd2b
179372f
fa176bb
ee812ff
abfe14f
fecb2df
8017d67
1c8730f
1f7f9a8
5f50a28
f5f162b
5d9b48b
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,128 @@ | ||
/** | ||
* 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.pulsar.client.api; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import org.apache.pulsar.common.classification.InterfaceAudience; | ||
import org.apache.pulsar.common.classification.InterfaceStability; | ||
|
||
/** | ||
* {@link AutoClusterFailoverBuilder} is used to configure and create instance of {@link ServiceUrlProvider}. | ||
* | ||
* @since 2.10.0 | ||
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Evolving | ||
public interface AutoClusterFailoverBuilder { | ||
|
||
@SuppressWarnings("checkstyle:javadoctype") | ||
enum FailoverPolicy { | ||
ORDER | ||
} | ||
/** | ||
* Set the primary service url. | ||
* | ||
* @param primary | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder primary(String primary); | ||
|
||
/** | ||
* Set the secondary service url. | ||
* | ||
* @param secondary | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder secondary(List<String> secondary); | ||
|
||
/** | ||
* Set secondary choose policy. The default secondary choose policy is `ORDER`. | ||
* @param policy | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder failoverPolicy(FailoverPolicy policy); | ||
|
||
/** | ||
* Set secondary authentication. | ||
* | ||
* @param authentication | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder secondaryAuthentication(Map<String, Authentication> authentication); | ||
|
||
/** | ||
* Set secondary tlsTrustCertsFilePath. | ||
* | ||
* @param tlsTrustCertsFilePath | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder secondaryTlsTrustCertsFilePath(Map<String, String> tlsTrustCertsFilePath); | ||
|
||
/** | ||
* Set secondary tlsTrustStorePath. | ||
* | ||
* @param tlsTrustStorePath | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder secondaryTlsTrustStorePath(Map<String, String> tlsTrustStorePath); | ||
|
||
/** | ||
* Set secondary tlsTrustStorePassword. | ||
* | ||
* @param tlsTrustStorePassword | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder secondaryTlsTrustStorePassword(Map<String, String> tlsTrustStorePassword); | ||
/** | ||
* Set the switch failoverDelay. When one cluster failed longer than failoverDelay, it will trigger cluster switch. | ||
* | ||
* @param failoverDelay | ||
* @param timeUnit | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder failoverDelay(long failoverDelay, TimeUnit timeUnit); | ||
|
||
/** | ||
* Set the switchBackDelay. When switched to the secondary cluster, and after the primary cluster comes back, | ||
* it will wait for switchBackDelay to switch back to the primary cluster. | ||
* | ||
* @param switchBackDelay | ||
* @param timeUnit | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder switchBackDelay(long switchBackDelay, TimeUnit timeUnit); | ||
|
||
/** | ||
* Set the checkInterval for probe. | ||
* | ||
* @param interval | ||
* @param timeUnit | ||
* @return | ||
*/ | ||
AutoClusterFailoverBuilder checkInterval(long interval, TimeUnit timeUnit); | ||
|
||
/** | ||
* Build the ServiceUrlProvider instance. | ||
* | ||
* @return | ||
*/ | ||
ServiceUrlProvider build(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* 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.pulsar.client.api; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import org.apache.pulsar.common.classification.InterfaceAudience; | ||
import org.apache.pulsar.common.classification.InterfaceStability; | ||
|
||
/** | ||
* {@link ControlledClusterFailoverBuilder} is used to configure and create instance of {@link ServiceUrlProvider}. | ||
* | ||
* @since 2.10.0 | ||
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Evolving | ||
public interface ControlledClusterFailoverBuilder { | ||
/** | ||
* Set default service url. | ||
* | ||
* @param serviceUrl | ||
* @return | ||
*/ | ||
ControlledClusterFailoverBuilder defaultServiceUrl(String serviceUrl); | ||
|
||
/** | ||
* Set the service url provider. ServiceUrlProvider will fetch serviceUrl from urlProvider periodically. | ||
* | ||
* @param urlProvider | ||
* @return | ||
*/ | ||
ControlledClusterFailoverBuilder urlProvider(String urlProvider); | ||
|
||
/** | ||
* Set the service url provider header to authenticate provider service. | ||
* @param header | ||
* @return | ||
*/ | ||
ControlledClusterFailoverBuilder urlProviderHeader(Map<String, String> header); | ||
|
||
/** | ||
* Set the probe check interval. | ||
* @param interval | ||
* @param timeUnit | ||
* @return | ||
*/ | ||
ControlledClusterFailoverBuilder checkInterval(long interval, TimeUnit timeUnit); | ||
|
||
/** | ||
* Build the ServiceUrlProvider instance. | ||
* | ||
* @return | ||
* @throws IOException | ||
*/ | ||
ServiceUrlProvider build() throws IOException; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Stable | ||
public interface ServiceUrlProvider { | ||
public interface ServiceUrlProvider extends AutoCloseable { | ||
|
||
/** | ||
* Initialize the service url provider with Pulsar client instance. | ||
|
@@ -51,4 +51,12 @@ public interface ServiceUrlProvider { | |
*/ | ||
String getServiceUrl(); | ||
|
||
/** | ||
* Close the resource that the provider allocated. | ||
* | ||
*/ | ||
@Override | ||
default void close() { | ||
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. Would it be better to make the interface inherit 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. done 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. So, we can remove the default empty implementation here? 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. Other serviceUrlProvider implementation also need to implement |
||
// do nothing | ||
} | ||
} |
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.
What does
ORDER
mean?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 use List to store the secondary serviceUrls, and probe them by given order. I provide the failoverPolicy interface to support different policies.