use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class LeveledManifest method getCandidatesFor.
private Collection<SSTableReader> getCandidatesFor(int level) {
assert !generations[level].isEmpty();
logger.debug("Choosing candidates for L{}", level);
if (level == 0) {
// because L0 files may overlap each other, we treat compactions there specially:
// a L0 compaction also checks other L0 files for overlap.
Set<SSTableReader> candidates = new HashSet<SSTableReader>();
// pick the oldest sstable from L0, and any that overlap with it
List<SSTableReader> ageSortedSSTables = new ArrayList<SSTableReader>(generations[0]);
Collections.sort(ageSortedSSTables, SSTable.maxTimestampComparator);
List<SSTableReader> L0 = overlapping(ageSortedSSTables.get(0), generations[0]);
L0 = L0.size() > MAX_COMPACTING_L0 ? L0.subList(0, MAX_COMPACTING_L0) : L0;
// add the overlapping ones from L1
for (SSTableReader sstable : L0) candidates.addAll(overlapping(sstable, generations[1]));
return candidates;
}
// for non-L0 compactions, pick up where we left off last time
Collections.sort(generations[level], SSTable.sstableComparator);
for (SSTableReader sstable : generations[level]) {
// the first sstable that is > than the marked
if (sstable.first.compareTo(lastCompactedKeys[level]) > 0)
return overlapping(sstable, generations[(level + 1)]);
}
// or if there was no last time, start with the first sstable
return overlapping(generations[level].get(0), generations[(level + 1)]);
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class LeveledManifest method create.
static LeveledManifest create(ColumnFamilyStore cfs, int maxSSTableSize) {
LeveledManifest manifest = new LeveledManifest(cfs, maxSSTableSize);
load(cfs, manifest);
// ensure all SSTables are in the manifest
for (SSTableReader ssTableReader : cfs.getSSTables()) {
if (manifest.levelOf(ssTableReader) < 0)
manifest.add(ssTableReader);
}
return manifest;
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class LeveledManifest method promote.
public synchronized void promote(Iterable<SSTableReader> removed, Iterable<SSTableReader> added) {
// use add() instead of promote when adding new sstables
assert !Iterables.isEmpty(removed);
logDistribution();
if (logger.isDebugEnabled())
logger.debug("Replacing [" + toString(removed) + "]");
// the level for the added sstables is the max of the removed ones,
// plus one if the removed were all on the same level
int minimumLevel = Integer.MAX_VALUE;
int maximumLevel = 0;
for (SSTableReader sstable : removed) {
int thisLevel = levelOf(sstable);
maximumLevel = Math.max(maximumLevel, thisLevel);
minimumLevel = Math.min(minimumLevel, thisLevel);
remove(sstable);
}
// it's valid to do a remove w/o an add (e.g. on truncate)
if (!added.iterator().hasNext())
return;
int newLevel = minimumLevel == maximumLevel ? maximumLevel + 1 : maximumLevel;
newLevel = skipLevels(newLevel, added);
assert newLevel > 0;
if (logger.isDebugEnabled())
logger.debug("Adding [{}] at L{}", toString(added), newLevel);
lastCompactedKeys[minimumLevel] = SSTable.sstableOrdering.max(added).last;
for (SSTableReader ssTableReader : added) add(ssTableReader, newLevel);
serialize();
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class SSTableExportTest method testEscapingDoubleQuotes.
@Test
public void testEscapingDoubleQuotes() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "ValuesWithQuotes");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "ValuesWithQuotes");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(null, new Column(ByteBufferUtil.bytes("data"), UTF8Type.instance.fromString("{\"foo\":\"bar\"}")));
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("ValuesWithQuotes", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
JSONArray data = (JSONArray) rowA.get(0);
assert hexToBytes((String) data.get(0)).equals(ByteBufferUtil.bytes("data"));
assert data.get(1).equals("{\"foo\":\"bar\"}");
}
use of org.apache.cassandra.io.sstable.SSTableReader in project eiger by wlloyd.
the class SSTableExportTest method testExportCounterCf.
@Test
public void testExportCounterCf() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "Counter1");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Counter1");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(null, new CounterColumn(ByteBufferUtil.bytes("colA"), 42, System.currentTimeMillis()));
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("Counter1", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[0]);
JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
JSONArray rowA = (JSONArray) json.get(asHex("rowA"));
JSONArray colA = (JSONArray) rowA.get(0);
assert hexToBytes((String) colA.get(0)).equals(ByteBufferUtil.bytes("colA"));
assert ((String) colA.get(3)).equals("c");
assert (Long) colA.get(4) == Long.MIN_VALUE;
}
Aggregations