Example usage for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY

List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY.

Prototype

null EMPTY_BYTE_ARRAY

To view the source code for org.apache.commons.lang ArrayUtils EMPTY_BYTE_ARRAY.

Click Source Link

Document

An empty immutable byte array.

Usage

From source file:org.apache.cassandra.cql.common.ColumnRangeQueryRSD.java

public List<Map<String, String>> getRows() throws UnsupportedEncodingException {
    QueryPath path;//  ww w. ja v a  2 s.com
    String superColumnKey = null;

    if (superColumnKey_ != null) {
        superColumnKey = (String) (superColumnKey_.get());
        path = new QueryPath(cfMetaData_.cfName, superColumnKey.getBytes("UTF-8"));
    } else {
        path = new QueryPath(cfMetaData_.cfName);
    }

    Row row = null;
    try {
        String key = (String) (rowKey_.get());
        ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key, path,
                ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, limit_);
        row = StorageProxy.readProtocol(readCommand, ConsistencyLevel.ONE);
    } catch (Exception e) {
        logger_.error(LogUtil.throwableToString(e));
        throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
    }

    List<Map<String, String>> rows = new LinkedList<Map<String, String>>();
    if (row != null) {
        ColumnFamily cfamily = row.getColumnFamily(cfMetaData_.cfName);
        if (cfamily != null) {
            Collection<IColumn> columns = null;
            if (superColumnKey_ != null) {
                // this is the super column case
                IColumn column = cfamily.getColumn(superColumnKey.getBytes("UTF-8"));
                if (column != null)
                    columns = column.getSubColumns();
            } else {
                columns = cfamily.getSortedColumns();
            }

            if (columns != null && columns.size() > 0) {
                for (IColumn column : columns) {
                    Map<String, String> result = new HashMap<String, String>();

                    result.put(cfMetaData_.n_columnKey, new String(column.name(), "UTF-8"));
                    result.put(cfMetaData_.n_columnValue, new String(column.value()));
                    result.put(cfMetaData_.n_columnTimestamp, Long.toString(column.timestamp()));

                    rows.add(result);
                }
            }
        }
    }
    return rows;
}

From source file:org.apache.cassandra.cql.common.SuperColumnRangeQueryRSD.java

public List<Map<String, String>> getRows() throws UnsupportedEncodingException {
    Row row = null;/*from  w w w. j  a  v a  2  s.  c  om*/
    try {
        String key = (String) (rowKey_.get());
        ReadCommand readCommand = new SliceFromReadCommand(cfMetaData_.tableName, key,
                new QueryPath(cfMetaData_.cfName), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY,
                true, limit_);
        row = StorageProxy.readProtocol(readCommand, ConsistencyLevel.ONE);
    } catch (Exception e) {
        logger_.error(LogUtil.throwableToString(e));
        throw new RuntimeException(RuntimeErrorMsg.GENERIC_ERROR.getMsg());
    }

    List<Map<String, String>> rows = new LinkedList<Map<String, String>>();
    if (row != null) {
        ColumnFamily cfamily = row.getColumnFamily(cfMetaData_.cfName);
        if (cfamily != null) {
            Collection<IColumn> columns = cfamily.getSortedColumns();
            if (columns != null && columns.size() > 0) {
                for (IColumn column : columns) {
                    Collection<IColumn> subColumns = column.getSubColumns();
                    for (IColumn subColumn : subColumns) {
                        Map<String, String> result = new HashMap<String, String>();
                        result.put(cfMetaData_.n_superColumnKey, new String(column.name(), "UTF-8"));
                        result.put(cfMetaData_.n_columnKey, new String(subColumn.name(), "UTF-8"));
                        result.put(cfMetaData_.n_columnValue, new String(subColumn.value()));
                        result.put(cfMetaData_.n_columnTimestamp, Long.toString(subColumn.timestamp()));
                        rows.add(result);
                    }
                }
            }
        }
    }
    return rows;
}

From source file:org.apache.cassandra.db.ColumnFamilyStoreTest.java

License:asdf

@Test
public void testDeleteSuperRowSticksAfterFlush() throws Throwable {
    String tableName = "Keyspace1";
    String cfName = "Super1";
    ByteBuffer scfName = ByteBufferUtil.bytes("SuperDuper");
    Table table = Table.open(tableName);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    DecoratedKey key = Util.dk("flush-resurrection");

    // create an isolated sstable.
    putColsSuper(cfs, key, scfName, new Column(getBytes(1), ByteBufferUtil.bytes("val1"), 1),
            new Column(getBytes(2), ByteBufferUtil.bytes("val2"), 1),
            new Column(getBytes(3), ByteBufferUtil.bytes("val3"), 1));
    cfs.forceBlockingFlush();//from  www .  j  a v a2s.c  om

    // insert, don't flush.
    putColsSuper(cfs, key, scfName, new Column(getBytes(4), ByteBufferUtil.bytes("val4"), 1),
            new Column(getBytes(5), ByteBufferUtil.bytes("val5"), 1),
            new Column(getBytes(6), ByteBufferUtil.bytes("val6"), 1));

    // verify insert.
    final SlicePredicate sp = new SlicePredicate();
    sp.setSlice_range(new SliceRange());
    sp.getSlice_range().setCount(100);
    sp.getSlice_range().setStart(ArrayUtils.EMPTY_BYTE_ARRAY);
    sp.getSlice_range().setFinish(ArrayUtils.EMPTY_BYTE_ARRAY);

    assertRowAndColCount(1, 6, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100,
            QueryFilter.getFilter(sp, cfs.getComparator())));

    // deeleet.
    RowMutation rm = new RowMutation(table.name, key.key);
    rm.delete(new QueryPath(cfName, scfName), 2);
    rm.apply();

    // verify delete.
    assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100,
            QueryFilter.getFilter(sp, cfs.getComparator())));

    // flush
    cfs.forceBlockingFlush();

    // re-verify delete.
    assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100,
            QueryFilter.getFilter(sp, cfs.getComparator())));

    // late insert.
    putColsSuper(cfs, key, scfName, new Column(getBytes(4), ByteBufferUtil.bytes("val4"), 1L),
            new Column(getBytes(7), ByteBufferUtil.bytes("val7"), 1L));

    // re-verify delete.
    assertRowAndColCount(1, 0, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100,
            QueryFilter.getFilter(sp, cfs.getComparator())));

    // make sure new writes are recognized.
    putColsSuper(cfs, key, scfName, new Column(getBytes(3), ByteBufferUtil.bytes("val3"), 3),
            new Column(getBytes(8), ByteBufferUtil.bytes("val8"), 3),
            new Column(getBytes(9), ByteBufferUtil.bytes("val9"), 3));
    assertRowAndColCount(1, 3, scfName, false, cfs.getRangeSlice(scfName, Util.range("f", "g"), 100,
            QueryFilter.getFilter(sp, cfs.getComparator())));
}

From source file:org.apache.cassandra.db.ColumnFamilyStoreTest.java

License:asdf

@Test
public void testDeleteStandardRowSticksAfterFlush() throws Throwable {
    // test to make sure flushing after a delete doesn't resurrect delted cols.
    String tableName = "Keyspace1";
    String cfName = "Standard1";
    Table table = Table.open(tableName);
    ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
    DecoratedKey key = Util.dk("f-flush-resurrection");

    SlicePredicate sp = new SlicePredicate();
    sp.setSlice_range(new SliceRange());
    sp.getSlice_range().setCount(100);/*from   www .  j  a  va 2 s. c om*/
    sp.getSlice_range().setStart(ArrayUtils.EMPTY_BYTE_ARRAY);
    sp.getSlice_range().setFinish(ArrayUtils.EMPTY_BYTE_ARRAY);

    // insert
    putColsStandard(cfs, key, column("col1", "val1", 1), column("col2", "val2", 1));
    assertRowAndColCount(1, 2, null, false,
            cfs.getRangeSlice(null, Util.range("f", "g"), 100, QueryFilter.getFilter(sp, cfs.getComparator())));

    // flush.
    cfs.forceBlockingFlush();

    // insert, don't flush
    putColsStandard(cfs, key, column("col3", "val3", 1), column("col4", "val4", 1));
    assertRowAndColCount(1, 4, null, false,
            cfs.getRangeSlice(null, Util.range("f", "g"), 100, QueryFilter.getFilter(sp, cfs.getComparator())));

    // delete (from sstable and memtable)
    RowMutation rm = new RowMutation(table.name, key.key);
    rm.delete(new QueryPath(cfs.columnFamily, null, null), 2);
    rm.apply();

    // verify delete
    assertRowAndColCount(1, 0, null, true,
            cfs.getRangeSlice(null, Util.range("f", "g"), 100, QueryFilter.getFilter(sp, cfs.getComparator())));

    // flush
    cfs.forceBlockingFlush();

    // re-verify delete. // first breakage is right here because of CASSANDRA-1837.
    assertRowAndColCount(1, 0, null, true,
            cfs.getRangeSlice(null, Util.range("f", "g"), 100, QueryFilter.getFilter(sp, cfs.getComparator())));

    // simulate a 'late' insertion that gets put in after the deletion. should get inserted, but fail on read.
    putColsStandard(cfs, key, column("col5", "val5", 1), column("col2", "val2", 1));

    // should still be nothing there because we deleted this row. 2nd breakage, but was undetected because of 1837.
    assertRowAndColCount(1, 0, null, true,
            cfs.getRangeSlice(null, Util.range("f", "g"), 100, QueryFilter.getFilter(sp, cfs.getComparator())));

    // make sure that new writes are recognized.
    putColsStandard(cfs, key, column("col6", "val6", 3), column("col7", "val7", 3));
    assertRowAndColCount(1, 2, null, true,
            cfs.getRangeSlice(null, Util.range("f", "g"), 100, QueryFilter.getFilter(sp, cfs.getComparator())));

    // and it remains so after flush. (this wasn't failing before, but it's good to check.)
    cfs.forceBlockingFlush();
    assertRowAndColCount(1, 2, null, true,
            cfs.getRangeSlice(null, Util.range("f", "g"), 100, QueryFilter.getFilter(sp, cfs.getComparator())));
}

From source file:org.apache.cassandra.db.columniterator.IdentityQueryFilter.java

/**
 * Only for use in testing; will read entire CF into memory.
 *//*from   ww w . j  av  a  2  s .c o m*/
public IdentityQueryFilter() {
    super(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, false, Integer.MAX_VALUE);
}

From source file:org.apache.cassandra.db.marshal.TypeCompareTest.java

License:asdf

@Test
public void testAscii() {
    AsciiType comparator = new AsciiType();
    assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, "asdf".getBytes()) < 0;
    assert comparator.compare("asdf".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY) > 0;
    assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY) == 0;
    assert comparator.compare("z".getBytes(), "a".getBytes()) > 0;
    assert comparator.compare("a".getBytes(), "z".getBytes()) < 0;
    assert comparator.compare("asdf".getBytes(), "asdf".getBytes()) == 0;
    assert comparator.compare("asdz".getBytes(), "asdf".getBytes()) > 0;
}

From source file:org.apache.cassandra.db.marshal.TypeCompareTest.java

License:asdf

@Test
public void testBytes() {
    BytesType comparator = new BytesType();
    assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, "asdf".getBytes()) < 0;
    assert comparator.compare("asdf".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY) > 0;
    assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY) == 0;
    assert comparator.compare("z".getBytes(), "a".getBytes()) > 0;
    assert comparator.compare("a".getBytes(), "z".getBytes()) < 0;
    assert comparator.compare("asdf".getBytes(), "asdf".getBytes()) == 0;
    assert comparator.compare("asdz".getBytes(), "asdf".getBytes()) > 0;
}

From source file:org.apache.cassandra.db.marshal.TypeCompareTest.java

License:asdf

@Test
public void testUTF8() throws UnsupportedEncodingException {
    UTF8Type comparator = new UTF8Type();
    assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, "asdf".getBytes()) < 0;
    assert comparator.compare("asdf".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY) > 0;
    assert comparator.compare(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY) == 0;
    assert comparator.compare("z".getBytes("UTF-8"), "a".getBytes("UTF-8")) > 0;
    assert comparator.compare("z".getBytes("UTF-8"), "z".getBytes("UTF-8")) == 0;
    assert comparator.compare("a".getBytes("UTF-8"), "z".getBytes("UTF-8")) < 0;
}

From source file:org.apache.cassandra.db.ReadMessageTest.java

@Test
public void testMakeReadMessage() throws IOException {
    ArrayList<byte[]> colList = new ArrayList<byte[]>();
    colList.add("col1".getBytes());
    colList.add("col2".getBytes());

    ReadCommand rm, rm2;//from   w  w w  . jav  a 2 s  .c  o m
    DecoratedKey dk = Util.dk("row1");

    rm = new SliceByNamesReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), colList);
    rm2 = serializeAndDeserializeReadMessage(rm);
    assert rm2.toString().equals(rm.toString());

    rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), ArrayUtils.EMPTY_BYTE_ARRAY,
            ArrayUtils.EMPTY_BYTE_ARRAY, true, 2);
    rm2 = serializeAndDeserializeReadMessage(rm);
    assert rm2.toString().equals(rm.toString());

    rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), "a".getBytes(),
            "z".getBytes(), true, 5);
    rm2 = serializeAndDeserializeReadMessage(rm);
    assertEquals(rm2.toString(), rm.toString());

    rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), ArrayUtils.EMPTY_BYTE_ARRAY,
            ArrayUtils.EMPTY_BYTE_ARRAY, true, 2);
    rm2 = serializeAndDeserializeReadMessage(rm);
    assert rm2.toString().equals(rm.toString());

    rm = new SliceFromReadCommand("Keyspace1", dk.key, new QueryPath("Standard1"), "a".getBytes(),
            "z".getBytes(), true, 5);
    rm2 = serializeAndDeserializeReadMessage(rm);
    assertEquals(rm2.toString(), rm.toString());
}

From source file:org.apache.cassandra.db.Table.java

/**
 * This method adds the row to the Commit Log associated with this table.
 * Once this happens the data associated with the individual column families
 * is also written to the column family store's memtable.
*///from   w w  w . j  a v a2s .c o  m
public void apply(RowMutation mutation, Object serializedMutation, boolean writeCommitLog) throws IOException {
    HashMap<ColumnFamilyStore, Memtable> memtablesToFlush = new HashMap<ColumnFamilyStore, Memtable>(2);

    // write the mutation to the commitlog and memtables
    flusherLock.readLock().lock();
    try {
        if (writeCommitLog)
            CommitLog.instance().add(mutation, serializedMutation);

        DecoratedKey key = StorageService.getPartitioner().decorateKey(mutation.key());
        for (ColumnFamily cf : mutation.getColumnFamilies()) {
            ColumnFamilyStore cfs = columnFamilyStores.get(cf.id());
            if (cfs == null) {
                logger.error("Attempting to mutate non-existant column family " + cf.id());
                continue;
            }

            SortedSet<byte[]> mutatedIndexedColumns = null;
            for (byte[] column : cfs.getIndexedColumns()) {
                if (cf.getColumnNames().contains(column)) {
                    if (mutatedIndexedColumns == null)
                        mutatedIndexedColumns = new TreeSet<byte[]>(FBUtilities.byteArrayComparator);
                    mutatedIndexedColumns.add(column);
                }
            }

            if (mutatedIndexedColumns == null) {
                // just update the actual value, no extra synchronization
                applyCF(cfs, key, cf, memtablesToFlush);
            } else {
                synchronized (indexLockFor(mutation.key())) {
                    // read old indexed values
                    QueryFilter filter = QueryFilter.getNamesFilter(key,
                            new QueryPath(cfs.getColumnFamilyName()), mutatedIndexedColumns);
                    ColumnFamily oldIndexedColumns = cfs.getColumnFamily(filter);

                    // ignore obsolete column updates
                    if (oldIndexedColumns != null) {
                        for (IColumn oldColumn : oldIndexedColumns) {
                            if (cfs.metadata.reconciler
                                    .reconcile((Column) oldColumn, (Column) cf.getColumn(oldColumn.name()))
                                    .equals(oldColumn)) {
                                cf.remove(oldColumn.name());
                                mutatedIndexedColumns.remove(oldColumn.name());
                                oldIndexedColumns.remove(oldColumn.name());
                            }
                        }
                    }

                    // apply the mutation
                    applyCF(cfs, key, cf, memtablesToFlush);

                    // add new index entries
                    for (byte[] columnName : mutatedIndexedColumns) {
                        IColumn column = cf.getColumn(columnName);
                        DecoratedKey<LocalToken> valueKey = cfs.getIndexKeyFor(columnName, column.value());
                        ColumnFamily cfi = cfs.newIndexedColumnFamily(columnName);
                        cfi.addColumn(new Column(mutation.key(), ArrayUtils.EMPTY_BYTE_ARRAY, column.clock()));
                        applyCF(cfs.getIndexedColumnFamilyStore(columnName), valueKey, cfi, memtablesToFlush);
                    }

                    // remove the old index entries
                    if (oldIndexedColumns != null) {
                        int localDeletionTime = (int) (System.currentTimeMillis() / 1000);
                        for (Map.Entry<byte[], IColumn> entry : oldIndexedColumns.getColumnsMap().entrySet()) {
                            byte[] columnName = entry.getKey();
                            IColumn column = entry.getValue();
                            DecoratedKey<LocalToken> valueKey = cfs.getIndexKeyFor(columnName, column.value());
                            ColumnFamily cfi = cfs.newIndexedColumnFamily(columnName);
                            cfi.deleteColumn(mutation.key(), localDeletionTime, column.clock());
                            applyCF(cfs.getIndexedColumnFamilyStore(columnName), valueKey, cfi,
                                    memtablesToFlush);
                        }
                    }
                }
            }

            ColumnFamily cachedRow = cfs.getRawCachedRow(key);
            if (cachedRow != null)
                cachedRow.addAll(cf);
        }
    } finally {
        flusherLock.readLock().unlock();
    }

    // flush memtables that got filled up.  usually mTF will be empty and this will be a no-op
    for (Map.Entry<ColumnFamilyStore, Memtable> entry : memtablesToFlush.entrySet())
        entry.getKey().maybeSwitchMemtable(entry.getValue(), writeCommitLog);
}