本文整理汇总了Java中org.apache.cassandra.db.commitlog.CommitLog类的典型用法代码示例。如果您正苦于以下问题:Java CommitLog类的具体用法?Java CommitLog怎么用?Java CommitLog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommitLog类属于org.apache.cassandra.db.commitlog包,在下文中一共展示了CommitLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExceedRecordLimit
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testExceedRecordLimit() throws Exception
{
CommitLog.instance.resetUnsafe();
try
{
Mutation rm = new Mutation("Keyspace1", bytes("k"));
rm.add("Standard1", Util.cellname("c1"), ByteBuffer.allocate(1 + getMaxRecordDataSize()), 0);
CommitLog.instance.add(rm);
throw new AssertionError("mutation larger than limit was accepted");
}
catch (IllegalArgumentException e)
{
// IAE is thrown on too-large mutations
}
}
示例2: testCommitFailurePolicy_stop
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testCommitFailurePolicy_stop() throws ConfigurationException
{
// Need storage service active so stop policy can shutdown gossip
StorageService.instance.initServer();
Assert.assertTrue(Gossiper.instance.isEnabled());
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try
{
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.stop);
CommitLog.handleCommitError("Test stop error", new Throwable());
Assert.assertFalse(Gossiper.instance.isEnabled());
}
finally
{
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
}
}
示例3: testCommitFailurePolicy_die
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testCommitFailurePolicy_die()
{
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try
{
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.die);
CommitLog.handleCommitError("Testing die policy", new Throwable());
Assert.assertTrue(killerForTests.wasKilled());
}
finally
{
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
示例4: testTruncate
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testTruncate() throws IOException
{
Keyspace keyspace = Keyspace.open("Keyspace1");
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
Mutation rm;
ColumnFamily cf;
// add a single cell
cf = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1");
cf.addColumn(column("col1", "val1", 1L));
rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("keymulti"), cf);
rm.apply();
// Make sure data was written
assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
// and now truncate it
cfs.truncateBlocking();
CommitLog.instance.resetUnsafe();
CommitLog.instance.recover();
// and validate truncation.
assertNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
}
示例5: prepareServer
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
public static void prepareServer()
{
// Cleanup first
cleanupAndLeaveDirs();
CommitLog.instance.allocator.enableReserveSegmentCreation();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{
public void uncaughtException(Thread t, Throwable e)
{
logger.error("Fatal exception in thread " + t, e);
}
});
Keyspace.setInitialized();
}
示例6: testTruncate
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testTruncate() throws IOException, ExecutionException, InterruptedException
{
Keyspace keyspace = Keyspace.open("Keyspace1");
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");
RowMutation rm;
ColumnFamily cf;
// add a single cell
cf = TreeMapBackedSortedColumns.factory.create("Keyspace1", "Standard1");
cf.addColumn(column("col1", "val1", 1L));
rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("keymulti"), cf);
rm.apply();
// Make sure data was written
assertNotNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
// and now truncate it
cfs.truncateBlocking();
CommitLog.instance.resetUnsafe();
CommitLog.instance.recover();
// and validate truncation.
assertNull(getFromTable(keyspace, "Standard1", "keymulti", "col1"));
}
示例7: loadSchema
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
public static void loadSchema(boolean withOldCfIds) throws IOException, ConfigurationException
{
// Cleanup first
cleanupAndLeaveDirs();
CommitLog.instance.allocator.enableReserveSegmentCreation();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{
public void uncaughtException(Thread t, Throwable e)
{
logger.error("Fatal exception in thread " + t, e);
}
});
// Migrations aren't happy if gossiper is not started. Even if we don't use migrations though,
// some tests now expect us to start gossip for them.
startGossiper();
// if you're messing with low-level sstable stuff, it can be useful to inject the schema directly
// Schema.instance.load(schemaDefinition(withOldCfIds));
for (KSMetaData ksm : schemaDefinition(withOldCfIds))
MigrationManager.announceNewKeyspace(ksm);
}
示例8: flushAndExpectError
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
public void flushAndExpectError() throws InterruptedException, ExecutionException
{
try
{
Keyspace.open(KEYSPACE).getColumnFamilyStore(currentTable()).forceFlush().get();
fail("FSWriteError expected.");
}
catch (ExecutionException e)
{
// Correct path.
Assert.assertTrue(e.getCause() instanceof FSWriteError);
}
// Make sure commit log wasn't discarded.
UUID cfid = currentTableMetadata().cfId;
for (CommitLogSegment segment : CommitLog.instance.allocator.getActiveSegments())
if (segment.getDirtyCFIDs().contains(cfid))
return;
fail("Expected commit log to remain dirty for the affected table.");
}
示例9: testCommitFailurePolicy_stop
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testCommitFailurePolicy_stop() throws ConfigurationException
{
CassandraDaemon daemon = new CassandraDaemon();
daemon.completeSetup(); //startup must be completed, otherwise commit log failure must kill JVM regardless of failure policy
StorageService.instance.registerDaemon(daemon);
// Need storage service active so stop policy can shutdown gossip
StorageService.instance.initServer();
Assert.assertTrue(Gossiper.instance.isEnabled());
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try
{
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.stop);
CommitLog.handleCommitError("Test stop error", new Throwable());
Assert.assertFalse(Gossiper.instance.isEnabled());
}
finally
{
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
}
}
示例10: testCommitFailurePolicy_die
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testCommitFailurePolicy_die()
{
CassandraDaemon daemon = new CassandraDaemon();
daemon.completeSetup(); //startup must be completed, otherwise commit log failure must kill JVM regardless of failure policy
StorageService.instance.registerDaemon(daemon);
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try
{
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.die);
CommitLog.handleCommitError("Testing die policy", new Throwable());
Assert.assertTrue(killerForTests.wasKilled());
Assert.assertFalse(killerForTests.wasKilledQuietly()); //only killed quietly on startup failure
}
finally
{
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
示例11: testCommitFailurePolicy_ignore_beforeStartup
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testCommitFailurePolicy_ignore_beforeStartup()
{
//startup was not completed successfuly (since method completeSetup() was not called)
CassandraDaemon daemon = new CassandraDaemon();
StorageService.instance.registerDaemon(daemon);
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try
{
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.ignore);
CommitLog.handleCommitError("Testing ignore policy", new Throwable());
//even though policy is ignore, JVM must die because Daemon has not finished initializing
Assert.assertTrue(killerForTests.wasKilled());
Assert.assertTrue(killerForTests.wasKilledQuietly()); //killed quietly due to startup failure
}
finally
{
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
示例12: testCommitFailurePolicy_ignore_afterStartup
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testCommitFailurePolicy_ignore_afterStartup() throws Exception
{
CassandraDaemon daemon = new CassandraDaemon();
daemon.completeSetup(); //startup must be completed, otherwise commit log failure must kill JVM regardless of failure policy
StorageService.instance.registerDaemon(daemon);
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try
{
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.ignore);
CommitLog.handleCommitError("Testing ignore policy", new Throwable());
//error policy is set to IGNORE, so JVM must not be killed if error ocurs after startup
Assert.assertFalse(killerForTests.wasKilled());
}
finally
{
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
示例13: testOne
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testOne() throws IOException
{
CommitLog.instance.resetUnsafe(true);
Keyspace keyspace1 = Keyspace.open(KEYSPACE1);
Keyspace keyspace2 = Keyspace.open(KEYSPACE2);
UnfilteredRowIterator upd1 = Util.apply(new RowUpdateBuilder(keyspace1.getColumnFamilyStore(CF_STANDARD1).metadata, 1L, 0, "keymulti")
.clustering("col1").add("val", "1")
.build());
UnfilteredRowIterator upd2 = Util.apply(new RowUpdateBuilder(keyspace2.getColumnFamilyStore(CF_STANDARD3).metadata, 1L, 0, "keymulti")
.clustering("col2").add("val", "1")
.build());
keyspace1.getColumnFamilyStore("Standard1").clearUnsafe();
keyspace2.getColumnFamilyStore("Standard3").clearUnsafe();
CommitLog.instance.resetUnsafe(false);
DecoratedKey dk = Util.dk("keymulti");
Assert.assertTrue(Util.equal(upd1, Util.getOnlyPartitionUnfiltered(Util.cmd(keyspace1.getColumnFamilyStore(CF_STANDARD1), dk).build()).unfilteredIterator()));
Assert.assertTrue(Util.equal(upd2, Util.getOnlyPartitionUnfiltered(Util.cmd(keyspace2.getColumnFamilyStore(CF_STANDARD3), dk).build()).unfilteredIterator()));
}
示例14: testRecoverCounter
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testRecoverCounter() throws IOException
{
CommitLog.instance.resetUnsafe(true);
Keyspace keyspace1 = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace1.getColumnFamilyStore(CF_COUNTER1);
for (int i = 0; i < 10; ++i)
{
new CounterMutation(new RowUpdateBuilder(cfs.metadata, 1L, 0, "key")
.clustering("cc").add("val", CounterContext.instance().createLocal(1L))
.build(), ConsistencyLevel.ALL).apply();
}
keyspace1.getColumnFamilyStore("Counter1").clearUnsafe();
int replayed = CommitLog.instance.resetUnsafe(false);
ColumnDefinition counterCol = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
Row row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val").build());
assertEquals(10L, CounterContext.instance().total(row.getCell(counterCol).value()));
}
示例15: testExceedRecordLimit
import org.apache.cassandra.db.commitlog.CommitLog; //导入依赖的package包/类
@Test
public void testExceedRecordLimit() throws Exception
{
CommitLog.instance.resetUnsafe();
try
{
Mutation rm = new Mutation(KEYSPACE1, bytes("k"));
rm.add(CF1, Util.cellname("c1"), ByteBuffer.allocate(1 + getMaxRecordDataSize()), 0);
CommitLog.instance.add(rm);
throw new AssertionError("mutation larger than limit was accepted");
}
catch (IllegalArgumentException e)
{
// IAE is thrown on too-large mutations
}
}