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


Java CounterContext类代码示例

本文整理汇总了Java中org.apache.cassandra.db.context.CounterContext的典型用法代码示例。如果您正苦于以下问题:Java CounterContext类的具体用法?Java CounterContext怎么用?Java CounterContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: toString

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
@Override
public String toString()
{
    if (isCounterCell())
        return String.format("[%s=%d ts=%d]", column().name, CounterContext.instance().total(value()), timestamp());

    AbstractType<?> type = column().type;
    if (type instanceof CollectionType && type.isMultiCell())
    {
        CollectionType ct = (CollectionType)type;
        return String.format("[%s[%s]=%s %s]",
                             column().name,
                             ct.nameComparator().getString(path().get(0)),
                             ct.valueComparator().getString(value()),
                             livenessInfoString());
    }
    if (isTombstone())
        return String.format("[%s=<tombstone> %s]", column().name, livenessInfoString());
    else
        return String.format("[%s=%s %s]", column().name, type.getString(value()), livenessInfoString());
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:22,代码来源:AbstractCell.java

示例2: deserialize

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
public Future<Pair<CounterCacheKey, ClockAndCount>> deserialize(DataInputStream in, final ColumnFamilyStore cfs) throws IOException
{
    final ByteBuffer partitionKey = ByteBufferUtil.readWithLength(in);
    final CellName cellName = cfs.metadata.comparator.cellFromByteBuffer(ByteBufferUtil.readWithLength(in));
    return StageManager.getStage(Stage.READ).submit(new Callable<Pair<CounterCacheKey, ClockAndCount>>()
    {
        public Pair<CounterCacheKey, ClockAndCount> call() throws Exception
        {
            DecoratedKey key = cfs.partitioner.decorateKey(partitionKey);
            QueryFilter filter = QueryFilter.getNamesFilter(key,
                                                            cfs.metadata.cfName,
                                                            FBUtilities.singleton(cellName, cfs.metadata.comparator),
                                                            Long.MIN_VALUE);
            ColumnFamily cf = cfs.getTopLevelColumns(filter, Integer.MIN_VALUE);
            if (cf == null)
                return null;
            Cell cell = cf.getColumn(cellName);
            if (cell == null || !cell.isLive(Long.MIN_VALUE))
                return null;
            ClockAndCount clockAndCount = CounterContext.instance().getLocalClockAndCount(cell.value());
            return Pair.create(CounterCacheKey.create(cfs.metadata.cfId, partitionKey, cellName), clockAndCount);
        }
    });
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:25,代码来源:CacheService.java

示例3: getCurrentValuesFromCFS

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
private void getCurrentValuesFromCFS(List<CounterUpdateCell> counterUpdateCells,
                                     ColumnFamilyStore cfs,
                                     ClockAndCount[] currentValues)
{
    SortedSet<CellName> names = new TreeSet<>(cfs.metadata.comparator);
    for (int i = 0; i < currentValues.length; i++)
        if (currentValues[i] == null)
            names.add(counterUpdateCells.get(i).name());

    ReadCommand cmd = new SliceByNamesReadCommand(getKeyspaceName(), key(), cfs.metadata.cfName, Long.MIN_VALUE, new NamesQueryFilter(names));
    Row row = cmd.getRow(cfs.keyspace);
    ColumnFamily cf = row == null ? null : row.cf;

    for (int i = 0; i < currentValues.length; i++)
    {
        if (currentValues[i] != null)
            continue;

        Cell cell = cf == null ? null : cf.getColumn(counterUpdateCells.get(i).name());
        if (cell == null || !cell.isLive()) // absent or a tombstone.
            currentValues[i] = ClockAndCount.BLANK;
        else
            currentValues[i] = CounterContext.instance().getLocalClockAndCount(cell.value());
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:26,代码来源:CounterMutation.java

示例4: testDuplicateCells

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
@Test
public void testDuplicateCells() throws WriteTimeoutException
{
    ColumnFamilyStore cfs = Keyspace.open(KS).getColumnFamilyStore(CF1);
    cfs.truncateBlocking();

    ColumnFamily cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addCounter(cellname(1), 1L);
    cells.addCounter(cellname(1), 2L);
    cells.addCounter(cellname(1), 3L);
    cells.addCounter(cellname(1), 4L);
    new CounterMutation(new Mutation(KS, bytes(1), cells), ConsistencyLevel.ONE).apply();

    ColumnFamily current = cfs.getColumnFamily(QueryFilter.getIdentityFilter(dk(bytes(1)), CF1, System.currentTimeMillis()));
    ByteBuffer context = current.getColumn(cellname(1)).value();
    assertEquals(10L, CounterContext.instance().total(context));
    assertEquals(ClockAndCount.create(1L, 10L), CounterContext.instance().getLocalClockAndCount(context));
    assertEquals(ClockAndCount.create(1L, 10L), cfs.getCachedCounter(bytes(1), cellname(1)));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:20,代码来源:CounterMutationTest.java

示例5: testCreate

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
@Test
public void testCreate()
{
    long delta = 3L;
    CounterCell cell = new BufferCounterCell(Util.cellname("x"),
                                       CounterContext.instance().createLocal(delta),
                                       1L,
                                       Long.MIN_VALUE);

    Assert.assertEquals(delta, cell.total());
    Assert.assertEquals(1, cell.value().getShort(0));
    Assert.assertEquals(0, cell.value().getShort(2));
    Assert.assertTrue(CounterId.wrap(cell.value(), 4).isLocalId());
    Assert.assertEquals(1L, cell.value().getLong(4 + idLength));
    Assert.assertEquals(delta, cell.value().getLong(4 + idLength + clockLength));
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:17,代码来源:CounterCellTest.java

示例6: updateForRow

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
private void updateForRow(PeekingIterator<PartitionUpdate.CounterMark> markIter, Row row, ColumnFamilyStore cfs)
{
    int cmp = 0;
    // If the mark is before the row, we have no value for this mark, just consume it
    while (markIter.hasNext() && (cmp = compare(markIter.peek().clustering(), row.clustering(), cfs)) < 0)
        markIter.next();

    if (!markIter.hasNext())
        return;

    while (cmp == 0)
    {
        PartitionUpdate.CounterMark mark = markIter.next();
        Cell cell = mark.path() == null ? row.getCell(mark.column()) : row.getCell(mark.column(), mark.path());
        if (cell != null)
        {
            updateWithCurrentValue(mark, CounterContext.instance().getLocalClockAndCount(cell.value()), cfs);
            markIter.remove();
        }
        if (!markIter.hasNext())
            return;

        cmp = compare(markIter.peek().clustering(), row.clustering(), cfs);
    }
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:26,代码来源:CounterMutation.java

示例7: apply

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
@Override
public String apply(ColumnDefinition c, List<Object> params) {
    CounterContext.ContextState state = CounterContext.ContextState.wrap(value);
    StringBuilder buf = new StringBuilder();
    while (state.hasRemaining()) {
        if (buf.length() != 0) {
            buf.append(", ");
        }
        int type = 'r';
        if (state.isGlobal()) {
            type = 'g';
        }
        if (state.isLocal()) {
            type = 'l';
        }
        buf.append('(').append(type).append(',').append(getUUID(state.getCounterId().bytes())).append(',')
                .append(state.getClock()).append(',').append(state.getCount()).append(')');
        state.moveToNext();
    }
    return " = SCYLLA_COUNTER_SHARD_LIST([" + buf.toString() + "])";
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:22,代码来源:SSTableToCQL.java

示例8: testRecoverCounter

import org.apache.cassandra.db.context.CounterContext; //导入依赖的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()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:23,代码来源:RecoveryManagerTest.java

示例9: addTwoAndCheck

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
private void addTwoAndCheck(ColumnFamilyStore cfs, long addOne, long expectedOne, long addTwo, long expectedTwo)
{
    ColumnDefinition cDefOne = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val"));
    ColumnDefinition cDefTwo = cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes("val2"));

    Mutation m = new RowUpdateBuilder(cfs.metadata, 5, "key1")
        .clustering("cc")
        .add("val", addOne)
        .add("val2", addTwo)
        .build();
    new CounterMutation(m, ConsistencyLevel.ONE).apply();

    Row row = Util.getOnlyRow(Util.cmd(cfs).includeRow("cc").columns("val", "val2").build());
    assertEquals(expectedOne, CounterContext.instance().total(row.getCell(cDefOne).value()));
    assertEquals(expectedTwo, CounterContext.instance().total(row.getCell(cDefTwo).value()));
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:17,代码来源:CounterMutationTest.java

示例10: testCreate

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
@Test
public void testCreate()
{
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(COUNTER1);
    long delta = 3L;

    Cell cell = createLegacyCounterCell(cfs, ByteBufferUtil.bytes("val"), delta, 1);

    assertEquals(delta, CounterContext.instance().total(cell.value()));
    assertEquals(1, cell.value().getShort(0));
    assertEquals(0, cell.value().getShort(2));
    Assert.assertTrue(CounterId.wrap(cell.value(), 4).isLocalId());
    assertEquals(1L, cell.value().getLong(4 + idLength));
    assertEquals(delta, cell.value().getLong(4 + idLength + clockLength));

}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:17,代码来源:CounterCellTest.java

示例11: testDuplicateCells

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
@Test
public void testDuplicateCells() throws WriteTimeoutException
{
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF1);
    cfs.truncateBlocking();

    ColumnFamily cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addCounter(cellname(1), 1L);
    cells.addCounter(cellname(1), 2L);
    cells.addCounter(cellname(1), 3L);
    cells.addCounter(cellname(1), 4L);
    new CounterMutation(new Mutation(KEYSPACE1, bytes(1), cells), ConsistencyLevel.ONE).apply();

    ColumnFamily current = cfs.getColumnFamily(QueryFilter.getIdentityFilter(dk(bytes(1)), CF1, System.currentTimeMillis()));
    ByteBuffer context = current.getColumn(cellname(1)).value();
    assertEquals(10L, CounterContext.instance().total(context));
    assertEquals(ClockAndCount.create(1L, 10L), CounterContext.instance().getLocalClockAndCount(context));
    assertEquals(ClockAndCount.create(1L, 10L), cfs.getCachedCounter(bytes(1), cellname(1)));
}
 
开发者ID:daidong,项目名称:GraphTrek,代码行数:20,代码来源:CounterMutationTest.java

示例12: deserialize

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
public Future<Pair<CounterCacheKey, ClockAndCount>> deserialize(DataInputStream in, final ColumnFamilyStore cfs) throws IOException
{
    final ByteBuffer partitionKey = ByteBufferUtil.readWithLength(in);
    final CellName cellName = cfs.metadata.comparator.cellFromByteBuffer(ByteBufferUtil.readWithLength(in));
    return StageManager.getStage(Stage.READ).submit(new Callable<Pair<CounterCacheKey, ClockAndCount>>()
    {
        public Pair<CounterCacheKey, ClockAndCount> call() throws Exception
        {
            DecoratedKey key = cfs.partitioner.decorateKey(partitionKey);
            QueryFilter filter = QueryFilter.getNamesFilter(key,
                                                            cfs.metadata.cfName,
                                                            FBUtilities.singleton(cellName, cfs.metadata.comparator),
                                                            Long.MIN_VALUE);
            ColumnFamily cf = cfs.getTopLevelColumns(filter, Integer.MIN_VALUE);
            if (cf == null)
                return null;
            Cell cell = cf.getColumn(cellName);
            if (cell == null || cell.isMarkedForDelete(Long.MIN_VALUE))
                return null;
            ClockAndCount clockAndCount = CounterContext.instance().getLocalClockAndCount(cell.value());
            return Pair.create(CounterCacheKey.create(cfs.metadata.cfId, partitionKey, cellName), clockAndCount);
        }
    });
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:25,代码来源:CacheService.java

示例13: getCurrentValuesFromCFS

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
private void getCurrentValuesFromCFS(List<CounterUpdateCell> counterUpdateCells,
                                     ColumnFamilyStore cfs,
                                     ClockAndCount[] currentValues)
{
    SortedSet<CellName> names = new TreeSet<>(cfs.metadata.comparator);
    for (int i = 0; i < currentValues.length; i++)
        if (currentValues[i] == null)
            names.add(counterUpdateCells.get(i).name);

    ReadCommand cmd = new SliceByNamesReadCommand(getKeyspaceName(), key(), cfs.metadata.cfName, Long.MIN_VALUE, new NamesQueryFilter(names));
    Row row = cmd.getRow(cfs.keyspace);
    ColumnFamily cf = row == null ? null : row.cf;

    for (int i = 0; i < currentValues.length; i++)
    {
        if (currentValues[i] != null)
            continue;

        Cell cell = cf == null ? null : cf.getColumn(counterUpdateCells.get(i).name());
        if (cell == null || cell.isMarkedForDelete(Long.MIN_VALUE)) // absent or a tombstone.
            currentValues[i] = ClockAndCount.BLANK;
        else
            currentValues[i] = CounterContext.instance().getLocalClockAndCount(cell.value());
    }
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:26,代码来源:CounterMutation.java

示例14: testCreate

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
@Test
public void testCreate()
{
    long delta = 3L;
    CounterCell cell = new CounterCell(Util.cellname("x"),
                                       CounterContext.instance().createLocal(delta),
                                       1L,
                                       Long.MIN_VALUE);

    Assert.assertEquals(delta, cell.total());
    Assert.assertEquals(1, cell.value().getShort(0));
    Assert.assertEquals(0, cell.value().getShort(2));
    Assert.assertTrue(CounterId.wrap(cell.value(), 4).isLocalId());
    Assert.assertEquals(1L, cell.value().getLong(4 + idLength));
    Assert.assertEquals(delta, cell.value().getLong(4 + idLength + clockLength));
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:17,代码来源:CounterCellTest.java

示例15: counter

import org.apache.cassandra.db.context.CounterContext; //导入依赖的package包/类
public static LegacyCell counter(CFMetaData metadata, ByteBuffer superColumnName, ByteBuffer name, long value)
    throws UnknownColumnException
{
    // See UpdateParameters.addCounter() for more details on this
    ByteBuffer counterValue = CounterContext.instance().createLocal(value);
    return counter(decodeCellName(metadata, superColumnName, name), counterValue);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:8,代码来源:LegacyLayout.java


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