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.db.TimeSortTest.java

@Test
public void testMixedSources() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore cfStore = table.getColumnFamilyStore("StandardLong1");
    RowMutation rm;/*from   ww w . ja v a 2 s  .c  o  m*/
    DecoratedKey key = Util.dk("key0");

    rm = new RowMutation("Keyspace1", key.key);
    rm.add(new QueryPath("StandardLong1", null, getBytes(100)), "a".getBytes(), new TimestampClock(100));
    rm.apply();
    cfStore.forceBlockingFlush();

    rm = new RowMutation("Keyspace1", key.key);
    rm.add(new QueryPath("StandardLong1", null, getBytes(0)), "b".getBytes(), new TimestampClock(0));
    rm.apply();

    ColumnFamily cf = cfStore.getColumnFamily(key, new QueryPath("StandardLong1"), getBytes(10),
            ArrayUtils.EMPTY_BYTE_ARRAY, false, 1000);
    Collection<IColumn> columns = cf.getSortedColumns();
    assert columns.size() == 1;
}

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

@Test
public void testTimeSort() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore cfStore = table.getColumnFamilyStore("StandardLong1");

    for (int i = 900; i < 1000; ++i) {
        RowMutation rm = new RowMutation("Keyspace1", Integer.toString(i).getBytes());
        for (int j = 0; j < 8; ++j) {
            rm.add(new QueryPath("StandardLong1", null, getBytes(j * 2)), "a".getBytes(),
                    new TimestampClock(j * 2));
        }//  www . ja  va  2  s . c  o  m
        rm.apply();
    }

    validateTimeSort(table);

    cfStore.forceBlockingFlush();
    validateTimeSort(table);

    // interleave some new data to test memtable + sstable
    DecoratedKey key = Util.dk("900");
    RowMutation rm = new RowMutation("Keyspace1", key.key);
    for (int j = 0; j < 4; ++j) {
        rm.add(new QueryPath("StandardLong1", null, getBytes(j * 2 + 1)), "b".getBytes(),
                new TimestampClock(j * 2 + 1));
    }
    rm.apply();
    // and some overwrites
    rm = new RowMutation("Keyspace1", key.key);
    rm.add(new QueryPath("StandardLong1", null, getBytes(0)), "c".getBytes(), new TimestampClock(100));
    rm.add(new QueryPath("StandardLong1", null, getBytes(10)), "c".getBytes(), new TimestampClock(100));
    rm.apply();

    // verify
    ColumnFamily cf = cfStore.getColumnFamily(key, new QueryPath("StandardLong1"), getBytes(0),
            ArrayUtils.EMPTY_BYTE_ARRAY, false, 1000);
    Collection<IColumn> columns = cf.getSortedColumns();
    assertEquals(12, columns.size());
    Iterator<IColumn> iter = columns.iterator();
    IColumn column;
    for (int j = 0; j < 8; j++) {
        column = iter.next();
        assert Arrays.equals(column.name(), getBytes(j));
    }
    TreeSet<byte[]> columnNames = new TreeSet<byte[]>(LongType.instance);
    columnNames.add(getBytes(10));
    columnNames.add(getBytes(0));
    cf = cfStore.getColumnFamily(
            QueryFilter.getNamesFilter(Util.dk("900"), new QueryPath("StandardLong1"), columnNames));
    assert "c".equals(new String(cf.getColumn(getBytes(0)).value()));
    assert "c".equals(new String(cf.getColumn(getBytes(10)).value()));
}

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

private void validateTimeSort(Table table) throws IOException {
    for (int i = 900; i < 1000; ++i) {
        DecoratedKey key = Util.dk(Integer.toString(i));
        for (int j = 0; j < 8; j += 3) {
            ColumnFamily cf = table.getColumnFamilyStore("StandardLong1").getColumnFamily(key,
                    new QueryPath("StandardLong1"), getBytes(j * 2), ArrayUtils.EMPTY_BYTE_ARRAY, false, 1000);
            Collection<IColumn> columns = cf.getSortedColumns();
            assert columns.size() == 8 - j;
            int k = j;
            for (IColumn c : columns) {
                assertEquals((k++) * 2, ((TimestampClock) c.clock()).timestamp());

            }/*from   ww w . ja  v a2 s  . c  om*/
        }
    }
}

From source file:org.apache.cassandra.dht.BootStrapper.java

static Token<?> getBootstrapTokenFrom(InetAddress maxEndpoint) {
    Message message = new Message(FBUtilities.getLocalAddress(), StorageService.Verb.BOOTSTRAP_TOKEN,
            ArrayUtils.EMPTY_BYTE_ARRAY, Gossiper.instance.getVersion(maxEndpoint));
    BootstrapTokenCallback btc = new BootstrapTokenCallback();
    MessagingService.instance().sendRR(message, maxEndpoint, btc);
    return btc.getToken();
}

From source file:org.apache.cassandra.dht.LocalPartitioner.java

public LocalToken getMinimumToken() {
    return new LocalToken(comparator, ArrayUtils.EMPTY_BYTE_ARRAY);
}

From source file:org.apache.cassandra.hadoop.ColumnFamilyRecordReader.java

static boolean isEmptyPredicate(SlicePredicate predicate) {
    if (predicate == null)
        return true;

    if (predicate.isSetColumn_names() && predicate.getSlice_range() == null)
        return false;

    if (predicate.getSlice_range() == null)
        return true;

    byte[] start = predicate.getSlice_range().getStart();
    byte[] finish = predicate.getSlice_range().getFinish();
    if ((start == null || start == ArrayUtils.EMPTY_BYTE_ARRAY)
            && (finish == null || finish == ArrayUtils.EMPTY_BYTE_ARRAY))
        return true;

    return false;
}

From source file:org.apache.cassandra.io.sstable.IndexRecoveryProcessor.java

/**
 * Removes the given SSTable from temporary status and opens it, rebuilding the non-essential portions of the
 * file if necessary./*from  w w w. ja v a 2  s. c o m*/
 * TODO: Builds most of the in-memory state of the sstable, but doesn't actually open it.
 *
 * @param desc Descriptor for the SSTable file
 */
public void recover(Descriptor desc) throws IOException {
    ColumnFamilyStore cfs = Table.open(desc.ksname).getColumnFamilyStore(desc.cfname);
    Set<byte[]> indexedColumns = cfs.getIndexedColumns();

    // open the data file for input, and an IndexWriter for output
    BufferedRandomAccessFile dfile = new BufferedRandomAccessFile(desc.filenameFor(SSTable.COMPONENT_DATA), "r",
            8 * 1024 * 1024);
    SSTableWriter.IndexWriter iwriter;
    long estimatedRows;
    try {
        estimatedRows = SSTableWriter.estimateRows(desc, dfile);
        iwriter = new SSTableWriter.IndexWriter(desc, StorageService.getPartitioner(), estimatedRows);
    } catch (IOException e) {
        dfile.close();
        throw e;
    }

    // build the index and filter
    long rows = 0;
    try {
        DecoratedKey key;
        long dataPosition = 0;
        while (dataPosition < dfile.length()) {
            key = SSTableReader.decodeKey(StorageService.getPartitioner(), desc,
                    FBUtilities.readShortByteArray(dfile));
            long dataSize = SSTableReader.readRowSize(dfile, desc);
            if (!indexedColumns.isEmpty()) {
                // skip bloom filter and column index
                dfile.readFully(new byte[dfile.readInt()]);
                dfile.readFully(new byte[dfile.readInt()]);

                // index the column data
                ColumnFamily cf = ColumnFamily.create(desc.ksname, desc.cfname);
                ColumnFamily.serializer().deserializeFromSSTableNoColumns(cf, dfile);
                int columns = dfile.readInt();
                for (int i = 0; i < columns; i++) {
                    IColumn iColumn = cf.getColumnSerializer().deserialize(dfile);
                    if (indexedColumns.contains(iColumn.name())) {
                        DecoratedKey valueKey = cfs.getIndexKeyFor(iColumn.name(), iColumn.value());
                        ColumnFamily indexedCf = cfs.newIndexedColumnFamily(iColumn.name());
                        indexedCf.addColumn(new Column(key.key, ArrayUtils.EMPTY_BYTE_ARRAY, iColumn.clock()));
                        logger.debug("adding indexed column row mutation for key {}", valueKey);
                        Table.open(desc.ksname).applyIndexedCF(cfs.getIndexedColumnFamilyStore(iColumn.name()),
                                key, valueKey, indexedCf);
                    }
                }
            }

            iwriter.afterAppend(key, dataPosition);
            dataPosition = dfile.getFilePointer() + dataSize;
            dfile.seek(dataPosition);
            rows++;
        }

        for (byte[] column : cfs.getIndexedColumns()) {
            try {
                cfs.getIndexedColumnFamilyStore(column).forceBlockingFlush();
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }
        }
    } finally {
        try {
            dfile.close();
            iwriter.close();
        } catch (IOException e) {
            logger.error("Failed to close data or index file during recovery of " + desc, e);
        }
    }

    SSTableWriter.rename(desc, SSTable.componentsFor(desc));

    logger.debug("estimated row count was %s of real count", ((double) estimatedRows) / rows);
}

From source file:org.apache.cassandra.io.sstable.SSTableWriter.java

/**
 * If either of the index or filter files are missing, rebuilds both.
 * TODO: Builds most of the in-memory state of the sstable, but doesn't actually open it.
 *///from w w  w. j  a v a 2  s .c  o  m
private static void maybeRecover(Descriptor desc) throws IOException {
    logger.debug("In maybeRecover with Descriptor {}", desc);
    File ifile = new File(desc.filenameFor(SSTable.COMPONENT_INDEX));
    File ffile = new File(desc.filenameFor(SSTable.COMPONENT_FILTER));
    if (ifile.exists() && ffile.exists())
        // nothing to do
        return;

    ColumnFamilyStore cfs = Table.open(desc.ksname).getColumnFamilyStore(desc.cfname);
    Set<byte[]> indexedColumns = cfs.getIndexedColumns();
    // remove existing files
    ifile.delete();
    ffile.delete();

    // open the data file for input, and an IndexWriter for output
    BufferedRandomAccessFile dfile = new BufferedRandomAccessFile(desc.filenameFor(SSTable.COMPONENT_DATA), "r",
            8 * 1024 * 1024);
    IndexWriter iwriter;
    long estimatedRows;
    try {
        estimatedRows = estimateRows(desc, dfile);
        iwriter = new IndexWriter(desc, StorageService.getPartitioner(), estimatedRows);
    } catch (IOException e) {
        dfile.close();
        throw e;
    }

    // build the index and filter
    long rows = 0;
    try {
        DecoratedKey key;
        long dataPosition = 0;
        while (dataPosition < dfile.length()) {
            key = SSTableReader.decodeKey(StorageService.getPartitioner(), desc,
                    FBUtilities.readShortByteArray(dfile));
            long dataSize = SSTableReader.readRowSize(dfile, desc);
            if (!indexedColumns.isEmpty()) {
                // skip bloom filter and column index
                dfile.readFully(new byte[dfile.readInt()]);
                dfile.readFully(new byte[dfile.readInt()]);

                // index the column data
                ColumnFamily cf = ColumnFamily.create(desc.ksname, desc.cfname);
                ColumnFamily.serializer().deserializeFromSSTableNoColumns(cf, dfile);
                int columns = dfile.readInt();
                for (int i = 0; i < columns; i++) {
                    IColumn iColumn = cf.getColumnSerializer().deserialize(dfile);
                    if (indexedColumns.contains(iColumn.name())) {
                        DecoratedKey valueKey = cfs.getIndexKeyFor(iColumn.name(), iColumn.value());
                        ColumnFamily indexedCf = cfs.newIndexedColumnFamily(iColumn.name());
                        indexedCf.addColumn(new Column(key.key, ArrayUtils.EMPTY_BYTE_ARRAY, iColumn.clock()));
                        logger.debug("adding indexed column row mutation for key {}", valueKey);
                        Table.open(desc.ksname).applyIndexedCF(cfs.getIndexedColumnFamilyStore(iColumn.name()),
                                key, valueKey, indexedCf);
                    }
                }
            }

            iwriter.afterAppend(key, dataPosition);
            dataPosition = dfile.getFilePointer() + dataSize;
            dfile.seek(dataPosition);
            rows++;
        }

        for (byte[] column : cfs.getIndexedColumns()) {
            try {
                cfs.getIndexedColumnFamilyStore(column).forceBlockingFlush();
            } catch (ExecutionException e) {
                throw new RuntimeException(e);
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }
        }
    } finally {
        try {
            dfile.close();
            iwriter.close();
        } catch (IOException e) {
            logger.error("Failed to close data or index file during recovery of " + desc, e);
        }
    }

    logger.debug("estimated row count was %s of real count", ((double) estimatedRows) / rows);
}

From source file:org.apache.cassandra.service.CassandraServer.java

public int get_column_count(String table, String key, ColumnParent column_parent, int consistency_level)
        throws InvalidRequestException {
    if (logger.isDebugEnabled())
        logger.debug("get_column_count");
    // validateColumnParent assumes we require simple columns; g_c_c is the only
    // one of the columnParent-taking apis that can also work at the SC level.
    // so we roll a one-off validator here.
    String cfType = ThriftValidation.validateColumnFamily(table, column_parent.column_family);
    if (cfType.equals("Standard") && column_parent.super_column != null) {
        throw new InvalidRequestException(
                "columnfamily alone is required for standard CF " + column_parent.column_family);
    }//w  w w.  java2 s .c o  m

    ColumnFamily cfamily;
    cfamily = readColumnFamily(new SliceFromReadCommand(table, key, column_parent, ArrayUtils.EMPTY_BYTE_ARRAY,
            ArrayUtils.EMPTY_BYTE_ARRAY, true, Integer.MAX_VALUE), consistency_level);
    if (cfamily == null) {
        return 0;
    }
    Collection<IColumn> columns = null;
    if (column_parent.super_column != null) {
        IColumn column = cfamily.getColumn(column_parent.super_column);
        if (column != null) {
            columns = column.getSubColumns();
        }
    } else {
        columns = cfamily.getSortedColumns();
    }
    if (columns == null || columns.size() == 0) {
        return 0;
    }
    return columns.size();
}

From source file:org.apache.cassandra.service.StorageProxy.java

/**
 * initiate a request/response session with each live node to check whether or not everybody is using the same
 * migration id. This is useful for determining if a schema change has propagated through the cluster. Disagreement
 * is assumed if any node fails to respond.
 *///from ww w.j  a v  a2 s  . c om
public static Map<String, List<String>> describeSchemaVersions() {
    final String myVersion = DatabaseDescriptor.getDefsVersion().toString();
    final Map<InetAddress, UUID> versions = new ConcurrentHashMap<InetAddress, UUID>();
    final Set<InetAddress> liveHosts = Gossiper.instance.getLiveMembers();
    final CountDownLatch latch = new CountDownLatch(liveHosts.size());

    IAsyncCallback cb = new IAsyncCallback() {
        public void response(Message message) {
            // record the response from the remote node.
            logger.debug("Received schema check response from " + message.getFrom().getHostAddress());
            UUID theirVersion = UUID.fromString(new String(message.getMessageBody()));
            versions.put(message.getFrom(), theirVersion);
            latch.countDown();
        }

        public boolean isLatencyForSnitch() {
            return false;
        }
    };
    // an empty message acts as a request to the SchemaCheckVerbHandler.
    for (InetAddress endpoint : liveHosts) {
        Message message = new Message(FBUtilities.getLocalAddress(), StorageService.Verb.SCHEMA_CHECK,
                ArrayUtils.EMPTY_BYTE_ARRAY, Gossiper.instance.getVersion(endpoint));
        MessagingService.instance().sendRR(message, endpoint, cb);
    }

    try {
        // wait for as long as possible. timeout-1s if possible.
        latch.await(DatabaseDescriptor.getRpcTimeout(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException ex) {
        throw new AssertionError("This latch shouldn't have been interrupted.");
    }

    logger.debug("My version is " + myVersion);

    // maps versions to hosts that are on that version.
    Map<String, List<String>> results = new HashMap<String, List<String>>();
    Iterable<InetAddress> allHosts = Iterables.concat(Gossiper.instance.getLiveMembers(),
            Gossiper.instance.getUnreachableMembers());
    for (InetAddress host : allHosts) {
        UUID version = versions.get(host);
        String stringVersion = version == null ? UNREACHABLE : version.toString();
        List<String> hosts = results.get(stringVersion);
        if (hosts == null) {
            hosts = new ArrayList<String>();
            results.put(stringVersion, hosts);
        }
        hosts.add(host.getHostAddress());
    }

    // we're done: the results map is ready to return to the client.  the rest is just debug logging:
    if (results.get(UNREACHABLE) != null)
        logger.debug("Hosts not in agreement. Didn't get a response from everybody: "
                + StringUtils.join(results.get(UNREACHABLE), ","));
    for (Map.Entry<String, List<String>> entry : results.entrySet()) {
        // check for version disagreement. log the hosts that don't agree.
        if (entry.getKey().equals(UNREACHABLE) || entry.getKey().equals(myVersion))
            continue;
        for (String host : entry.getValue())
            logger.debug("%s disagrees (%s)", host, entry.getKey());
    }
    if (results.size() == 1)
        logger.debug("Schemas are in agreement.");

    return results;
}