当前位置: 首页>>代码示例>>Java>>正文


Java Keyspace.getColumnFamilyStore方法代码示例

本文整理汇总了Java中org.apache.cassandra.db.Keyspace.getColumnFamilyStore方法的典型用法代码示例。如果您正苦于以下问题:Java Keyspace.getColumnFamilyStore方法的具体用法?Java Keyspace.getColumnFamilyStore怎么用?Java Keyspace.getColumnFamilyStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.db.Keyspace的用法示例。


在下文中一共展示了Keyspace.getColumnFamilyStore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStore

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
private ColumnFamilyStore getStore(String ksName, String cfName) {
    // Start by validating keyspace name
    if (Schema.instance.getKSMetaData(ksName) == null) {
        System.err.println(String.format("Reference to nonexistent keyspace: %s!", ksName));
        System.exit(1);
    }
    Keyspace keyspace = Keyspace.open(ksName);

    // Make it works for indexes too - find parent cf if necessary
    String baseName = cfName;
    if (cfName.contains(".")) {
        String[] parts = cfName.split("\\.", 2);
        baseName = parts[0];
    }

    // IllegalArgumentException will be thrown here if ks/cf pair does not exist
    try {
        return keyspace.getColumnFamilyStore(baseName);
    } catch (Throwable t) {
        System.err.println(String.format(
                "The provided column family is not part of this cassandra keyspace: keyspace = %s, column family = %s",
                ksName, cfName));
        System.exit(1);
    }
    return null;
}
 
开发者ID:instaclustr,项目名称:cassandra-sstable-tools,代码行数:27,代码来源:CassandraBackend.java

示例2: antiCompactionSizeTest

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void antiCompactionSizeTest() throws ExecutionException, InterruptedException, IOException
{
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    cfs.disableAutoCompaction();
    SSTableReader s = writeFile(cfs, 1000);
    cfs.addSSTable(s);
    long origSize = s.bytesOnDisk();
    Range<Token> range = new Range<Token>(new BytesToken(ByteBufferUtil.bytes(0)), new BytesToken(ByteBufferUtil.bytes(500)));
    Collection<SSTableReader> sstables = cfs.getSSTables();
    CompactionManager.instance.performAnticompaction(cfs, Arrays.asList(range), Refs.tryRef(sstables), 12345);
    long sum = 0;
    for (SSTableReader x : cfs.getSSTables())
        sum += x.bytesOnDisk();
    assertEquals(sum, cfs.metric.liveDiskSpaceUsed.count());
    assertEquals(origSize, cfs.metric.liveDiskSpaceUsed.count(), 100000);

}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:20,代码来源:AntiCompactionTest.java

示例3: testSSTableSplit

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testSSTableSplit() throws InterruptedException
{
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    truncate(cfs);
    cfs.disableAutoCompaction();
    SSTableReader s = writeFile(cfs, 1000);
    try (LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.UNKNOWN, s))
    {
        SSTableSplitter splitter = new SSTableSplitter(cfs, txn, 10);
        splitter.split();

        assertFileCounts(s.descriptor.directory.list());
        LifecycleTransaction.waitForDeletions();

        for (File f : s.descriptor.directory.listFiles())
        {
            // we need to clear out the data dir, otherwise tests running after this breaks
            FileUtils.deleteRecursive(f);
        }
    }
    truncate(cfs);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:25,代码来源:SSTableRewriterTest.java

示例4: testGetScannerForNoIntersectingRanges

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
/** see CASSANDRA-5407 */
@Test
public void testGetScannerForNoIntersectingRanges()
{
    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard1");
    ByteBuffer key = ByteBufferUtil.bytes(String.valueOf("k1"));
    Mutation rm = new Mutation("Keyspace1", key);
    rm.add("Standard1", cellname("xyz"), ByteBufferUtil.bytes("abc"), 0);
    rm.apply();
    store.forceBlockingFlush();
    boolean foundScanner = false;
    for (SSTableReader s : store.getSSTables())
    {
        ISSTableScanner scanner = s.getScanner(new Range<Token>(t(0), t(1), s.partitioner), null);
        scanner.next(); // throws exception pre 5407
        foundScanner = true;
    }
    assertTrue(foundScanner);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:21,代码来源:SSTableReaderTest.java

示例5: testRewriteAborted

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testRewriteAborted() throws IOException
{
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(REWRITE_ABORTED_CF);

    SSTableReader oldSSTable = getSSTable(cfs, 1);
    LifecycleTransaction txn = cfs.getTracker().tryModify(oldSSTable, OperationType.COMPACTION);

    replaceSSTable(cfs, txn, true);
    LogTransaction.waitForDeletions();

    assertFiles(oldSSTable.descriptor.directory.getPath(), new HashSet<>(oldSSTable.getAllFilePaths()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:15,代码来源:RealTransactionsTest.java

示例6: testFilterOldSSTables

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testFilterOldSSTables()
{
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    cfs.disableAutoCompaction();

    ByteBuffer value = ByteBuffer.wrap(new byte[100]);

    // create 3 sstables
    int numSSTables = 3;
    for (int r = 0; r < numSSTables; r++)
    {
        DecoratedKey key = Util.dk(String.valueOf(r));
        new RowUpdateBuilder(cfs.metadata, r, key.getKey())
            .clustering("column")
            .add("val", value).build().applyUnsafe();

        cfs.forceBlockingFlush();
    }
    cfs.forceBlockingFlush();

    Iterable<SSTableReader> filtered;
    List<SSTableReader> sstrs = new ArrayList<>(cfs.getLiveSSTables());

    filtered = filterOldSSTables(sstrs, 0, 2);
    assertEquals("when maxSSTableAge is zero, no sstables should be filtered", sstrs.size(), Iterables.size(filtered));

    filtered = filterOldSSTables(sstrs, 1, 2);
    assertEquals("only the newest 2 sstables should remain", 2, Iterables.size(filtered));

    filtered = filterOldSSTables(sstrs, 1, 3);
    assertEquals("only the newest sstable should remain", 1, Iterables.size(filtered));

    filtered = filterOldSSTables(sstrs, 1, 4);
    assertEquals("no sstables should remain when all are too old", 0, Iterables.size(filtered));
    cfs.truncateBlocking();
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:39,代码来源:DateTieredCompactionStrategyTest.java

示例7: prepareColumnFamilyStore

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
private ColumnFamilyStore prepareColumnFamilyStore()
{
    Keyspace keyspace = Keyspace.open(KEYSPACE5);
    ColumnFamilyStore store = keyspace.getColumnFamilyStore(CF_STANDARD1);
    store.truncateBlocking();
    store.disableAutoCompaction();
    createSSTables(store, 10);
    return store;
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:10,代码来源:ActiveRepairServiceTest.java

示例8: testFlush

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testFlush() throws IOException
{
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(FLUSH_CF);

    SSTableReader ssTableReader = getSSTable(cfs, 100);

    String dataFolder = cfs.getLiveSSTables().iterator().next().descriptor.directory.getPath();
    assertFiles(dataFolder, new HashSet<>(ssTableReader.getAllFilePaths()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:12,代码来源:RealTransactionsTest.java

示例9: beforeTest

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Before
public void beforeTest()
{
    String ksname = KEYSPACE1;
    String cfname = CF_STANDARDLOWiINTERVAL; // index interval of 8, no key caching
    Keyspace keyspace = Keyspace.open(ksname);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    originalMinIndexInterval = cfs.metadata.params.minIndexInterval;
    originalMaxIndexInterval = cfs.metadata.params.maxIndexInterval;
    originalCapacity = IndexSummaryManager.instance.getMemoryPoolCapacityInMB();
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:12,代码来源:IndexSummaryManagerTest.java

示例10: testDifference

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testDifference() throws Throwable
{
    Range<Token> range = new Range<>(partirioner.getMinimumToken(), partirioner.getRandomToken());
    UUID parentRepairSession = UUID.randomUUID();
    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1");

    ActiveRepairService.instance.registerParentRepairSession(parentRepairSession, Arrays.asList(cfs), Arrays.asList(range));

    RepairJobDesc desc = new RepairJobDesc(parentRepairSession, UUID.randomUUID(), "Keyspace1", "Standard1", range);

    MerkleTree tree1 = createInitialTree(desc);
    MerkleTree tree2 = createInitialTree(desc);

    // change a range in one of the trees
    Token token = partirioner.midpoint(range.left, range.right);
    tree1.invalidate(token);
    MerkleTree.TreeRange changed = tree1.get(token);
    changed.hash("non-empty hash!".getBytes());

    Set<Range<Token>> interesting = new HashSet<>();
    interesting.add(changed);

    // difference the trees
    // note: we reuse the same endpoint which is bogus in theory but fine here
    TreeResponse r1 = new TreeResponse(InetAddress.getByName("127.0.0.1"), tree1);
    TreeResponse r2 = new TreeResponse(InetAddress.getByName("127.0.0.2"), tree2);
    Differencer diff = new Differencer(desc, r1, r2);
    diff.run();

    // ensure that the changed range was recorded
    assertEquals("Wrong differing ranges", interesting, new HashSet<>(diff.differences));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:35,代码来源:DifferencerTest.java

示例11: testGetFullyExpiredSSTables

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testGetFullyExpiredSSTables()
{
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF2);
    cfs.truncateBlocking();

    DecoratedKey key = Util.dk("k1");

    long timestamp1 = FBUtilities.timestampMicros(); // latest timestamp
    long timestamp2 = timestamp1 - 5;
    long timestamp3 = timestamp2 - 5; // oldest timestamp

    // create sstable with tombstone that should be expired in no older timestamps
    applyDeleteMutation(cfs.metadata, key, timestamp2);
    cfs.forceBlockingFlush();

    // first sstable with tombstone is compacting
    Set<SSTableReader> compacting = Sets.newHashSet(cfs.getLiveSSTables());

    // create another sstable with more recent timestamp
    applyMutation(cfs.metadata, key, timestamp1);
    cfs.forceBlockingFlush();

    // second sstable is overlapping
    Set<SSTableReader> overlapping = Sets.difference(Sets.newHashSet(cfs.getLiveSSTables()), compacting);

    // the first sstable should be expired because the overlapping sstable is newer and the gc period is later
    int gcBefore = (int) (System.currentTimeMillis() / 1000) + 5;
    Set<SSTableReader> expired = CompactionController.getFullyExpiredSSTables(cfs, compacting, overlapping, gcBefore);
    assertNotNull(expired);
    assertEquals(1, expired.size());
    assertEquals(compacting.iterator().next(), expired.iterator().next());

    // however if we add an older mutation to the memtable then the sstable should not be expired
    applyMutation(cfs.metadata, key, timestamp3);
    expired = CompactionController.getFullyExpiredSSTables(cfs, compacting, overlapping, gcBefore);
    assertNotNull(expired);
    assertEquals(0, expired.size());
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:41,代码来源:CompactionControllerTest.java

示例12: testTwoWriters

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
/**
 * emulates anticompaction - writing from one source sstable to two new sstables
 *
 * @throws IOException
 */
@Test
public void testTwoWriters() throws IOException
{
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    truncate(cfs);

    SSTableReader s = writeFile(cfs, 1000);
    cfs.addSSTable(s);
    Set<SSTableReader> sstables = Sets.newHashSet(s);
    assertEquals(1, sstables.size());
    int nowInSec = FBUtilities.nowInSeconds();
    try (AbstractCompactionStrategy.ScannerList scanners = cfs.getCompactionStrategyManager().getScanners(sstables);
         LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.UNKNOWN);
         SSTableRewriter writer = new SSTableRewriter(txn, 1000, false, false);
         SSTableRewriter writer2 = new SSTableRewriter(txn, 1000, false, false);
         CompactionController controller = new CompactionController(cfs, sstables, cfs.gcBefore(nowInSec));
         CompactionIterator ci = new CompactionIterator(OperationType.COMPACTION, scanners.scanners, controller, nowInSec, UUIDGen.getTimeUUID())
         )
    {
        writer.switchWriter(getWriter(cfs, sstables.iterator().next().descriptor.directory, txn));
        writer2.switchWriter(getWriter(cfs, sstables.iterator().next().descriptor.directory, txn));
        while (ci.hasNext())
        {
            if (writer.currentWriter().getFilePointer() < 15000000)
                writer.append(ci.next());
            else
                writer2.append(ci.next());
        }
        for (int i = 0; i < 5000; i++)
            assertFalse(Util.getOnlyPartition(Util.cmd(cfs, ByteBufferUtil.bytes(i)).build()).isEmpty());
    }
    truncateCF();
    validateCFS(cfs);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:41,代码来源:SSTableRewriterTest.java

示例13: testNumberOfFiles_truncate

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
@Test
public void testNumberOfFiles_truncate() throws Exception
{
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    truncate(cfs);
    cfs.disableAutoCompaction();

    SSTableReader s = writeFile(cfs, 1000);
    cfs.addSSTable(s);
    Set<SSTableReader> compacting = Sets.newHashSet(s);

    List<SSTableReader> sstables;
    int files = 1;
    try (ISSTableScanner scanner = s.getScanner();
         CompactionController controller = new CompactionController(cfs, compacting, 0);
         LifecycleTransaction txn = cfs.getTracker().tryModify(compacting, OperationType.UNKNOWN);
         SSTableRewriter rewriter = new SSTableRewriter(txn, 1000, false, 10000000, false);
         CompactionIterator ci = new CompactionIterator(OperationType.COMPACTION, Collections.singletonList(scanner), controller, FBUtilities.nowInSeconds(), UUIDGen.getTimeUUID()))
    {
        rewriter.switchWriter(getWriter(cfs, s.descriptor.directory, txn));
        while(ci.hasNext())
        {
            rewriter.append(ci.next());
            if (rewriter.currentWriter().getOnDiskFilePointer() > 25000000)
            {
                rewriter.switchWriter(getWriter(cfs, s.descriptor.directory, txn));
                files++;
                assertEquals(cfs.getLiveSSTables().size(), files); // we have one original file plus the ones we have switched out.
            }
        }

        sstables = rewriter.finish();
    }

    LifecycleTransaction.waitForDeletions();
    assertFileCounts(s.descriptor.directory.list());
    validateCFS(cfs);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:40,代码来源:SSTableRewriterTest.java

示例14: testNumberOfFiles_abort

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
private void testNumberOfFiles_abort(RewriterTest test) throws Exception
{
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF);
    truncate(cfs);

    SSTableReader s = writeFile(cfs, 1000);
    cfs.addSSTable(s);

    DecoratedKey origFirst = s.first;
    DecoratedKey origLast = s.last;
    long startSize = cfs.metric.liveDiskSpaceUsed.getCount();
    Set<SSTableReader> compacting = Sets.newHashSet(s);
    try (ISSTableScanner scanner = s.getScanner();
         CompactionController controller = new CompactionController(cfs, compacting, 0);
         LifecycleTransaction txn = cfs.getTracker().tryModify(compacting, OperationType.UNKNOWN);
         SSTableRewriter rewriter = new SSTableRewriter(txn, 1000, false, 10000000, false))
    {
        rewriter.switchWriter(getWriter(cfs, s.descriptor.directory, txn));
        test.run(scanner, controller, s, cfs, rewriter, txn);
    }

    LifecycleTransaction.waitForDeletions();

    assertEquals(startSize, cfs.metric.liveDiskSpaceUsed.getCount());
    assertEquals(1, cfs.getLiveSSTables().size());
    assertFileCounts(s.descriptor.directory.list());
    assertEquals(cfs.getLiveSSTables().iterator().next().first, origFirst);
    assertEquals(cfs.getLiveSSTables().iterator().next().last, origLast);
    validateCFS(cfs);
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:32,代码来源:SSTableRewriterTest.java

示例15: testGetPositionsKeyCacheStats

import org.apache.cassandra.db.Keyspace; //导入方法依赖的package包/类
public void testGetPositionsKeyCacheStats() throws IOException, ExecutionException, InterruptedException
{
    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore store = keyspace.getColumnFamilyStore("Standard2");
    CacheService.instance.keyCache.setCapacity(1000);

    // insert data and compact to a single sstable
    CompactionManager.instance.disableAutoCompaction();
    for (int j = 0; j < 10; j++)
    {
        ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j));
        Mutation rm = new Mutation("Keyspace1", key);
        rm.add("Standard2", cellname("0"), ByteBufferUtil.EMPTY_BYTE_BUFFER, j);
        rm.apply();
    }
    store.forceBlockingFlush();
    CompactionManager.instance.performMaximal(store);

    SSTableReader sstable = store.getSSTables().iterator().next();
    sstable.getPosition(k(2), SSTableReader.Operator.EQ);
    assertEquals(0, sstable.getKeyCacheHit());
    assertEquals(1, sstable.getBloomFilterTruePositiveCount());
    sstable.getPosition(k(2), SSTableReader.Operator.EQ);
    assertEquals(1, sstable.getKeyCacheHit());
    assertEquals(2, sstable.getBloomFilterTruePositiveCount());
    sstable.getPosition(k(15), SSTableReader.Operator.EQ);
    assertEquals(1, sstable.getKeyCacheHit());
    assertEquals(2, sstable.getBloomFilterTruePositiveCount());

}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:31,代码来源:SSTableReaderTest.java


注:本文中的org.apache.cassandra.db.Keyspace.getColumnFamilyStore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。