Package com.netflix.astyanax

Examples of com.netflix.astyanax.MutationBatch


        this.columnFamilyInfo = columnFamilyInfo;
    }

    @Override
    public void addReadings(List<Reading> readings) {
        MutationBatch m = keyspace.prepareMutationBatch();

        for (Reading reading : readings) {
            m.withRow(columnFamilyInfo, reading.getSensorId())
                    .putColumn(reading.getTimestamp(), reading, ReadingSerializer.get(), ttl);
        }

        try {
            // note: you still have access to m.execute() if you don't need async feature.
            Future<OperationResult<Void>> future = m.executeAsync();

            // do some other stuff here...

            OperationResult<Void> result = future.get();
        }
View Full Code Here


    }

    @Override
    public ResponseData put(Object key, Object colName, Object value) throws OperationException
    {
        MutationBatch m = AstyanaxConnection.instance.keyspace().prepareMutationBatch();
        if (isCounter)
            m.withRow(cfs, key).incrementCounterColumn(colName, (Long) value);
        else
            m.withRow(cfs, key).putColumn(colName, value, valueSerializer, null);
        try
        {
            OperationResult<Void> result = m.execute();
            return new AstyanaxResponseData("", 0, result, key, colName, value);
        }
        catch (ConnectionException e)
        {
            throw new OperationException(e);
View Full Code Here

    }

    @Override
    public ResponseData batchMutate(Object key, Map<?, ?> nv) throws OperationException
    {
        MutationBatch m = AstyanaxConnection.instance.keyspace().prepareMutationBatch();
        ColumnListMutation<Object> cf = m.withRow(cfs, key);
        for (Map.Entry<?, ?> entry : nv.entrySet())
        {
            if (isCounter)
                cf.incrementCounterColumn(entry.getKey(), (Long) entry.getValue());
            else
                cf.putColumn(entry.getKey(), entry.getValue(), valueSerializer, null);
        }
        try
        {
            OperationResult<Void> result = m.execute();
            return new AstyanaxResponseData("", 0, result, key, nv);
        }
        catch (ConnectionException e)
        {
            throw new OperationException(e);
View Full Code Here

      throw new RuntimeException(e);
    }
  }
  public void sendChangesImpl(List<Action> actions, MetaLookup ormSession) throws ConnectionException {
    Keyspace keyspace = columnFamilies.getKeyspace();
    MutationBatch m = keyspace.prepareMutationBatch();
    //MutationBatch m = m1.setConsistencyLevel(ConsistencyLevel.CL_QUORUM);
   
    for(Action action : actions) {
      if(action instanceof Persist) {
        persist((Persist)action, ormSession, m);
      } else if(action instanceof Remove) {
        remove((Remove)action, ormSession, m);
      } else if(action instanceof PersistIndex) {
        persistIndex((PersistIndex)action, ormSession, m);
      } else if(action instanceof RemoveIndex) {
        removeIndex((RemoveIndex)action, ormSession, m);
      } else if(action instanceof RemoveColumn) {
        removeColumn((RemoveColumn) action, ormSession, m);
      }
    }
   
    long time = System.currentTimeMillis();
    m.execute();
   
    if(log.isTraceEnabled()) {
      long total = System.currentTimeMillis()-time;
      log.trace("astyanx save took="+total+" ms");
    }
View Full Code Here

    {
      long start = System.currentTimeMillis();
      ChunkedStorage.newWriter(indexStorage, key, new FileInputStream(compressedIndexFile))
          .withConcurrencyLevel(CONCURRENCY).call();
      byte[] json = jsonMapper.writeValueAsBytes(segment);
      MutationBatch mutation = this.keyspace.prepareMutationBatch();
      mutation.withRow(descriptorStorage, key)
        .putColumn("lastmodified", System.currentTimeMillis(), null)
        .putColumn("descriptor", json, null);       
      mutation.execute();
      log.info("Wrote index to C* in [%s] ms", System.currentTimeMillis() - start);
    } catch (Exception e)
    {
      throw new IOException(e);
    }
View Full Code Here

    @Override
    public void writeMetaEntity(Entity entity) {
        // TODO Auto-generated method stub
        Keyspace ks = kscp.acquireKeyspace("meta");
        ks.prepareMutationBatch();
        MutationBatch m;
        OperationResult<Void> result;
        m = ks.prepareMutationBatch();
        m.withRow(dbcf, entity.getRowKey()).putColumn(entity.getName(), entity.getPayLoad(), null);
        try {
            result = m.execute();
            if (entity instanceof PaasTableEntity) {
                String schemaName = ((PaasTableEntity)entity).getSchemaName();
                Keyspace schemaks = kscp.acquireKeyspace(schemaName);
                ColumnFamily<String, String> cf = ColumnFamily.newColumnFamily(entity.getName(), StringSerializer.get(), StringSerializer.get());
                schemaks.createColumnFamily(cf, null);
View Full Code Here

    }

    @Override
    public Collection<String> findUnion(Map<String, String> tags) throws IndexerException {
        Set<String> ids = Sets.newHashSet();
        MutationBatch mb = keyspace.prepareMutationBatch();
        try {
            for (Row<String, IndexEntry> row : keyspace.prepareQuery(indexCf).getKeySlice(fieldsToSet(tags)).execute().getResult()) {
                ColumnListMutation<IndexEntry> mrow = null;
                IndexEntry previousEntry = null;
                for (Column<IndexEntry> column : row.getColumns()) {
                    IndexEntry entry = column.getName();
                    if (previousEntry != null && entry.id == previousEntry.id) {
                        if (mrow == null)
                            mrow = mb.withRow(indexCf, row.getKey());
                        mrow.deleteColumn(previousEntry);
                    }
                    ids.add(entry.id);
                }
            }
        } catch (ConnectionException e) {
            throw new IndexerException("Failed to get tags : " + tags, e);
        } finally {
            try {
                mb.execute();
            }
            catch (Exception e) {
                // OK to ignore
            }
        }
View Full Code Here

    @Override
    public Collection<String> findIntersection(Map<String, String> tags) throws IndexerException  {
        Set<String> ids = Sets.newHashSet();
       
        MutationBatch mb = keyspace.prepareMutationBatch();
        try {
            boolean first = true;
            Set<Entry<String, String>> elements = tags.entrySet();
           
            for (Row<String, IndexEntry> row : keyspace.prepareQuery(indexCf).getKeySlice(fieldsToSet(tags)).execute().getResult()) {
                Set<String> rowIds = Sets.newHashSet();
                ColumnListMutation<IndexEntry> mrow = null;
                IndexEntry previousEntry = null;
                for (Column<IndexEntry> column : row.getColumns()) {
                    IndexEntry entry = column.getName();
                    if (previousEntry != null && entry.id == previousEntry.id) {
                        if (mrow == null)
                            mrow = mb.withRow(indexCf, row.getKey());
                        mrow.deleteColumn(previousEntry);
                    }
                   
                    rowIds.add(entry.id);
                }
               
                if (first) {
                    first = false;
                    ids = rowIds;
                }
                else {
                    ids = Sets.intersection(ids, rowIds);
                    if (ids.isEmpty())
                        return ids;
                }
            }
        } catch (ConnectionException e) {
            throw new IndexerException("Failed to get tags : " + tags, e);
        } finally {
            try {
                mb.execute();
            }
            catch (ConnectionException e) {
                // OK to ignore
            }
        }
View Full Code Here

    @Override
    public Collection<String> find(String field, String value) throws IndexerException  {
        Set<String> ids = Sets.newHashSet();
        String indexRowKey = field + "=" + value;
       
        MutationBatch mb = keyspace.prepareMutationBatch();
        try {
            boolean first = true;
            ColumnList<IndexEntry> row = keyspace.prepareQuery(indexCf).getRow(indexRowKey).execute().getResult();
            IndexEntry previousEntry = null;
            for (Column<IndexEntry> column : row) {
                IndexEntry entry = column.getName();
                ColumnListMutation<IndexEntry> mrow = null;
                if (previousEntry != null && entry.id == previousEntry.id) {
                    if (mrow == null)
                        mrow = mb.withRow(indexCf, indexRowKey);
                    mrow.deleteColumn(previousEntry);
                }
                else {
                    ids.add(entry.id);
                }
            }
        } catch (ConnectionException e) {
            throw new IndexerException("Failed to get tag : " + indexRowKey, e);
        } finally {
            try {
                mb.execute();
            }
            catch (ConnectionException e) {
                // OK to ignore
            }
        }
View Full Code Here

        return ids;
    }

    @Override
    public void tagId(String id, Map<String, String> tags) throws IndexerException  {
        MutationBatch mb = keyspace.prepareMutationBatch();
       
        ColumnListMutation<String> idRow = mb.withRow(dataCf, id);
        UUID uuid = TimeUUIDUtils.getUniqueTimeUUIDinMicros();
        for (Map.Entry<String, String> tag : tags.entrySet()) {
            String rowkey = tag.getKey() + "=" + tag.getValue();
            System.out.println("Rowkey: " + rowkey);
            mb.withRow(indexCf, tag.getKey() + "=" + tag.getValue())
              .putEmptyColumn(new IndexEntry(id, uuid));
//            idRow.putColumn(tag.getKey(), tag.getValue());
        }
       
        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new IndexerException("Failed to store tags : " + tags + " for id " + id, 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.