Skip to content
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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -270,6 +270,18 @@ private boolean isExpectedThread(Thread thread) {
} else if (threadName.contains("ObjectCleanerThread")) {
// Required since upgrade to Netty 4.1.22 maybe because https://github.com/netty/netty/commit/739e70398ccb6b11ffa97c6b5f8d55e455a2165e
return true;
} else if (threadName.contains("RMI TCP")) {
return true;
} else if (threadName.contains("RMI Scheduler")) {
return true;
} else if (threadName.contains("RMI RenewClean")) {
return true;
} else if (threadName.contains("Signal Dispatcher")) {
return true;
} else if (threadName.contains("ForkJoinPool.commonPool")) {
return true;
} else if (threadName.contains("GC Daemon")) {
return true;
} else {
for (StackTraceElement element : thread.getStackTrace()) {
if (element.getClassName().contains("org.jboss.byteman.agent.TransformListener")) {
Expand Down
Expand Up @@ -264,6 +264,9 @@ public static String getDefaultHapolicyBackupStrategy() {
// the directory to store the journal files in
private static String DEFAULT_JOURNAL_DIR = "data/journal";

// the directory to store the data files in
private static String DEFAULT_DATA_DIR = "data";

// true means that the journal directory will be created
private static boolean DEFAULT_CREATE_JOURNAL_DIR = true;

Expand Down Expand Up @@ -627,6 +630,8 @@ public static String getDefaultHapolicyBackupStrategy() {

public static final String DEFAULT_TEMPORARY_QUEUE_NAMESPACE = "";

private static final String DEFAULT_DISTRIBUTED_PRIMITIVE_MANAGER_CLASS_NAME = "org.apache.activemq.artemis.quorum.zookeeper.CuratorDistributedPrimitiveManager";

// Number of concurrent workers for a core bridge
public static int DEFAULT_BRIDGE_CONCURRENCY = 1;

Expand Down Expand Up @@ -938,6 +943,13 @@ public static String getDefaultJournalDir() {
return DEFAULT_JOURNAL_DIR;
}

/**
* the directory to store the journal files in
*/
public static String getDefaultDataDir() {
return DEFAULT_DATA_DIR;
}

/**
* true means that the journal directory will be created
*/
Expand Down Expand Up @@ -1721,6 +1733,10 @@ public static String getDefaultTemporaryQueueNamespace() {
return DEFAULT_TEMPORARY_QUEUE_NAMESPACE;
}

public static String getDefaultDistributedPrimitiveManagerClassName() {
return DEFAULT_DISTRIBUTED_PRIMITIVE_MANAGER_CLASS_NAME;
}

public static int getDefaultBridgeConcurrency() {
return DEFAULT_BRIDGE_CONCURRENCY;
}
Expand Down
11 changes: 11 additions & 0 deletions artemis-distribution/pom.xml
Expand Up @@ -231,6 +231,17 @@
<version>${project.version}</version>
<classifier>javadoc</classifier>
</dependency>
<!-- quorum -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-quorum-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-quorum-ri</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions artemis-distribution/src/main/assembly/dep.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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 -->
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<include>org.apache.curator:curator-recipes</include>
<include>org.apache.curator:curator-client</include>
<include>org.apache.curator:curator-framework</include>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelandrepearce these are the ZK deps

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Expand Down
1 change: 1 addition & 0 deletions artemis-features/src/main/resources/features.xml
Expand Up @@ -81,6 +81,7 @@
<!--bundle dependency="true">mvn:io.micrometer/micrometer-core/${version.micrometer}</bundle-->

<bundle>mvn:org.apache.activemq/activemq-artemis-native/${activemq-artemis-native-version}</bundle>
<bundle>mvn:org.apache.activemq/artemis-quorum-api/${pom.version}</bundle>
<bundle>mvn:org.apache.activemq/artemis-server-osgi/${pom.version}</bundle>
</feature>

Expand Down
41 changes: 41 additions & 0 deletions artemis-quorum-api/pom.xml
@@ -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>
@@ -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();
}
@@ -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();
}
}
@@ -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);
}
}