Example usage for org.apache.cassandra.db DeletionTime serializer

List of usage examples for org.apache.cassandra.db DeletionTime serializer

Introduction

In this page you can find the example usage for org.apache.cassandra.db DeletionTime serializer.

Prototype

Serializer serializer

To view the source code for org.apache.cassandra.db DeletionTime serializer.

Click Source Link

Usage

From source file:com.cloudian.support.RowFinder.java

License:Apache License

private void find() throws IOException {

    // get ColumnFamilyStore instance
    System.out.println("Opening keyspace " + ksName + " ...");
    Keyspace keyspace = Keyspace.open(ksName);
    System.out.println("Opened keyspace " + ksName);

    System.out.println("Getting column family " + cfName + " ...");
    ColumnFamilyStore cfStore = keyspace.getColumnFamilyStore(cfName);
    Collection<SSTableReader> ssTables = cfStore.getSSTables();
    System.out.println("Got column family " + cfName);

    ByteBuffer buff = ByteBufferUtil.bytes(this.rowKey);
    IPartitioner<?> partitioner = cfStore.partitioner;

    System.out.println(this.rowKey + " is included in the following files");
    System.out.println("==============================================================================");
    System.out.println("FINE_NAME, COLUMN_INFO, CONTIGUOUS_TOMBSTONED_COLUMNS(over " + threshold + ")");
    System.out.println("==============================================================================");
    for (SSTableReader reader : ssTables) {

        if (reader.getBloomFilter().isPresent(buff)) {

            // seek to row key
            RandomAccessReader dfile = reader.openDataReader();
            RowIndexEntry entry = reader.getPosition(partitioner.decorateKey(buff), SSTableReader.Operator.EQ);
            if (entry == null)
                continue;
            dfile.seek(entry.position);//w w  w  .  j  a va2 s  . c  o  m

            // read some
            ByteBufferUtil.readWithShortLength(dfile);
            if (reader.descriptor.version.hasRowSizeAndColumnCount)
                dfile.readLong();
            DeletionInfo deletionInfo = new DeletionInfo(DeletionTime.serializer.deserialize(dfile));
            int columnCount = reader.descriptor.version.hasRowSizeAndColumnCount ? dfile.readInt()
                    : Integer.MAX_VALUE;

            // get iterator
            Iterator<OnDiskAtom> atomIterator = reader.metadata.getOnDiskIterator(dfile, columnCount,
                    reader.descriptor.version);

            // iterate
            System.out.print(new File(reader.getFilename()).getName());
            boolean isContiguous = false;
            int contiguousTombstonedColumns = 0;
            String contiguousTombstonedColumnsStart = null;
            int live = 0;
            int deleted = 0;
            int rangeTombstone = 0;
            StringBuffer sb = new StringBuffer();
            while (atomIterator.hasNext()) {

                OnDiskAtom atom = atomIterator.next();

                if (atom instanceof Column) {

                    if (atom instanceof DeletedColumn) {

                        deleted++;

                        if (!isContiguous) {

                            isContiguous = true;
                            contiguousTombstonedColumnsStart = ByteBufferUtil.string(atom.name());

                        }

                        contiguousTombstonedColumns++;

                    } else {

                        live++;

                        if (isContiguous) {

                            // print
                            if (contiguousTombstonedColumns >= this.threshold) {

                                sb.append(", [" + contiguousTombstonedColumnsStart + "|"
                                        + contiguousTombstonedColumns + "]");

                            }

                            // reset
                            contiguousTombstonedColumns = 0;
                            contiguousTombstonedColumnsStart = null;
                            isContiguous = false;

                        }

                    }

                } else if (atom instanceof RangeTombstone) {

                    rangeTombstone++;

                    int localDeletionTime = atom.getLocalDeletionTime();
                    ByteBuffer min = ((RangeTombstone) atom).min;
                    ByteBuffer max = ((RangeTombstone) atom).max;
                    String minString = ByteBufferUtil.string(min);
                    String maxString = ByteBufferUtil.string(max);

                    sb.append(", [" + minString + ", " + maxString + "(" + localDeletionTime + ")]");

                }

                // if it ends with finished columns
                if (contiguousTombstonedColumns >= this.threshold) {

                    sb.append(
                            ", [" + contiguousTombstonedColumnsStart + "|" + contiguousTombstonedColumns + "]");

                }

            }

            System.out.print(", (live, deleted, range tombstone)=(" + live + ", " + deleted + ", "
                    + rangeTombstone + ")");
            System.out.println(sb.toString());

        }

    }

}