Search in sources :

Example 1 with TMutation

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);
}
Also used : TMutation(org.apache.accumulo.core.data.thrift.TMutation) TMutation(org.apache.accumulo.core.data.thrift.TMutation) Test(org.junit.Test)

Example 2 with TMutation

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);
}
Also used : TMutation(org.apache.accumulo.core.data.thrift.TMutation) TMutation(org.apache.accumulo.core.data.thrift.TMutation) Test(org.junit.Test)

Example 3 with TMutation

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);
    }
}
Also used : ArrayList(java.util.ArrayList) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) TConditionalMutation(org.apache.accumulo.core.data.thrift.TConditionalMutation) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TCondition(org.apache.accumulo.core.data.thrift.TCondition) List(java.util.List) ArrayList(java.util.ArrayList) TMutation(org.apache.accumulo.core.data.thrift.TMutation)

Example 4 with TMutation

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);
}
Also used : DataOutputStream(java.io.DataOutputStream) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) ServerMutation(org.apache.accumulo.server.data.ServerMutation) TMutation(org.apache.accumulo.core.data.thrift.TMutation) LogFileKey(org.apache.accumulo.tserver.logger.LogFileKey) Mutation(org.apache.accumulo.core.data.Mutation) TMutation(org.apache.accumulo.core.data.thrift.TMutation) ServerMutation(org.apache.accumulo.server.data.ServerMutation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WalEdits(org.apache.accumulo.core.replication.thrift.WalEdits) Test(org.junit.Test)

Example 5 with TMutation

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);
}
Also used : DataOutputStream(java.io.DataOutputStream) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) ServerMutation(org.apache.accumulo.server.data.ServerMutation) TMutation(org.apache.accumulo.core.data.thrift.TMutation) LogFileKey(org.apache.accumulo.tserver.logger.LogFileKey) Mutation(org.apache.accumulo.core.data.Mutation) TMutation(org.apache.accumulo.core.data.thrift.TMutation) ServerMutation(org.apache.accumulo.server.data.ServerMutation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WalEdits(org.apache.accumulo.core.replication.thrift.WalEdits) Test(org.junit.Test)

Aggregations

TMutation (org.apache.accumulo.core.data.thrift.TMutation)6 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)2 Mutation (org.apache.accumulo.core.data.Mutation)2 WalEdits (org.apache.accumulo.core.replication.thrift.WalEdits)2 ServerMutation (org.apache.accumulo.server.data.ServerMutation)2 LogFileKey (org.apache.accumulo.tserver.logger.LogFileKey)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)1 TCondition (org.apache.accumulo.core.data.thrift.TCondition)1 TConditionalMutation (org.apache.accumulo.core.data.thrift.TConditionalMutation)1 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)1