This commit is contained in:
Clebert Suconic 2017-04-12 11:05:36 -04:00
commit a1664bdd47
4 changed files with 1 additions and 124 deletions

View File

@ -1,103 +0,0 @@
/*
* 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.core.server.impl;
import java.io.File;
import java.nio.channels.FileLock;
import org.apache.activemq.artemis.core.io.aio.ActiveMQFileLock;
import org.apache.activemq.artemis.jlibaio.LibaioContext;
import org.apache.activemq.artemis.jlibaio.LibaioFile;
/**
* This is using the ActiveMQ Artemis Libaio Native to perform calls to flock on a Linux system. At the
* current version of RHEL there's a bug on GFS2 and because of that fctl is not functional what
* will cause issues on Failover over Shared Storage.
* <p>
* This will provide an alternative to perform locks through our native module until fctl is fixed
* on Linux.
* <p>
* https://bugzilla.redhat.com/show_bug.cgi?id=678585
*/
public final class AIOFileLockNodeManager extends FileLockNodeManager {
/**
* @param directory
* @param replicatingBackup
*/
public AIOFileLockNodeManager(final File directory, boolean replicatingBackup) {
super(directory, replicatingBackup);
}
public AIOFileLockNodeManager(final File directory, boolean replicatingBackup, long lockAcquisitionTimeout) {
super(directory, replicatingBackup);
this.lockAcquisitionTimeout = lockAcquisitionTimeout;
}
@Override
protected FileLock tryLock(final int lockPos) throws Exception {
File file = newFileForRegionLock(lockPos);
LibaioFile fileControl = LibaioContext.openControlFile(file.getAbsolutePath(), false);
if (!fileControl.lock()) {
fileControl.close();
return null;
}
FileLock lock = new ActiveMQFileLock(fileControl);
return lock;
}
@Override
protected FileLock lock(final int liveLockPos) throws Exception {
long start = System.currentTimeMillis();
File file = newFileForRegionLock(liveLockPos);
while (!interrupted) {
FileLock lockFile = tryLock(liveLockPos);
if (lockFile != null) {
return lockFile;
} else {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
return null;
}
if (lockAcquisitionTimeout != -1 && (System.currentTimeMillis() - start) > lockAcquisitionTimeout) {
throw new Exception("timed out waiting for lock");
}
}
}
return null;
}
/**
* @param liveLockPos
* @return
*/
protected File newFileForRegionLock(final int liveLockPos) {
File file = newFile("server." + liveLockPos + ".lock");
return file;
}
}

View File

@ -154,7 +154,6 @@ import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings;
import org.apache.activemq.artemis.core.transaction.ResourceManager;
import org.apache.activemq.artemis.core.transaction.impl.ResourceManagerImpl;
import org.apache.activemq.artemis.core.version.Version;
import org.apache.activemq.artemis.jlibaio.LibaioContext;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.spi.core.protocol.SessionCallback;
@ -446,8 +445,6 @@ public class ActiveMQServerImpl implements ActiveMQServer {
NodeManager manager;
if (!configuration.isPersistenceEnabled()) {
manager = new InVMNodeManager(replicatingBackup);
} else if (configuration.getJournalType() == JournalType.ASYNCIO && LibaioContext.isLoaded()) {
manager = new AIOFileLockNodeManager(directory, replicatingBackup, configuration.getJournalLockAcquisitionTimeout());
} else {
manager = new FileLockNodeManager(directory, replicatingBackup, configuration.getJournalLockAcquisitionTimeout());
}

View File

@ -22,12 +22,9 @@ import java.io.File;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.JournalType;
import org.apache.activemq.artemis.core.server.NodeManager;
import org.apache.activemq.artemis.core.server.impl.AIOFileLockNodeManager;
import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
import org.apache.activemq.artemis.core.server.impl.FileLockNodeManager;
import org.apache.activemq.artemis.jlibaio.LibaioContext;
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
public class ColocatedActiveMQServer extends ActiveMQServerImpl {
@ -68,11 +65,7 @@ public class ColocatedActiveMQServer extends ActiveMQServerImpl {
@Override
protected NodeManager createNodeManager(final File directory, boolean replicatingBackup) {
if (replicatingBackup) {
if (getConfiguration().getJournalType() == JournalType.ASYNCIO && LibaioContext.isLoaded()) {
return new AIOFileLockNodeManager(directory, replicatingBackup, getConfiguration().getJournalLockAcquisitionTimeout());
} else {
return new FileLockNodeManager(directory, replicatingBackup, getConfiguration().getJournalLockAcquisitionTimeout());
}
return new FileLockNodeManager(directory, replicatingBackup, getConfiguration().getJournalLockAcquisitionTimeout());
} else {
if (backup) {
return nodeManagerBackup;

View File

@ -18,9 +18,7 @@ package org.apache.activemq.artemis.tests.unit.core.server.impl;
import java.io.File;
import org.apache.activemq.artemis.core.server.impl.AIOFileLockNodeManager;
import org.apache.activemq.artemis.core.server.impl.FileLockNodeManager;
import org.apache.activemq.artemis.jlibaio.LibaioContext;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.Before;
import org.junit.Test;
@ -41,14 +39,6 @@ public class FileLockTest extends ActiveMQTestBase {
}
@Test
public void testAIOLock() throws Exception {
if (LibaioContext.isLoaded()) {
doTestLock(new AIOFileLockNodeManager(getTestDirfile(), false), new AIOFileLockNodeManager(getTestDirfile(), false));
}
}
public void doTestLock(final FileLockNodeManager lockManager1,
final FileLockNodeManager lockManager2) throws Exception {
lockManager1.start();