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
ARTEMIS-2716 Implements pluggable Quorum Vote #3555
Changes from all commits
9926061
e3d2269
ac7adda
5a25ad2
e4ffad7
ed45ec1
045578a
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 |
---|---|---|
|
@@ -62,6 +62,9 @@ | |
<include>org.apache.activemq.rest:artemis-rest</include> | ||
<include>org.apache.qpid:qpid-jms-client</include> | ||
<include>io.micrometer:micrometer-core</include> | ||
<!-- quorum --> | ||
<include>org.apache.activemq:artemis-quorum-api</include> | ||
<include>org.apache.activemq:artemis-quorum-ri</include> | ||
|
||
<!-- dependencies --> | ||
<include>jakarta.jms:jakarta.jms-api</include> | ||
|
@@ -97,6 +100,12 @@ | |
<include>com.sun.xml.bind:jaxb-impl</include> | ||
<include>jakarta.activation:jakarta.activation-api</include> | ||
<include>jakarta.security.auth.message:jakarta.security.auth.message-api</include> | ||
<!-- quorum --> | ||
<include>org.apache.curator:curator-recipes</include> | ||
<include>org.apache.curator:curator-client</include> | ||
<include>org.apache.curator:curator-framework</include> | ||
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. @michaelandrepearce these are the ZK deps 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. Now out of office eh, still need to rebase vs master and include other deps for logging and force 3.6.1 ZK client version |
||
<include>org.apache.zookeeper:zookeeper</include> | ||
<include>org.apache.zookeeper:zookeeper-jute</include> | ||
</includes> | ||
<!--excludes> | ||
<exclude>org.apache.activemq:artemis-website</exclude> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.activemq</groupId> | ||
<artifactId>artemis-pom</artifactId> | ||
<version>2.18.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>artemis-quorum-api</artifactId> | ||
<packaging>bundle</packaging> | ||
<name>ActiveMQ Artemis Quorum API</name> | ||
|
||
<properties> | ||
<activemq.basedir>${project.basedir}/..</activemq.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.errorprone</groupId> | ||
<artifactId>error_prone_core</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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.activemq.artemis.quorum; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.locks.LockSupport; | ||
|
||
public interface DistributedLock extends AutoCloseable { | ||
|
||
String getLockId(); | ||
|
||
boolean isHeldByCaller() throws UnavailableStateException; | ||
|
||
boolean tryLock() throws UnavailableStateException, InterruptedException; | ||
|
||
default boolean tryLock(long timeout, TimeUnit unit) throws UnavailableStateException, InterruptedException { | ||
// it doesn't make sense to be super fast | ||
final long TARGET_FIRE_PERIOD_NS = TimeUnit.MILLISECONDS.toNanos(250); | ||
if (timeout < 0) { | ||
throw new IllegalArgumentException("timeout cannot be negative"); | ||
} | ||
Objects.requireNonNull(unit); | ||
if (timeout == 0) { | ||
return tryLock(); | ||
} | ||
final Thread currentThread = Thread.currentThread(); | ||
final long timeoutNs = unit.toNanos(timeout); | ||
final long start = System.nanoTime(); | ||
final long deadline = start + timeoutNs; | ||
long expectedNextFireTime = start; | ||
while (!currentThread.isInterrupted()) { | ||
long parkNs = expectedNextFireTime - System.nanoTime(); | ||
while (parkNs > 0) { | ||
LockSupport.parkNanos(parkNs); | ||
if (currentThread.isInterrupted()) { | ||
throw new InterruptedException(); | ||
} | ||
final long now = System.nanoTime(); | ||
parkNs = expectedNextFireTime - now; | ||
} | ||
if (tryLock()) { | ||
return true; | ||
} | ||
final long now = System.nanoTime(); | ||
final long remainingTime = deadline - now; | ||
if (remainingTime <= 0) { | ||
return false; | ||
} | ||
if (remainingTime < TARGET_FIRE_PERIOD_NS) { | ||
expectedNextFireTime = now; | ||
} else { | ||
expectedNextFireTime += TARGET_FIRE_PERIOD_NS; | ||
} | ||
} | ||
throw new InterruptedException(); | ||
} | ||
|
||
void unlock() throws UnavailableStateException; | ||
|
||
void addListener(UnavailableLockListener listener); | ||
|
||
void removeListener(UnavailableLockListener listener); | ||
|
||
@FunctionalInterface | ||
interface UnavailableLockListener { | ||
|
||
void onUnavailableLockEvent(); | ||
} | ||
|
||
@Override | ||
void close(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.activemq.artemis.quorum; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public interface DistributedPrimitiveManager extends AutoCloseable { | ||
|
||
static DistributedPrimitiveManager newInstanceOf(String className, Map<String, String> properties) throws Exception { | ||
return (DistributedPrimitiveManager) Class.forName(className).getDeclaredConstructor(Map.class).newInstance(properties); | ||
} | ||
|
||
@FunctionalInterface | ||
interface UnavailableManagerListener { | ||
|
||
void onUnavailableManagerEvent(); | ||
} | ||
|
||
void addUnavailableManagerListener(UnavailableManagerListener listener); | ||
|
||
void removeUnavailableManagerListener(UnavailableManagerListener listener); | ||
|
||
boolean start(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException; | ||
|
||
void start() throws InterruptedException, ExecutionException; | ||
|
||
boolean isStarted(); | ||
|
||
void stop(); | ||
|
||
DistributedLock getDistributedLock(String lockId) throws InterruptedException, ExecutionException, TimeoutException; | ||
|
||
@Override | ||
default void close() { | ||
stop(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.activemq.artemis.quorum; | ||
|
||
public final class UnavailableStateException extends Exception { | ||
|
||
public UnavailableStateException() { | ||
super(); | ||
} | ||
|
||
public UnavailableStateException(String message) { | ||
super(message); | ||
} | ||
|
||
public UnavailableStateException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public UnavailableStateException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
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.
Where are the zk deps here too?
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.
https://github.com/apache/activemq-artemis/pull/3555/files#r625528887