Package org.apache.cassandra.db.context

Examples of org.apache.cassandra.db.context.CounterContext$ContextState


    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Table table = Table.open("Keyspace1");
        final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();
       
        final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();

        List<String> keys = createAndTransfer(table, cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
                ColumnFamily cf = ColumnFamily.create(cfs.metadata);
                ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(NodeId.fromInt(2), 9L, 3L, true);
                state.writeElement(NodeId.fromInt(4), 4L, 2L);
                state.writeElement(NodeId.fromInt(6), 3L, 3L);
                state.writeElement(NodeId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                               state.context,
                                               timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                                      cc.clearAllDelta(state.context),
                                                      timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here


    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Table table = Table.open("Keyspace1");
        final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();

        final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();

        List<String> keys = createAndTransfer(table, cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
                ColumnFamily cf = ColumnFamily.create(cfs.metadata);
                ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(CounterId.fromInt(2), 9L, 3L, true);
                state.writeElement(CounterId.fromInt(4), 4L, 2L);
                state.writeElement(CounterId.fromInt(6), 3L, 3L);
                state.writeElement(CounterId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                               state.context,
                                               timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                                      cc.clearAllDelta(state.context),
                                                      timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here

    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Table table = Table.open("Keyspace1");
        final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();

        final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();

        List<String> keys = createAndTransfer(table, cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
                ColumnFamily cf = ColumnFamily.create(cfs.metadata);
                ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(CounterId.fromInt(2), 9L, 3L, true);
                state.writeElement(CounterId.fromInt(4), 4L, 2L);
                state.writeElement(CounterId.fromInt(6), 3L, 3L);
                state.writeElement(CounterId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                               state.context,
                                               timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                                      cc.clearAllDelta(state.context),
                                                      timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here

    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Keyspace keyspace = Keyspace.open("Keyspace1");
        final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();

        final Map<String, ColumnFamily> cleanedEntries = new HashMap<>();

        List<String> keys = createAndTransfer(cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<>();
                ColumnFamily cf = TreeMapBackedSortedColumns.factory.create(cfs.metadata);
                ColumnFamily cfCleaned = TreeMapBackedSortedColumns.factory.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(CounterId.fromInt(2), 9L, 3L, true);
                state.writeElement(CounterId.fromInt(4), 4L, 2L);
                state.writeElement(CounterId.fromInt(6), 3L, 3L);
                state.writeElement(CounterId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                        state.context,
                        timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                        cc.clearAllDelta(state.context),
                        timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here

    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Keyspace keyspace = Keyspace.open("Keyspace1");
        final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();

        final Map<String, ColumnFamily> cleanedEntries = new HashMap<>();

        List<String> keys = createAndTransfer(cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<>();
                ColumnFamily cf = ArrayBackedSortedColumns.factory.create(cfs.metadata);
                ColumnFamily cfCleaned = ArrayBackedSortedColumns.factory.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(0, 1, 3, HeapAllocator.instance);
                state.writeLocal(CounterId.fromInt(2), 9L, 3L);
                state.writeRemote(CounterId.fromInt(4), 4L, 2L);
                state.writeRemote(CounterId.fromInt(6), 3L, 3L);
                state.writeRemote(CounterId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterCell(cellname(col), state.context, timestamp));
                cfCleaned.addColumn(new CounterCell(cellname(col), cc.clearAllLocal(state.context), timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
                    .ks(keyspace.getName())
View Full Code Here

    }

    @Test
    public void testRemoveOldShardFixCorrupted() throws IOException
    {
        CounterContext ctx = CounterContext.instance();

        // Check that corrupted context created prior to #2968 are fixed by removeOldShards
        NodeId id1 = NodeId.getLocalId();
        NodeId.renewLocalId();
        NodeId id2 = NodeId.getLocalId();

        ContextState state = ContextState.allocate(3, 2);
        state.writeElement(NodeId.fromInt(1), 1, 4, false);
        state.writeElement(id1, 3, 2, true);
        state.writeElement(id2, -System.currentTimeMillis(), 5, true); // corrupted!

        assert ctx.total(state.context) == 11;

        try
        {
            ctx.removeOldShards(state.context, Integer.MAX_VALUE);
            fail("RemoveOldShards should throw an exception if the current id is non-sensical");
        }
        catch (RuntimeException e) {}

        NodeId.renewLocalId();
        ByteBuffer cleaned = ctx.removeOldShards(state.context, Integer.MAX_VALUE);
        assert ctx.total(cleaned) == 11;

        // Check it is not corrupted anymore
        ContextState state2 = new ContextState(cleaned);
        while (state2.hasRemaining())
        {
            assert state2.getClock() >= 0 || state2.getCount() == 0;
            state2.moveToNext();
        }

        // Check that if we merge old and clean on another node, we keep the right count
        ByteBuffer onRemote = ctx.merge(ctx.clearAllDelta(state.context), ctx.clearAllDelta(cleaned), HeapAllocator.instance);
        assert ctx.total(onRemote) == 11;
    }
View Full Code Here

    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Table table = Table.open("Keyspace1");
        final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();
       
        final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();

        List<String> keys = createAndTransfer(table, cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
                ColumnFamily cf = ColumnFamily.create(cfs.metadata);
                ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(NodeId.fromInt(2), 9L, 3L, true);
                state.writeElement(NodeId.fromInt(4), 4L, 2L);
                state.writeElement(NodeId.fromInt(6), 3L, 3L);
                state.writeElement(NodeId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                               state.context,
                                               timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                                      cc.clearAllDelta(state.context),
                                                      timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here

    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Table table = Table.open("Keyspace1");
        final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();

        final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();

        List<String> keys = createAndTransfer(table, cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
                ColumnFamily cf = ColumnFamily.create(cfs.metadata);
                ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(CounterId.fromInt(2), 9L, 3L, true);
                state.writeElement(CounterId.fromInt(4), 4L, 2L);
                state.writeElement(CounterId.fromInt(6), 3L, 3L);
                state.writeElement(CounterId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                               state.context,
                                               timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                                      cc.clearAllDelta(state.context),
                                                      timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here

    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Table table = Table.open("Keyspace1");
        final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();
       
        final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();

        List<String> keys = createAndTransfer(table, cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
                ColumnFamily cf = ColumnFamily.create(cfs.metadata);
                ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(NodeId.fromInt(2), 9L, 3L, true);
                state.writeElement(NodeId.fromInt(4), 4L, 2L);
                state.writeElement(NodeId.fromInt(6), 3L, 3L);
                state.writeElement(NodeId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                               state.context,
                                               timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                                      cc.clearAllDelta(state.context),
                                                      timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here

    @Test
    public void testTransferTableCounter() throws Exception
    {
        final Table table = Table.open("Keyspace1");
        final ColumnFamilyStore cfs = table.getColumnFamilyStore("Counter1");
        final CounterContext cc = new CounterContext();

        final Map<String, ColumnFamily> cleanedEntries = new HashMap<String, ColumnFamily>();

        List<String> keys = createAndTransfer(table, cfs, new Mutator()
        {
            /** Creates a new SSTable per key: all will be merged before streaming. */
            public void mutate(String key, String col, long timestamp) throws Exception
            {
                Map<String, ColumnFamily> entries = new HashMap<String, ColumnFamily>();
                ColumnFamily cf = ColumnFamily.create(cfs.metadata);
                ColumnFamily cfCleaned = ColumnFamily.create(cfs.metadata);
                CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 1);
                state.writeElement(CounterId.fromInt(2), 9L, 3L, true);
                state.writeElement(CounterId.fromInt(4), 4L, 2L);
                state.writeElement(CounterId.fromInt(6), 3L, 3L);
                state.writeElement(CounterId.fromInt(8), 2L, 4L);
                cf.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                               state.context,
                                               timestamp));
                cfCleaned.addColumn(new CounterColumn(ByteBufferUtil.bytes(col),
                                                      cc.clearAllDelta(state.context),
                                                      timestamp));

                entries.put(key, cf);
                cleanedEntries.put(key, cfCleaned);
                cfs.addSSTable(SSTableUtils.prepare()
View Full Code Here

TOP

Related Classes of org.apache.cassandra.db.context.CounterContext$ContextState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.