use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class RowDigestResolver method resolve.
/*
* This method handles two different scenarios:
*
* a) we're handling the initial read, of data from the closest replica + digests
* from the rest. In this case we check the digests against each other,
* throw an exception if there is a mismatch, otherwise return the data row.
*
* b) we're checking additional digests that arrived after the minimum to handle
* the requested ConsistencyLevel, i.e. asynchronous read repair check
*/
public Row resolve() throws DigestMismatchException, IOException {
if (logger.isDebugEnabled())
logger.debug("resolving " + replies.size() + " responses");
long startTime = System.currentTimeMillis();
// validate digests against each other; throw immediately on mismatch.
// also extract the data reply, if any.
ColumnFamily data = null;
ByteBuffer digest = null;
for (Map.Entry<Message, ReadResponse> entry : replies.entrySet()) {
ReadResponse response = entry.getValue();
if (response.isDigestQuery()) {
if (digest == null) {
digest = response.digest();
} else {
ByteBuffer digest2 = response.digest();
if (!digest.equals(digest2))
throw new DigestMismatchException(key, digest, digest2);
}
} else {
data = response.row().cf;
}
}
// that can only happen when we're doing the repair post-mismatch, and will be handled by RowRepairResolver.
if (digest != null) {
ByteBuffer digest2 = ColumnFamily.digest(data);
if (!digest.equals(digest2))
throw new DigestMismatchException(key, digest, digest2);
if (logger.isDebugEnabled())
logger.debug("digests verified");
}
if (logger.isDebugEnabled())
logger.debug("resolve: " + (System.currentTimeMillis() - startTime) + " ms.");
return new Row(key, data);
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class PendingTransactionMutation method makePending.
/* To mark columns as in a pending transaction, we'll apply the normal
* mutation except we'll use PendingTransactionColumns instead of what's
* ultimately intended
*/
public void makePending(QueryPath path) {
Integer id = Schema.instance.getId(table_, path.columnFamilyName);
ColumnFamily columnFamily = modifications_.get(id);
if (columnFamily == null) {
columnFamily = ColumnFamily.create(table_, path.columnFamilyName);
modifications_.put(id, columnFamily);
}
columnFamily.addPendingTransactionColumn(path, transactionId, pendingTime);
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class SSTableExportTest method testRoundTripStandardCf.
@Test
public void testRoundTripStandardCf() throws IOException, ParseException {
File tempSS = tempSSTableFile("Keyspace1", "Standard1");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("name")), ByteBufferUtil.bytes("val"), System.currentTimeMillis());
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
// Add rowExclude
cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("name")), ByteBufferUtil.bytes("val"), System.currentTimeMillis());
writer.append(Util.dk("rowExclude"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("Standard1", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[] { asHex("rowExclude") });
// Import JSON to another SSTable file
File tempSS2 = tempSSTableFile("Keyspace1", "Standard1");
SSTableImport.importJson(tempJson.getPath(), "Keyspace1", "Standard1", tempSS2.getPath());
reader = SSTableReader.open(Descriptor.fromFilename(tempSS2.getPath()));
QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Standard1", null, null), ByteBufferUtil.bytes("name"));
ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
assertTrue(cf != null);
assertTrue(cf.getColumn(ByteBufferUtil.bytes("name")).value().equals(hexToBytes("76616c")));
qf = QueryFilter.getNamesFilter(Util.dk("rowExclude"), new QueryPath("Standard1", null, null), ByteBufferUtil.bytes("name"));
cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
assert cf == null;
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class SSTableExportTest method testExportSimpleCf.
@Test
public void testExportSimpleCf() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "Standard1");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
//live for 42 seconds
int nowInSec = (int) (System.currentTimeMillis() / 1000) + 42;
// Add rowA
cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis());
cfamily.addColumn(null, new ExpiringColumn(ByteBufferUtil.bytes("colExp"), ByteBufferUtil.bytes("valExp"), System.currentTimeMillis(), 42, nowInSec));
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
// Add rowB
cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis());
writer.append(Util.dk("rowB"), cfamily);
cfamily.clear();
// Add rowExclude
cfamily.addColumn(new QueryPath("Standard1", null, ByteBufferUtil.bytes("colX")), ByteBufferUtil.bytes("valX"), System.currentTimeMillis());
writer.append(Util.dk("rowExclude"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("Standard1", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[] { asHex("rowExclude") });
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(1)).equals(ByteBufferUtil.bytes("valA"));
JSONArray colExp = (JSONArray) rowA.get(1);
assert ((Long) colExp.get(4)) == 42;
assert ((Long) colExp.get(5)) == nowInSec;
JSONArray rowB = (JSONArray) json.get(asHex("rowB"));
JSONArray colB = (JSONArray) rowB.get(0);
assert colB.size() == 3;
JSONArray rowExclude = (JSONArray) json.get(asHex("rowExclude"));
assert rowExclude == null;
}
use of org.apache.cassandra.db.ColumnFamily in project eiger by wlloyd.
the class SSTableExportTest method testExportSuperCf.
@Test
public void testExportSuperCf() throws IOException {
File tempSS = tempSSTableFile("Keyspace1", "Super4");
ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Super4");
SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2);
// Add rowA
cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superA"), ByteBufferUtil.bytes("colA")), ByteBufferUtil.bytes("valA"), System.currentTimeMillis());
writer.append(Util.dk("rowA"), cfamily);
cfamily.clear();
// Add rowB
cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superB"), ByteBufferUtil.bytes("colB")), ByteBufferUtil.bytes("valB"), System.currentTimeMillis());
writer.append(Util.dk("rowB"), cfamily);
cfamily.clear();
// Add rowExclude
cfamily.addColumn(new QueryPath("Super4", ByteBufferUtil.bytes("superX"), ByteBufferUtil.bytes("colX")), ByteBufferUtil.bytes("valX"), System.currentTimeMillis());
writer.append(Util.dk("rowExclude"), cfamily);
cfamily.clear();
SSTableReader reader = writer.closeAndOpenReader();
// Export to JSON and verify
File tempJson = File.createTempFile("Super4", ".json");
SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[] { asHex("rowExclude") });
JSONObject json = (JSONObject) JSONValue.parse(new FileReader(tempJson));
JSONObject rowA = (JSONObject) json.get(asHex("rowA"));
JSONObject superA = (JSONObject) rowA.get(cfamily.getComparator().getString(ByteBufferUtil.bytes("superA")));
JSONArray subColumns = (JSONArray) superA.get("subColumns");
JSONArray colA = (JSONArray) subColumns.get(0);
JSONObject rowExclude = (JSONObject) json.get(asHex("rowExclude"));
assert hexToBytes((String) colA.get(1)).equals(ByteBufferUtil.bytes("valA"));
assert colA.size() == 3;
assert rowExclude == null;
}
Aggregations