use of org.apache.accumulo.core.data.thrift.TMutation in project accumulo by apache.
the class MutationTest method testThrift_Invalid.
@Test(expected = IllegalArgumentException.class)
public void testThrift_Invalid() {
Mutation m1 = new Mutation("r1");
m1.put("cf1", "cq1", "v1");
TMutation tm1 = m1.toThrift();
tm1.setRow((byte[]) null);
new Mutation(tm1);
}
use of org.apache.accumulo.core.data.thrift.TMutation in project accumulo by apache.
the class MutationTest method testThrift.
@Test
public void testThrift() {
Mutation m1 = new Mutation("r1");
m1.put("cf1", "cq1", "v1");
TMutation tm1 = m1.toThrift();
Mutation m2 = new Mutation(tm1);
assertEquals(m1, m2);
}
use of org.apache.accumulo.core.data.thrift.TMutation in project accumulo by apache.
the class ConditionalWriterImpl method convertMutations.
private void convertMutations(TabletServerMutations<QCMutation> mutations, Map<Long, CMK> cmidToCm, MutableLong cmid, Map<TKeyExtent, List<TConditionalMutation>> tmutations, CompressedIterators compressedIters) {
for (Entry<KeyExtent, List<QCMutation>> entry : mutations.getMutations().entrySet()) {
TKeyExtent tke = entry.getKey().toThrift();
ArrayList<TConditionalMutation> tcondMutaions = new ArrayList<>();
List<QCMutation> condMutations = entry.getValue();
for (QCMutation cm : condMutations) {
TMutation tm = cm.toThrift();
List<TCondition> conditions = convertConditions(cm, compressedIters);
cmidToCm.put(cmid.longValue(), new CMK(entry.getKey(), cm));
TConditionalMutation tcm = new TConditionalMutation(conditions, tm, cmid.longValue());
cmid.increment();
tcondMutaions.add(tcm);
}
tmutations.put(tke, tcondMutaions);
}
}
use of org.apache.accumulo.core.data.thrift.TMutation in project accumulo by apache.
the class BatchWriterReplicationReplayerTest method systemTimestampsAreSetOnUpdates.
@Test
public void systemTimestampsAreSetOnUpdates() throws Exception {
final BatchWriterReplicationReplayer replayer = new BatchWriterReplicationReplayer();
final String tableName = "foo";
final long systemTimestamp = 1000;
final BatchWriterConfig bwCfg = new BatchWriterConfig();
bwCfg.setMaxMemory(1l);
LogFileKey key = new LogFileKey();
key.event = LogEvents.MANY_MUTATIONS;
key.seq = 1;
key.tid = 1;
WalEdits edits = new WalEdits();
// Make a mutation without timestamps
Mutation m = new Mutation("row");
m.put("cf", "cq1", "value");
m.put("cf", "cq2", "value");
m.put("cf", "cq3", "value");
m.put("cf", "cq4", "value");
m.put("cf", "cq5", "value");
// Make it a TMutation
TMutation tMutation = m.toThrift();
// And then make a ServerMutation from the TMutation, adding in our systemTimestamp
ServerMutation sMutation = new ServerMutation(tMutation);
sMutation.setSystemTimestamp(systemTimestamp);
// Serialize the ServerMutation (what AccumuloReplicaSystem will be doing)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
key.write(out);
out.writeInt(1);
sMutation.write(out);
out.close();
// Add it to our "input" to BatchWriterReplicationReplayer
edits.addToEdits(ByteBuffer.wrap(baos.toByteArray()));
Mutation expectedMutation = new Mutation("row");
expectedMutation.put("cf", "cq1", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq2", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq3", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq4", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq5", sMutation.getSystemTimestamp(), "value");
expect(conf.getAsBytes(Property.TSERV_REPLICATION_BW_REPLAYER_MEMORY)).andReturn(bwCfg.getMaxMemory());
expect(conn.createBatchWriter(tableName, bwCfg)).andReturn(bw);
bw.addMutations(Lists.newArrayList(expectedMutation));
expectLastCall().once();
bw.close();
expectLastCall().once();
replay(conn, conf, bw);
replayer.replicateLog(context, tableName, edits);
}
use of org.apache.accumulo.core.data.thrift.TMutation in project accumulo by apache.
the class BatchWriterReplicationReplayerTest method replicationSourcesArePreserved.
@Test
public void replicationSourcesArePreserved() throws Exception {
final BatchWriterReplicationReplayer replayer = new BatchWriterReplicationReplayer();
final String tableName = "foo";
final long systemTimestamp = 1000;
final String peerName = "peer";
final BatchWriterConfig bwCfg = new BatchWriterConfig();
bwCfg.setMaxMemory(1l);
LogFileKey key = new LogFileKey();
key.event = LogEvents.MANY_MUTATIONS;
key.seq = 1;
key.tid = 1;
WalEdits edits = new WalEdits();
// Make a mutation without timestamps
Mutation m = new Mutation("row");
m.put("cf", "cq1", "value");
m.put("cf", "cq2", "value");
m.put("cf", "cq3", "value");
m.put("cf", "cq4", "value");
m.put("cf", "cq5", "value");
// This Mutation "came" from a system called "peer"
m.addReplicationSource(peerName);
// Make it a TMutation
TMutation tMutation = m.toThrift();
// And then make a ServerMutation from the TMutation, adding in our systemTimestamp
ServerMutation sMutation = new ServerMutation(tMutation);
sMutation.setSystemTimestamp(systemTimestamp);
// Serialize the ServerMutation (what AccumuloReplicaSystem will be doing)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
key.write(out);
out.writeInt(1);
sMutation.write(out);
out.close();
// Add it to our "input" to BatchWriterReplicationReplayer
edits.addToEdits(ByteBuffer.wrap(baos.toByteArray()));
Mutation expectedMutation = new Mutation("row");
expectedMutation.put("cf", "cq1", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq2", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq3", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq4", sMutation.getSystemTimestamp(), "value");
expectedMutation.put("cf", "cq5", sMutation.getSystemTimestamp(), "value");
// We expect our peer name to be preserved in the mutation that gets written
expectedMutation.addReplicationSource(peerName);
expect(conf.getAsBytes(Property.TSERV_REPLICATION_BW_REPLAYER_MEMORY)).andReturn(bwCfg.getMaxMemory());
expect(conn.createBatchWriter(tableName, bwCfg)).andReturn(bw);
bw.addMutations(Lists.newArrayList(expectedMutation));
expectLastCall().once();
bw.close();
expectLastCall().once();
replay(conn, conf, bw);
replayer.replicateLog(context, tableName, edits);
}
Aggregations