Avoid deadlock during CommitLog initialization

patch by Zephyr Guo, Dinesh Joshi; reviewed by Jordan West and Dinesh Joshi for CASSANDRA-15295

Co-Authored-By: Zephyr Guo <gzh1992n@gmail.com>
Co-Authored-By: Dinesh Joshi <dinesh.joshi@apple.com>
This commit is contained in:
Zephyr Guo 2019-10-18 17:15:20 -07:00 committed by Dinesh A. Joshi
parent ce877cbe2b
commit 3a8300e0b8
38 changed files with 372 additions and 23 deletions

View File

@ -51,6 +51,10 @@ import org.apache.cassandra.auth.IRoleManager;
import org.apache.cassandra.config.Config.CommitLogSync;
import org.apache.cassandra.config.EncryptionOptions.ServerEncryptionOptions.InternodeEncryption;
import org.apache.cassandra.db.ConsistencyLevel;
import org.apache.cassandra.db.commitlog.AbstractCommitLogSegmentManager;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.db.commitlog.CommitLogSegmentManagerCDC;
import org.apache.cassandra.db.commitlog.CommitLogSegmentManagerStandard;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.FSWriteError;
@ -147,6 +151,10 @@ public class DatabaseDescriptor
// turns some warnings into exceptions for testing
private static final boolean strictRuntimeChecks = Boolean.getBoolean("cassandra.strict.runtime.checks");
private static Function<CommitLog, AbstractCommitLogSegmentManager> commitLogSegmentMgrProvider = c -> DatabaseDescriptor.isCDCEnabled()
? new CommitLogSegmentManagerCDC(c, DatabaseDescriptor.getCommitLogLocation())
: new CommitLogSegmentManagerStandard(c, DatabaseDescriptor.getCommitLogLocation());
public static void daemonInitialization() throws ConfigurationException
{
daemonInitialization(DatabaseDescriptor::loadConfig);
@ -2968,4 +2976,14 @@ public class DatabaseDescriptor
logger.info("Setting use_offheap_merkle_trees to {}", value);
conf.use_offheap_merkle_trees = value;
}
public static Function<CommitLog, AbstractCommitLogSegmentManager> getCommitLogSegmentMgrProvider()
{
return commitLogSegmentMgrProvider;
}
public static void setCommitLogSegmentMgrProvider(Function<CommitLog, AbstractCommitLogSegmentManager> provider)
{
commitLogSegmentMgrProvider = provider;
}
}

View File

@ -82,7 +82,8 @@ public abstract class AbstractCommitLogSegmentManager
*/
private final AtomicLong size = new AtomicLong();
private Thread managerThread;
@VisibleForTesting
Thread managerThread;
protected final CommitLog commitLog;
private volatile boolean shutdown;
private final BooleanSupplier managerThreadWaitCondition = () -> (availableSegment == null && !atSegmentBufferLimit()) || shutdown;
@ -485,8 +486,11 @@ public abstract class AbstractCommitLogSegmentManager
*/
public void awaitTermination() throws InterruptedException
{
managerThread.join();
managerThread = null;
if (managerThread != null)
{
managerThread.join();
managerThread = null;
}
for (CommitLogSegment segment : activeSegments)
segment.close();

View File

@ -26,7 +26,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codahale.metrics.Timer.Context;
import org.apache.cassandra.concurrent.NamedThreadFactory;
import org.apache.cassandra.config.Config;
import org.apache.cassandra.db.commitlog.CommitLogSegment.Allocation;
@ -133,8 +132,7 @@ public abstract class AbstractCommitLogService
throw new IllegalArgumentException(String.format("Commit log flush interval must be positive: %fms",
syncIntervalNanos * 1e-6));
shutdown = false;
Runnable runnable = new SyncRunnable(MonotonicClock.preciseTime);
thread = NamedThreadFactory.createThread(runnable, name);
thread = NamedThreadFactory.createThread(new SyncRunnable(MonotonicClock.preciseTime), name);
thread.start();
}
@ -314,7 +312,8 @@ public abstract class AbstractCommitLogService
public void awaitTermination() throws InterruptedException
{
thread.join();
if (thread != null)
thread.join();
}
public long getCompletedTasks()

View File

@ -20,6 +20,7 @@ package org.apache.cassandra.db.commitlog;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.function.Function;
import java.util.zip.CRC32;
import com.google.common.annotations.VisibleForTesting;
@ -74,17 +75,24 @@ public class CommitLog implements CommitLogMBean
final AbstractCommitLogService executor;
volatile Configuration configuration;
private boolean started = false;
private static CommitLog construct()
{
CommitLog log = new CommitLog(CommitLogArchiver.construct());
CommitLog log = new CommitLog(CommitLogArchiver.construct(), DatabaseDescriptor.getCommitLogSegmentMgrProvider());
MBeanWrapper.instance.registerMBean(log, "org.apache.cassandra.db:type=Commitlog");
return log.start();
return log;
}
@VisibleForTesting
CommitLog(CommitLogArchiver archiver)
{
this(archiver, DatabaseDescriptor.getCommitLogSegmentMgrProvider());
}
@VisibleForTesting
CommitLog(CommitLogArchiver archiver, Function<CommitLog, AbstractCommitLogSegmentManager> segmentManagerProvider)
{
this.configuration = new Configuration(DatabaseDescriptor.getCommitLogCompression(),
DatabaseDescriptor.getEncryptionContext());
@ -108,18 +116,30 @@ public class CommitLog implements CommitLogMBean
throw new IllegalArgumentException("Unknown commitlog service type: " + DatabaseDescriptor.getCommitLogSync());
}
segmentManager = DatabaseDescriptor.isCDCEnabled()
? new CommitLogSegmentManagerCDC(this, DatabaseDescriptor.getCommitLogLocation())
: new CommitLogSegmentManagerStandard(this, DatabaseDescriptor.getCommitLogLocation());
segmentManager = segmentManagerProvider.apply(this);
// register metrics
metrics.attach(executor, segmentManager);
}
CommitLog start()
/**
* Tries to start the CommitLog if not already started.
*/
synchronized public CommitLog start()
{
segmentManager.start();
executor.start();
if (started)
return this;
try
{
segmentManager.start();
executor.start();
started = true;
} catch (Throwable t)
{
started = false;
throw t;
}
return this;
}
@ -404,8 +424,12 @@ public class CommitLog implements CommitLogMBean
* Shuts down the threads used by the commit log, blocking until completion.
* TODO this should accept a timeout, and throw TimeoutException
*/
public void shutdownBlocking() throws InterruptedException
synchronized public void shutdownBlocking() throws InterruptedException
{
if (!started)
return;
started = false;
executor.shutdown();
executor.awaitTermination();
segmentManager.shutdown();
@ -416,7 +440,8 @@ public class CommitLog implements CommitLogMBean
* FOR TESTING PURPOSES
* @return the number of files recovered
*/
public int resetUnsafe(boolean deleteSegments) throws IOException
@VisibleForTesting
synchronized public int resetUnsafe(boolean deleteSegments) throws IOException
{
stopUnsafe(deleteSegments);
resetConfiguration();
@ -426,7 +451,8 @@ public class CommitLog implements CommitLogMBean
/**
* FOR TESTING PURPOSES.
*/
public void resetConfiguration()
@VisibleForTesting
synchronized public void resetConfiguration()
{
configuration = new Configuration(DatabaseDescriptor.getCommitLogCompression(),
DatabaseDescriptor.getEncryptionContext());
@ -435,8 +461,10 @@ public class CommitLog implements CommitLogMBean
/**
* FOR TESTING PURPOSES
*/
public void stopUnsafe(boolean deleteSegments)
@VisibleForTesting
synchronized public void stopUnsafe(boolean deleteSegments)
{
started = false;
executor.shutdown();
try
{
@ -456,8 +484,10 @@ public class CommitLog implements CommitLogMBean
/**
* FOR TESTING PURPOSES
*/
public int restartUnsafe() throws IOException
@VisibleForTesting
synchronized public int restartUnsafe() throws IOException
{
started = false;
return start().recoverSegmentsOnDisk();
}

View File

@ -202,6 +202,8 @@ public class CassandraDaemon
NativeLibrary.tryMlockall();
CommitLog.instance.start();
try
{
startupChecks.verify();

View File

@ -45,6 +45,9 @@ public final class JVMStabilityInspector
private static Object lock = new Object();
private static boolean printingHeapHistogram;
// It is used for unit test
public static OnKillHook killerHook;
private JVMStabilityInspector() {}
/**
@ -169,11 +172,26 @@ public final class JVMStabilityInspector
t.printStackTrace(System.err);
logger.error("JVM state determined to be unstable. Exiting forcefully due to:", t);
}
if (killing.compareAndSet(false, true))
boolean doExit = killerHook != null ? killerHook.execute(t) : true;
if (doExit && killing.compareAndSet(false, true))
{
StorageService.instance.removeShutdownHook();
System.exit(100);
}
}
}
/**
* This class is usually used to avoid JVM exit when running junit tests.
*/
public interface OnKillHook
{
/**
*
* @return False will skip exit
*/
boolean execute(Throwable t);
}
}

View File

@ -323,6 +323,7 @@ public class Instance extends IsolatedExecutor implements IInvokableInstance
DatabaseDescriptor.daemonInitialization();
DatabaseDescriptor.createAllDirectories();
CommitLog.instance.start();
// We need to persist this as soon as possible after startup checks.
// This should be the first write to SystemKeyspace (CASSANDRA-11742)

View File

@ -0,0 +1,107 @@
/*
* 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.cassandra;
import java.io.IOException;
import java.net.URLClassLoader;
import java.util.function.Predicate;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
import org.apache.cassandra.distributed.impl.Versions;
/**
*
* This class is usually used to test singletons. It ensure singletons can be unique in each test case.
*
*/
public class CassandraIsolatedJunit4ClassRunner extends BlockJUnit4ClassRunner
{
private static final Predicate<String> isolatedPackage = name ->
name.startsWith("org.apache.cassandra.") ||
// YAML could not be shared because
// org.apache.cassandra.config.Config is loaded by org.yaml.snakeyaml.YAML
name.startsWith("org.yaml.snakeyaml.");
/**
* Creates a CassandraIsolatedJunit4ClassRunner to run {@code klass}
*
* @param clazz
* @throws InitializationError if the test class is malformed.
*/
public CassandraIsolatedJunit4ClassRunner(Class<?> clazz) throws InitializationError
{
super(createClassLoader(clazz));
}
private static Class<?> createClassLoader(Class<?> clazz) throws InitializationError {
try {
ClassLoader testClassLoader = new CassandraIsolatedClassLoader();
return Class.forName(clazz.getName(), true, testClassLoader);
} catch (ClassNotFoundException e) {
throw new InitializationError(e);
}
}
public static class CassandraIsolatedClassLoader extends URLClassLoader
{
public CassandraIsolatedClassLoader()
{
super(Versions.CURRENT.classpath);
}
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
{
if (isolatedPackage.test(name))
{
synchronized (getClassLoadingLock(name))
{
// First, check if the class has already been loaded
Class<?> c = findLoadedClass(name);
if (c == null)
c = findClass(name);
return c;
}
}
else
{
return super.loadClass(name);
}
}
protected void finalize()
{
try
{
close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}

View File

@ -86,6 +86,13 @@ public class DatabaseDescriptorRefTest
"org.apache.cassandra.config.YamlConfigurationLoader$CustomConstructor",
"org.apache.cassandra.config.TransparentDataEncryptionOptions",
"org.apache.cassandra.db.ConsistencyLevel",
"org.apache.cassandra.db.commitlog.CommitLogSegmentManagerFactory",
"org.apache.cassandra.db.commitlog.DefaultCommitLogSegmentMgrFactory",
"org.apache.cassandra.db.commitlog.AbstractCommitLogSegmentManager",
"org.apache.cassandra.db.commitlog.CommitLogSegmentManagerCDC",
"org.apache.cassandra.db.commitlog.CommitLogSegmentManagerStandard",
"org.apache.cassandra.db.commitlog.CommitLog",
"org.apache.cassandra.db.commitlog.CommitLogMBean",
"org.apache.cassandra.dht.IPartitioner",
"org.apache.cassandra.distributed.api.IInstance",
"org.apache.cassandra.distributed.api.IIsolatedExecutor",

View File

@ -202,6 +202,7 @@ public abstract class CQLTester
DatabaseDescriptor.daemonInitialization();
DatabaseDescriptor.setTransientReplicationEnabledUnsafe(true);
CommitLog.instance.start();
// Cleanup first
try
@ -241,6 +242,7 @@ public abstract class CQLTester
public static void cleanupAndLeaveDirs() throws IOException
{
// We need to stop and unmap all CLS instances prior to cleanup() or we'll get failures on Windows.
CommitLog.instance.start();
CommitLog.instance.stopUnsafe(true);
mkdirs();
cleanup();

View File

@ -28,6 +28,7 @@ import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import org.apache.cassandra.cql3.ColumnIdentifier;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.db.marshal.BytesType;
import org.junit.AfterClass;
import org.junit.Test;
@ -51,6 +52,7 @@ public class ColumnsTest
static
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
private static final TableMetadata TABLE_METADATA = MockSchema.newCFS().metadata();

View File

@ -25,6 +25,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.schema.SchemaConstants;
import org.apache.cassandra.cql3.QueryProcessor;
@ -45,6 +46,7 @@ public class SystemKeyspaceTest
public static void prepSnapshotTracker()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
if (FBUtilities.isWindows)
WindowsFailedSnapshotTracker.deleteOldSnapshots();

View File

@ -0,0 +1,110 @@
/*
* 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.cassandra.db.commitlog;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.cassandra.CassandraIsolatedJunit4ClassRunner;
import org.apache.cassandra.config.Config;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.utils.JVMStabilityInspector;
@RunWith(CassandraIsolatedJunit4ClassRunner.class)
public class CommitLogInitWithExceptionTest
{
private static Thread initThread;
@BeforeClass
public static void setUp()
{
DatabaseDescriptor.daemonInitialization();
if (DatabaseDescriptor.getDiskFailurePolicy() == Config.DiskFailurePolicy.die ||
DatabaseDescriptor.getDiskFailurePolicy() == Config.DiskFailurePolicy.ignore)
{
DatabaseDescriptor.setDiskFailurePolicy(Config.DiskFailurePolicy.stop);
}
DatabaseDescriptor.setCommitLogSegmentMgrProvider(c -> new MockCommitLogSegmentMgr(c, DatabaseDescriptor.getCommitLogLocation()));
JVMStabilityInspector.killerHook = (t) -> {
Assert.assertEquals("MOCK EXCEPTION: createSegment", t.getMessage());
try
{
// Avoid JVM exit. The JVM still needs to run other junit tests.
return false;
}
finally
{
Assert.assertNotNull(initThread);
// We have to manually stop init thread because the JVM does not exit actually.
initThread.stop();
}
};
}
@Test(timeout = 30000)
public void testCommitLogInitWithException() {
// This line will trigger initialization process because it's the first time to access CommitLog class.
initThread = new Thread(CommitLog.instance::start);
initThread.setName("initThread");
initThread.start();
try
{
initThread.join(); // Should not block here
}
catch (InterruptedException expected)
{
}
Assert.assertFalse(initThread.isAlive());
try
{
Thread.sleep(1000); // Wait for COMMIT-LOG-ALLOCATOR exit
}
catch (InterruptedException e)
{
Assert.fail();
}
Assert.assertEquals(Thread.State.TERMINATED, CommitLog.instance.segmentManager.managerThread.getState()); // exit successfully
}
private static class MockCommitLogSegmentMgr extends CommitLogSegmentManagerStandard {
public MockCommitLogSegmentMgr(CommitLog commitLog, String storageDirectory)
{
super(commitLog, storageDirectory);
}
@Override
public CommitLogSegment createSegment()
{
throw new RuntimeException("MOCK EXCEPTION: createSegment");
}
}
}

View File

@ -28,6 +28,7 @@ import org.junit.Test;
import org.apache.cassandra.Util;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.ClockAndCount;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.db.context.CounterContext.Relationship;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.CounterId;
@ -55,6 +56,7 @@ public class CounterContextTest
public static void setupDD()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@Test

View File

@ -33,6 +33,7 @@ import org.junit.Test;
import org.junit.Assert;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.db.compaction.OperationType;
import org.apache.cassandra.io.sstable.format.SSTableReader;
import org.apache.cassandra.schema.MockSchema;
@ -48,6 +49,7 @@ public class HelpersTest
public static void setUp()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
MockSchema.cleanup();
}

View File

@ -77,6 +77,7 @@ public class TrackerTest
public static void setUp()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
MockSchema.cleanup();
}

View File

@ -36,6 +36,7 @@ import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.Memtable;
import org.apache.cassandra.db.PartitionPosition;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.dht.AbstractBounds;
import org.apache.cassandra.io.sstable.format.SSTableReader;
import org.apache.cassandra.schema.MockSchema;
@ -52,6 +53,7 @@ public class ViewTest
public static void setUp()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
MockSchema.cleanup();
}

View File

@ -29,6 +29,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.service.StorageService;
import static org.junit.Assert.assertEquals;
@ -47,6 +48,7 @@ public abstract class PartitionerTestCase
public static void initDD()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@Before

View File

@ -19,6 +19,7 @@ package org.apache.cassandra.dht;
import java.util.Collections;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.locator.RangesAtEndpoint;
import org.junit.BeforeClass;
import org.junit.Test;
@ -42,6 +43,7 @@ public class StreamStateStoreTest
public static void initDD()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@Test

View File

@ -29,6 +29,7 @@ import org.junit.Test;
import org.apache.cassandra.Util;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.RandomPartitioner;
import org.apache.cassandra.dht.Token;
@ -47,6 +48,7 @@ public class FailureDetectorTest
System.setProperty("cassandra.max_local_pause_in_ms", "20000");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@Test

View File

@ -34,6 +34,7 @@ import org.junit.Test;
import org.apache.cassandra.Util;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.RandomPartitioner;
import org.apache.cassandra.dht.Token;
@ -52,6 +53,7 @@ public class GossiperTest
{
System.setProperty(Gossiper.Props.DISABLE_THREAD_VALIDATION, "true");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
static final IPartitioner partitioner = new RandomPartitioner();

View File

@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.locator.IEndpointSnitch;
import org.apache.cassandra.locator.PropertyFileSnitch;
@ -53,6 +54,7 @@ public class ShadowRoundTest
System.setProperty("cassandra.config", "cassandra-seeds.yaml");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
IEndpointSnitch snitch = new PropertyFileSnitch();
DatabaseDescriptor.setEndpointSnitch(snitch);
Keyspace.setInitialized();

View File

@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.schema.TableMetadata;
import org.apache.cassandra.schema.ColumnMetadata;
import org.apache.cassandra.config.DatabaseDescriptor;
@ -63,6 +64,7 @@ public class SSTableFlushObserverTest
public static void initDD()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
private static final String KS_NAME = "test";

View File

@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
@ -43,6 +44,7 @@ public class AlibabaCloudSnitchTest
{
System.setProperty(Gossiper.Props.DISABLE_THREAD_VALIDATION, "true");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
SchemaLoader.mkdirs();
SchemaLoader.cleanup();
Keyspace.setInitialized();

View File

@ -29,6 +29,7 @@ import org.junit.Test;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
@ -46,6 +47,7 @@ public class CloudstackSnitchTest
{
System.setProperty(Gossiper.Props.DISABLE_THREAD_VALIDATION, "true");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
SchemaLoader.mkdirs();
SchemaLoader.cleanup();
Keyspace.setInitialized();

View File

@ -34,6 +34,7 @@ import org.junit.Test;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
@ -60,6 +61,7 @@ public class EC2SnitchTest
{
System.setProperty(Gossiper.Props.DISABLE_THREAD_VALIDATION, "true");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
SchemaLoader.mkdirs();
SchemaLoader.cleanup();
Keyspace.setInitialized();

View File

@ -30,6 +30,7 @@ import org.junit.Test;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
@ -47,6 +48,7 @@ public class GoogleCloudSnitchTest
{
System.setProperty(Gossiper.Props.DISABLE_THREAD_VALIDATION, "true");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
SchemaLoader.mkdirs();
SchemaLoader.cleanup();
Keyspace.setInitialized();

View File

@ -31,6 +31,7 @@ import com.google.common.collect.Iterators;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.UntypedResultSet;
import org.apache.cassandra.db.SystemKeyspace;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.db.marshal.Int32Type;
import org.apache.cassandra.db.marshal.UUIDType;
import org.apache.cassandra.hints.HintsService;
@ -45,6 +46,7 @@ public class HintedHandOffMetricsTest
public static void initDD()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@Test

View File

@ -55,6 +55,7 @@ import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.EncryptionOptions;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.exceptions.RequestFailureReason;
import org.apache.cassandra.exceptions.UnknownColumnException;
import org.apache.cassandra.io.IVersionedAsymmetricSerializer;
@ -119,6 +120,7 @@ public class ConnectionTest
public static void startup()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@AfterClass

View File

@ -31,6 +31,7 @@ import org.junit.Test;
import io.netty.channel.EventLoop;
import io.netty.util.concurrent.Future;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.net.OutboundConnectionInitiator.Result;
import org.apache.cassandra.net.OutboundConnectionInitiator.Result.MessagingSuccess;
@ -51,6 +52,7 @@ public class HandshakeTest
public static void startup()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@AfterClass

View File

@ -43,6 +43,7 @@ import com.codahale.metrics.Timer;
import org.apache.cassandra.auth.IInternodeAuthenticator;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.EncryptionOptions.ServerEncryptionOptions;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.metrics.MessagingMetrics;
import org.apache.cassandra.utils.ApproximateTime;
import org.apache.cassandra.exceptions.ConfigurationException;
@ -84,6 +85,7 @@ public class MessagingServiceTest
public static void beforeClass() throws UnknownHostException
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
DatabaseDescriptor.setBackPressureStrategy(new MockBackPressureStrategy(Collections.emptyMap()));
DatabaseDescriptor.setBroadcastAddress(InetAddress.getByName("127.0.0.1"));
originalAuthenticator = DatabaseDescriptor.getInternodeAuthenticator();

View File

@ -28,6 +28,7 @@ import org.junit.Test;
import org.apache.cassandra.config.Config;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.locator.AbstractEndpointSnitch;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.locator.Replica;
@ -44,6 +45,7 @@ public class OutboundConnectionSettingsTest
public static void before()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@Test (expected = IllegalArgumentException.class)

View File

@ -33,6 +33,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.gms.GossipDigestSyn;
import org.apache.cassandra.io.IVersionedSerializer;
import org.apache.cassandra.io.util.DataInputPlus;
@ -59,6 +60,7 @@ public class OutboundConnectionsTest
public static void before()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
@Before

View File

@ -32,6 +32,7 @@ import org.junit.*;
import org.apache.cassandra.Util;
import org.apache.cassandra.concurrent.NamedThreadFactory;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.dht.IPartitioner;
import org.apache.cassandra.dht.RandomPartitioner;
import org.apache.cassandra.dht.Token;
@ -55,6 +56,7 @@ public class RemoveTest
static
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
static final IPartitioner partitioner = RandomPartitioner.instance;

View File

@ -37,6 +37,7 @@ import org.apache.cassandra.OrderedJUnit4ClassRunner;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.audit.AuditLogManager;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.gms.VersionedValue;
@ -72,6 +73,7 @@ public class StorageServiceServerTest
{
System.setProperty(Gossiper.Props.DISABLE_THREAD_VALIDATION, "true");
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
IEndpointSnitch snitch = new PropertyFileSnitch();
DatabaseDescriptor.setEndpointSnitch(snitch);
Keyspace.setInitialized();

View File

@ -46,9 +46,9 @@ public class IdleDisconnectTest extends CQLTester
DatabaseDescriptor.setNativeTransportIdleTimeout(TIMEOUT);
try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort))
{
long start = System.currentTimeMillis();
client.connect(false, false);
Assert.assertTrue(client.channel.isOpen());
long start = System.currentTimeMillis();
CompletableFuture.runAsync(() -> {
while (!Thread.currentThread().isInterrupted() && client.channel.isOpen());
}).get(30, TimeUnit.SECONDS);
@ -63,9 +63,9 @@ public class IdleDisconnectTest extends CQLTester
long sleepTime = 1000;
try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort))
{
long start = System.currentTimeMillis();
client.connect(false, false);
Assert.assertTrue(client.channel.isOpen());
long start = System.currentTimeMillis();
Thread.sleep(sleepTime);
client.execute("SELECT * FROM system.peers", ConsistencyLevel.ONE);
CompletableFuture.runAsync(() -> {

View File

@ -24,6 +24,7 @@ import org.junit.Test;
import org.junit.Assert;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.commitlog.CommitLog;
@Ignore
public abstract class AbstractTransactionalTest
@ -32,6 +33,7 @@ public abstract class AbstractTransactionalTest
public static void setupDD()
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
protected abstract TestableTransaction newTest() throws Exception;

View File

@ -34,6 +34,7 @@ import org.apache.cassandra.cql3.statements.schema.CreateTableStatement;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.Directories;
import org.apache.cassandra.db.SystemKeyspace;
import org.apache.cassandra.db.commitlog.CommitLog;
import org.apache.cassandra.db.compaction.CompactionManager;
import org.apache.cassandra.db.lifecycle.LifecycleTransaction;
import org.apache.cassandra.dht.IPartitioner;
@ -75,6 +76,7 @@ public abstract class CompactionStress implements Runnable
static
{
DatabaseDescriptor.daemonInitialization();
CommitLog.instance.start();
}
List<File> getDataDirectories()