Package org.apache.cassandra.db

Examples of org.apache.cassandra.db.RowMutation


    public static Message createMessage(String Keyspace, String Key, String CFName, List<ColumnFamily> ColumnFamiles)
    {
        ColumnFamily baseColumnFamily;
        DataOutputBuffer bufOut = new org.apache.cassandra.io.DataOutputBuffer();
        RowMutation rm;
        Message message;
        Column column;

        /* Get the first column family from list, this is just to get past validation */
        baseColumnFamily = new ColumnFamily(CFName, "Standard",DatabaseDescriptor.getComparator(Keyspace, CFName), DatabaseDescriptor.getSubComparator(Keyspace, CFName));
       
        for(ColumnFamily cf : ColumnFamiles) {
            bufOut.reset();
            try
            {
                ColumnFamily.serializer().serializeWithIndexes(cf, bufOut);
                byte[] data = new byte[bufOut.getLength()];
                System.arraycopy(bufOut.getData(), 0, data, 0, bufOut.getLength());

                column = new Column(cf.name().getBytes("UTF-8"), data, 0, false);
                baseColumnFamily.addColumn(column);
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
        }
        rm = new RowMutation(Keyspace, Key);
        rm.add(baseColumnFamily);

        try
        {
            /* Make message */
            message = rm.makeRowMutationMessage(StorageService.binaryVerbHandler_);
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
View Full Code Here


                ColumnFamily cf = ColumnFamily.create(cfMeta);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("source")), FBUtilities.getBroadcastAddress());
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("thread")), threadName);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("source_elapsed")), elapsed);
                Tracing.addColumn(cf, Tracing.buildName(cfMeta, eventId, ByteBufferUtil.bytes("activity")), message);
                RowMutation mutation = new RowMutation(Tracing.TRACE_KS, sessionIdBytes);
                mutation.add(cf);
                StorageProxy.mutate(Arrays.asList(mutation), ConsistencyLevel.ANY);
            }
        });
    }
View Full Code Here

    {
        AbstractType<?> comparator = getComparator(keyspace);

        // if true we need to wrap RowMutation into CounterMutation
        boolean hasCounterColumn = false;
        RowMutation rm = new RowMutation(keyspace, key);

        for (Map.Entry<Term, Operation> column : getColumns().entrySet())
        {
            ByteBuffer colName = column.getKey().getByteBuffer(comparator);
            Operation op = column.getValue();

            if (op.isUnary())
            {
                if (hasCounterColumn)
                    throw new InvalidRequestException("Mix of commutative and non-commutative operations is not allowed.");

                ByteBuffer colValue = op.a.getByteBuffer(getValueValidator(keyspace, colName));

                validateColumn(metadata, colName, colValue);
                rm.add(new QueryPath(columnFamily, null, colName),
                       colValue,
                       (timestamp == null) ? getTimestamp() : timestamp,
                       getTimeToLive());
            }
            else
            {
                hasCounterColumn = true;

                if (!column.getKey().getText().equals(op.a.getText()))
                    throw new InvalidRequestException("Only expressions like X = X + <long> are supported.");

                long value;

                try
                {
                    value = Long.parseLong(op.b.getText());

                    if (op.type == OperationType.MINUS)
                    {
                        value *= -1;
                    }
                }
                catch (NumberFormatException e)
                {
                    throw new InvalidRequestException(String.format("'%s' is an invalid value, should be a long.",
                                                      op.b.getText()));
                }

                rm.addCounter(new QueryPath(columnFamily, null, colName), value);
            }
        }

        return (hasCounterColumn) ? new CounterMutation(rm, getConsistencyLevel()) : rm;
    }
View Full Code Here

                        continue;
                    }

                    /* deserialize the commit log entry */
                    ByteArrayInputStream bufIn = new ByteArrayInputStream(bytes, 0, serializedSize);
                    RowMutation rm = null;
                    try
                    {
                        rm = RowMutation.serializer().deserialize(new DataInputStream(bufIn));
                    }
                    catch (UnserializableColumnFamilyException ex)
                    {
                        AtomicInteger i = invalidMutations.get(ex.cfId);
                        if (i == null)
                        {
                            i = new AtomicInteger(1);
                            invalidMutations.put(ex.cfId, i);
                        }
                        else
                            i.incrementAndGet();
                        continue;
                    }
                   
                    if (logger.isDebugEnabled())
                        logger.debug(String.format("replaying mutation for %s.%s: %s",
                                                    rm.getTable(),
                                                    ByteBufferUtil.bytesToHex(rm.key()),
                                                    "{" + StringUtils.join(rm.getColumnFamilies(), ", ") + "}"));
                    final Table table = Table.open(rm.getTable());
                    tablesRecovered.add(table);
                    final Collection<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>(rm.getColumnFamilies());
                    final long entryLocation = reader.getFilePointer();
                    final CommitLogHeader finalHeader = clHeader;
                    final RowMutation frm = rm;
                    Runnable runnable = new WrappedRunnable()
                    {
                        public void runMayThrow() throws IOException
                        {
                            RowMutation newRm = new RowMutation(frm.getTable(), frm.key());

                            // Rebuild the row mutation, omitting column families that a) have already been flushed,
                            // b) are part of a cf that was dropped. Keep in mind that the cf.name() is suspect. do every
                            // thing based on the cfid instead.
                            for (ColumnFamily columnFamily : columnFamilies)
                            {
                                if (CFMetaData.getCF(columnFamily.id()) == null)
                                    // null means the cf has been dropped
                                    continue;

                                if (finalHeader == null || (finalHeader.isDirty(columnFamily.id()) && entryLocation > finalHeader.getPosition(columnFamily.id())))
                                    newRm.add(columnFamily);
                            }
                            if (!newRm.isEmpty())
                            {
                                Table.open(newRm.getTable()).apply(newRm, null, false);
                            }
                        }
                    };
                    futures.add(StageManager.getStage(Stage.MUTATION).submit(runnable));
                    if (futures.size() > MAX_OUTSTANDING_REPLAY_COUNT)
View Full Code Here

    private static SSTable makeSSTable()
    {
        Table t = Table.open("Keyspace1");
        for (int i = 0; i < 100; i++)
        {
            RowMutation rm = new RowMutation(t.name, ByteBufferUtil.bytes(Long.toString(System.nanoTime())));
            rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("cola")), ByteBufferUtil.bytes("value"), 0);
            try
            {
                rm.apply();
            }
            catch (IOException ex)
            {
                throw new RuntimeException(ex);
            }
View Full Code Here

    protected void insertData(String keyspace, String columnFamily, int offset, int numberOfRows) throws IOException
    {
        for (int i = offset; i < offset + numberOfRows; i++)
        {
            ByteBuffer key = ByteBufferUtil.bytes("key" + i);
            RowMutation rowMutation = new RowMutation(keyspace, key);
            QueryPath path = new QueryPath(columnFamily, null, ByteBufferUtil.bytes("col" + i));

            rowMutation.add(path, ByteBufferUtil.bytes("val" + i), System.currentTimeMillis());
            rowMutation.applyUnsafe();
        }
    }
View Full Code Here

    public ResponseData put(Object key, Object colName, Object value) throws OperationException
    {
        ByteBuffer rKey = kser.toByteBuffer(key);
        ByteBuffer name = colser.toByteBuffer(colName);
        ByteBuffer val = valser.toByteBuffer(value);
        RowMutation change = new RowMutation(ks, rKey);
        ColumnPath cp = new ColumnPath(cf).setColumn(name);
        change.add(new QueryPath(cp), val, System.currentTimeMillis());
        try
        {
            StorageProxy.mutate(Arrays.asList(change), wConsistecy);
        }
        catch (Exception e)
View Full Code Here

    @Override
    public ResponseData batchMutate(Object key, Map<?, ?> nv) throws OperationException
    {
        ByteBuffer rKey = kser.toByteBuffer(key);
        RowMutation change = new RowMutation(ks, rKey);
        for (Map.Entry entry : nv.entrySet())
        {
            ByteBuffer name = colser.toByteBuffer(entry.getKey());
            ByteBuffer val = valser.toByteBuffer(entry.getValue());
            ColumnPath cp = new ColumnPath(cf).setColumn(name);
            change.add(new QueryPath(cp), val, System.currentTimeMillis());
        }
        try
        {
            StorageProxy.mutate(Arrays.asList(change), wConsistecy);
        }
View Full Code Here

        int[] used = new int[16*1024];
        byte[] bytes = new byte[4*1024];
        for (int i = 0; i < 1; ++i)
        {
            String key = Integer.toString(i);
            RowMutation rm = new RowMutation("Mailbox", key);
            random.nextBytes(bytes);
            while ( totalUsed != 16*1024 )
            {
                int j = random.nextInt(16*1024);               
                if ( used[j] == 0 )
                {
                    used[j] = 1;
                    ++totalUsed;
                }            
                // rm.add("Test:Column-" + j, bytes, System.currentTimeMillis());
               
                for ( int k = 0; k < 1; ++k )
                {                            
                    rm.add("MailboxMailData0:SuperColumn-" + j + ":Column-" + k, bytes, k);                   
                }
            }
            rm.apply();           
        }
        System.out.println("Write done");
    }
View Full Code Here

                new FileInputStream(filepath)), 16 * 1024 * 1024);
        String line = null;
        String delimiter_ = new String(",");
        String firstuser = null;
        String nextuser = null;
        RowMutation rmInbox = null;
        RowMutation rmOutbox = null;
        ColumnFamily cfInbox = null;
        ColumnFamily cfOutbox = null;
        while ((line = bufReader.readLine()) != null)
        {
            StringTokenizer st = new StringTokenizer(line, delimiter_);
            int i = 0;
            String threadId = null;
            int lastUpdated = 0;
            int isDeleted = 0;
            int folder = 0;
            String user = null;
            while (st.hasMoreElements())
            {
                switch (i)
                {
                case 0:
                    user = (String) st.nextElement();// sb.append((String)st.nextElement());
                    break;

                case 1:
                    folder = Integer.parseInt((String) st.nextElement());// sb.append((String)st.nextElement());
                    break;

                case 2:
                    threadId = (String) st.nextElement();
                    break;

                case 3:
                    lastUpdated = Integer.parseInt((String) st.nextElement());
                    break;

                case 4:
                    isDeleted = Integer.parseInt((String) st.nextElement());// (String)st.nextElement();
                    break;

                default:
                    break;
                }
                ++i;
            }

         nextuser = user;
          if (firstuser == null || firstuser.compareTo(nextuser) != 0) {
                  firstuser = nextuser;
                  if (rmInbox != null) {
                          applyLoad(rmInbox);
                  }
                  if (rmOutbox != null) {
                          applyLoad(rmOutbox);
                  }
                  rmInbox = new RowMutation(tablename_, firstuser + ":0");
                  rmOutbox = new RowMutation(tablename_, firstuser + ":1");
          }
          // List <MboxStruct> list = userthreadmap.get(rs.getString(1));
          if (folder == 0) {
              rmInbox.add(columnFamily_+(columnFamilyHack_%divideby_)+":"+threadId, String.valueOf(isDeleted).getBytes(), lastUpdated);
          } else {
              rmOutbox.add(columnFamily_+(columnFamilyHack_%divideby_)+":"+threadId,String.valueOf(isDeleted).getBytes(),lastUpdated);
          }
  }
  if (firstuser != null) {
          if (rmInbox != null) {
                  applyLoad(rmInbox);
View Full Code Here

TOP

Related Classes of org.apache.cassandra.db.RowMutation

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.