Package com.netflix.astyanax

Examples of com.netflix.astyanax.MutationBatch


    @Test
    public void testTimeUUID2() throws Exception {
     
      CF_TIME_UUID.describe(keyspace);
   
        MutationBatch m = keyspace.prepareMutationBatch();
        String rowKey = "Key2";
        m.withRow(CF_TIME_UUID, rowKey).delete();
        m.execute();
        m.discardMutations();

        long now = System.currentTimeMillis();
        long msecPerDay = 86400000;
        for (int i = 0; i < 100; i++) {
            m.withRow(CF_TIME_UUID, rowKey).putColumn(
                    TimeUUIDUtils.getTimeUUID(now - i * msecPerDay), i, null);
        }
        m.execute();
       
        OperationResult<ColumnList<UUID>> result = keyspace
            .prepareQuery(CF_TIME_UUID)
            .getKey(rowKey)
            .withColumnRange(
View Full Code Here


        keyspace.createColumnFamily(CF_CHECKPOINTS,         null);
       
        KeyspaceDefinition ki = keyspaceContext.getEntity().describeKeyspace();
        System.out.println("Describe Keyspace: " + ki.getName());

        MutationBatch m;
        try {
            m = keyspace.prepareMutationBatch();
            // Add 10 rows
            for (long i = 0; i < 10; i++) {
                m.withRow(CF_ALL_ROWS, i)
                    .putColumn("A", 1)
                    .putColumn("B", 1)
                    ;
            }
            // Add 10 rows
            for (long i = 10; i < 20; i++) {
                m.withRow(CF_ALL_ROWS, i)
                    .putColumn("B", 1)
                    .putColumn("C", 1)
                    ;
            }
            // Add 10 rows
            for (long i = 20; i < 30; i++) {
                m.withRow(CF_ALL_ROWS, i)
                    .putColumn("B", 1)
                    .putColumn("C", 1)
                    ;
            }
            for (long i = 0; i < 100; i++) {
                m.withRow(CF_ALL_ROWS_TOMBSTONE, i)
                 .delete()
                ;
            }
            m.execute();
           
            m = keyspace.prepareMutationBatch();
            // Delete 7
            for (long i = 0; i < 20; i += 3) {
                m.withRow(CF_ALL_ROWS, i)
                    .delete();
            }
            // Delete 10
            for (long i = 20; i < 30; i ++ ) {
                m.withRow(CF_ALL_ROWS, i)
                    .delete();
            }
           
            // CF_ALL_ROWS should have 13 rows + 17 tombstones
           
            m.execute();           
           
            // Add 10,000 rows
            m = keyspace.prepareMutationBatch();
            for (long i = 0; i < LOTS_OF_ROWS_COUNT; i++) {
                m.withRow(CF_LOTS_OF_ROWS, i).putColumn("DATA", "TEST" + i);
            }
            m.execute();
           
           
        } catch (Exception e) {
            System.out.println(e.getMessage());
            Assert.fail();
View Full Code Here

    Assert.assertEquals(expectedRowCounts, resultRowCounts);
  }

  private void populateRowsForColumnRange() throws Exception {
   
        MutationBatch m = keyspace.prepareMutationBatch();

        for (char keyName = 'A'; keyName <= 'Z'; keyName++) {
          String rowKey = Character.toString(keyName);
          ColumnListMutation<String> colMutation = m.withRow(CF_COLUMN_RANGE_TEST, rowKey);
              for (char cName = 'a'; cName <= 'z'; cName++) {
                colMutation.putColumn(Character.toString(cName), (int) (cName - 'a') + 1, null);
              }
              m.withCaching(true);
              m.execute();
              m.discardMutations();
        }
  }
View Full Code Here

  }

  private void deleteRowsForColumnRange() throws Exception {
   
        for (char keyName = 'A'; keyName <= 'Z'; keyName++) {
            MutationBatch m = keyspace.prepareMutationBatch();
          String rowKey = Character.toString(keyName);
          m.withRow(CF_COLUMN_RANGE_TEST, rowKey).delete();
          m.execute();
          m.discardMutations();
        }
  }
View Full Code Here

     */
    public List<ListenableFuture<OperationResult<Void>>> replayWal(int count) {
        List<ListenableFuture<OperationResult<Void>>> futures = Lists.newArrayList();
        WriteAheadEntry walEntry;
        while (null != (walEntry = wal.readNextEntry()) && count-- > 0) {
            MutationBatch m = keyspace.prepareMutationBatch();
            try {
                walEntry.readMutation(m);
                futures.add(executeWalEntry(walEntry, m));
            }
            catch (WalException e) {
View Full Code Here

    private LinkedBlockingQueue<MutationBatch> queue = Queues.newLinkedBlockingQueue();
    private ConcurrentMap<MutationBatch, Boolean> busy = Maps.newConcurrentMap();

    @Override
    public MutationBatch getNextMutation(long timeout, TimeUnit unit) throws InterruptedException {
        MutationBatch mutation = queue.poll(timeout, unit);
        if (mutation != null) {
            busy.put(mutation, true);
        }
        return mutation;
    }
View Full Code Here

    }

    @Override
    public void clearMessages() throws MessageQueueException {
        LOG.info("Clearing messages from '" + getName() + "'");
        MutationBatch mb = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel);

        for (MessageQueueShard partition : shardReaderPolicy.listShards()) {
            mb.withRow(queueColumnFamily, partition.getName()).delete();
        }

        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new MessageQueueException("Failed to clear messages from queue " + getName(), e);
        }
    }
View Full Code Here

    }

    @Override
    public void deleteQueue() throws MessageQueueException {
        LOG.info("Deleting queue '" + getName() + "'");
        MutationBatch mb = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel);

        for (MessageQueueShard partition : shardReaderPolicy.listShards()) {
            mb.withRow(queueColumnFamily, partition.getName()).delete();
        }

        mb.withRow(queueColumnFamily, getName());

        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new MessageQueueException("Failed to clear messages from queue " + getName(), e);
        }
    }
View Full Code Here

        }
    }

    @Override
    public boolean deleteMessageByKey(String key) throws MessageQueueException {
        MutationBatch mb = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel);

        String groupRowKey = getCompositeKey(getName(), key);
        try {
            ColumnList<MessageMetadataEntry> columns = keyspace.prepareQuery(keyIndexColumnFamily)
                    .setConsistencyLevel(consistencyLevel)
                    .getRow(groupRowKey)
                    .withColumnRange(metadataSerializer.buildRange()
                    .greaterThanEquals((byte)MessageMetadataEntryType.MessageId.ordinal())
                    .lessThanEquals((byte)MessageMetadataEntryType.MessageId.ordinal())
                    .build()
                    )
                    .execute()
                    .getResult();

            for (Column<MessageMetadataEntry> entry : columns) {
                String[] parts = splitCompositeKey(entry.getName().getName());

                String shardKey = parts[0];
                MessageQueueEntry queueEntry = new MessageQueueEntry(parts[1]);

                mb.withRow(queueColumnFamily, shardKey).deleteColumn(queueEntry);
            }

            mb.withRow(keyIndexColumnFamily, groupRowKey).delete();
        } catch (NotFoundException e) {
            return false;
        } catch (ConnectionException e) {
            throw new MessageQueueException("Error fetching row " + groupRowKey, e);
        }

        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new MessageQueueException("Error deleting queue item " + groupRowKey, e);
        }

        return true;
View Full Code Here

        }
    }

    @Override
    public void deleteMessages(Collection<String> messageIds) throws MessageQueueException {
        MutationBatch mb = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel);

        for (String messageId : messageIds) {
            String[] parts = splitCompositeKey(messageId);
            String shardKey = parts[0];
            MessageQueueEntry entry = new MessageQueueEntry(parts[1]);

            mb.withRow(queueColumnFamily, shardKey)
                    .deleteColumn(entry);
        }

        try {
            mb.execute();
        }
        catch (ConnectionException e) {
            throw new MessageQueueException("Error deleting messages " + messageIds, e);
        }
    }
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.MutationBatch

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.