Skip to content

Commit 6e353b7

Browse files
authored
PIP-121: Pulsar cluster level auto failover on client side (#13316)
Related to #13315 ### Modification 1. add Pulsar cluster level auto failover
1 parent 2ca8e8a commit 6e353b7

File tree

8 files changed

+1254
-1
lines changed

8 files changed

+1254
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.client.api;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.concurrent.TimeUnit;
24+
import org.apache.pulsar.common.classification.InterfaceAudience;
25+
import org.apache.pulsar.common.classification.InterfaceStability;
26+
27+
/**
28+
* {@link AutoClusterFailoverBuilder} is used to configure and create instance of {@link ServiceUrlProvider}.
29+
*
30+
* @since 2.10.0
31+
*/
32+
@InterfaceAudience.Public
33+
@InterfaceStability.Evolving
34+
public interface AutoClusterFailoverBuilder {
35+
36+
@SuppressWarnings("checkstyle:javadoctype")
37+
enum FailoverPolicy {
38+
ORDER
39+
}
40+
/**
41+
* Set the primary service url.
42+
*
43+
* @param primary
44+
* @return
45+
*/
46+
AutoClusterFailoverBuilder primary(String primary);
47+
48+
/**
49+
* Set the secondary service url.
50+
*
51+
* @param secondary
52+
* @return
53+
*/
54+
AutoClusterFailoverBuilder secondary(List<String> secondary);
55+
56+
/**
57+
* Set secondary choose policy. The default secondary choose policy is `ORDER`.
58+
* @param policy
59+
* @return
60+
*/
61+
AutoClusterFailoverBuilder failoverPolicy(FailoverPolicy policy);
62+
63+
/**
64+
* Set secondary authentication.
65+
*
66+
* @param authentication
67+
* @return
68+
*/
69+
AutoClusterFailoverBuilder secondaryAuthentication(Map<String, Authentication> authentication);
70+
71+
/**
72+
* Set secondary tlsTrustCertsFilePath.
73+
*
74+
* @param tlsTrustCertsFilePath
75+
* @return
76+
*/
77+
AutoClusterFailoverBuilder secondaryTlsTrustCertsFilePath(Map<String, String> tlsTrustCertsFilePath);
78+
79+
/**
80+
* Set secondary tlsTrustStorePath.
81+
*
82+
* @param tlsTrustStorePath
83+
* @return
84+
*/
85+
AutoClusterFailoverBuilder secondaryTlsTrustStorePath(Map<String, String> tlsTrustStorePath);
86+
87+
/**
88+
* Set secondary tlsTrustStorePassword.
89+
*
90+
* @param tlsTrustStorePassword
91+
* @return
92+
*/
93+
AutoClusterFailoverBuilder secondaryTlsTrustStorePassword(Map<String, String> tlsTrustStorePassword);
94+
/**
95+
* Set the switch failoverDelay. When one cluster failed longer than failoverDelay, it will trigger cluster switch.
96+
*
97+
* @param failoverDelay
98+
* @param timeUnit
99+
* @return
100+
*/
101+
AutoClusterFailoverBuilder failoverDelay(long failoverDelay, TimeUnit timeUnit);
102+
103+
/**
104+
* Set the switchBackDelay. When switched to the secondary cluster, and after the primary cluster comes back,
105+
* it will wait for switchBackDelay to switch back to the primary cluster.
106+
*
107+
* @param switchBackDelay
108+
* @param timeUnit
109+
* @return
110+
*/
111+
AutoClusterFailoverBuilder switchBackDelay(long switchBackDelay, TimeUnit timeUnit);
112+
113+
/**
114+
* Set the checkInterval for probe.
115+
*
116+
* @param interval
117+
* @param timeUnit
118+
* @return
119+
*/
120+
AutoClusterFailoverBuilder checkInterval(long interval, TimeUnit timeUnit);
121+
122+
/**
123+
* Build the ServiceUrlProvider instance.
124+
*
125+
* @return
126+
*/
127+
ServiceUrlProvider build();
128+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.pulsar.client.api;
20+
21+
import java.io.IOException;
22+
import java.util.Map;
23+
import java.util.concurrent.TimeUnit;
24+
import org.apache.pulsar.common.classification.InterfaceAudience;
25+
import org.apache.pulsar.common.classification.InterfaceStability;
26+
27+
/**
28+
* {@link ControlledClusterFailoverBuilder} is used to configure and create instance of {@link ServiceUrlProvider}.
29+
*
30+
* @since 2.10.0
31+
*/
32+
@InterfaceAudience.Public
33+
@InterfaceStability.Evolving
34+
public interface ControlledClusterFailoverBuilder {
35+
/**
36+
* Set default service url.
37+
*
38+
* @param serviceUrl
39+
* @return
40+
*/
41+
ControlledClusterFailoverBuilder defaultServiceUrl(String serviceUrl);
42+
43+
/**
44+
* Set the service url provider. ServiceUrlProvider will fetch serviceUrl from urlProvider periodically.
45+
*
46+
* @param urlProvider
47+
* @return
48+
*/
49+
ControlledClusterFailoverBuilder urlProvider(String urlProvider);
50+
51+
/**
52+
* Set the service url provider header to authenticate provider service.
53+
* @param header
54+
* @return
55+
*/
56+
ControlledClusterFailoverBuilder urlProviderHeader(Map<String, String> header);
57+
58+
/**
59+
* Set the probe check interval.
60+
* @param interval
61+
* @param timeUnit
62+
* @return
63+
*/
64+
ControlledClusterFailoverBuilder checkInterval(long interval, TimeUnit timeUnit);
65+
66+
/**
67+
* Build the ServiceUrlProvider instance.
68+
*
69+
* @return
70+
* @throws IOException
71+
*/
72+
ServiceUrlProvider build() throws IOException;
73+
}

pulsar-client-api/src/main/java/org/apache/pulsar/client/api/ServiceUrlProvider.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
@InterfaceAudience.Public
3333
@InterfaceStability.Stable
34-
public interface ServiceUrlProvider {
34+
public interface ServiceUrlProvider extends AutoCloseable {
3535

3636
/**
3737
* Initialize the service url provider with Pulsar client instance.
@@ -51,4 +51,12 @@ public interface ServiceUrlProvider {
5151
*/
5252
String getServiceUrl();
5353

54+
/**
55+
* Close the resource that the provider allocated.
56+
*
57+
*/
58+
@Override
59+
default void close() {
60+
// do nothing
61+
}
5462
}

0 commit comments

Comments
 (0)