List of usage examples for org.apache.cassandra.io.sstable ISSTableScanner close
public void close();
From source file:com.scylladb.tools.SSTableToCQL.java
License:Open Source License
public void stream(File directoryOrSStable) throws IOException, ConfigurationException { RowBuilder builder = new RowBuilder(client); logger.info("Opening sstables and calculating sections to stream"); Map<InetAddress, Collection<Range<Token>>> ranges = client.getEndpointRanges(); Collection<SSTableReader> sstables = openSSTables(directoryOrSStable); // Hack. Must do because Range mangling code in cassandra is // broken, and does not preserve input range objects internal // "partitioner" field. DatabaseDescriptor.setPartitioner(client.getPartitioner()); try {/*from w w w.j a va2 s. com*/ for (SSTableReader reader : sstables) { if (ranges == null || ranges.isEmpty()) { ISSTableScanner scanner = reader.getScanner(); try { process(builder, null, scanner); } finally { scanner.close(); } } else { for (Map.Entry<InetAddress, Collection<Range<Token>>> e : ranges.entrySet()) { ISSTableScanner scanner = reader.getScanner(e.getValue(), null); try { process(builder, e.getKey(), scanner); } finally { scanner.close(); } } } } } finally { client.finish(); } }
From source file:org.jasonstack.cassandra.devops.TomnStoneScanner.java
License:Apache License
private static void run(Descriptor desc) throws IOException { CFMetaData cfm = CFMetaData.sparseCFMetaData(desc.ksname, desc.cfname, UTF8Type.instance); SSTableReader reader = SSTableReader.open(desc, cfm); ISSTableScanner scanner = reader.getScanner(); long totalTombstones = 0, totalColumns = 0; while (scanner.hasNext()) { // for each partition SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next(); int tombstonesCount = 0, columnsCount = 0; while (row.hasNext()) { // for each column in partition OnDiskAtom column = row.next(); if (column instanceof BufferDeletedCell) { tombstonesCount++;/*from w w w . j a v a 2 s. c o m*/ } columnsCount++; } totalTombstones += tombstonesCount; totalColumns += columnsCount; if (tombstonesCount > 0) { String key; try { key = UTF8Type.instance.getString(row.getKey().getKey()); } catch (RuntimeException e) { key = BytesType.instance.getString(row.getKey().getKey()); } //System.out.printf("PartitionKey: %s, Tombstones(Total): %d (%d)%n", paritionKey, tombstonesCount, columnsCount); TombstoneMetric count = new TombstoneMetric(desc.cfname, key, tombstonesCount, columnsCount); collector.add(count); } } //System.out.printf("Result: %d tombstones out of total %d columns", totalTombstones, totalColumns); scanner.close(); }