Search in sources :

Example 1 with BackpointerStreamView

use of org.corfudb.runtime.view.stream.BackpointerStreamView in project CorfuDB by CorfuDB.

the class CheckpointSmokeTest method writeCheckpointRecords.

private void writeCheckpointRecords(UUID streamId, String checkpointAuthor, UUID checkpointId, Object[] objects, Runnable l1, Runnable l2, boolean write1, boolean write2, boolean write3) throws Exception {
    BackpointerStreamView sv = new BackpointerStreamView(r, streamId);
    Map<CheckpointEntry.CheckpointDictKey, String> mdKV = new HashMap<>();
    mdKV.put(CheckpointEntry.CheckpointDictKey.START_TIME, "The perfect time");
    // Write cp #1 of 3
    if (write1) {
        TokenResponse tokResp1 = r.getSequencerView().nextToken(Collections.singleton(streamId), 0);
        long addr1 = tokResp1.getToken().getTokenValue();
        mdKV.put(CheckpointEntry.CheckpointDictKey.START_LOG_ADDRESS, Long.toString(addr1 + 1));
        CheckpointEntry cp1 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.START, checkpointAuthor, checkpointId, mdKV, null);
        sv.append(cp1, null, null);
    }
    // Interleaving opportunity #1
    l1.run();
    // Write cp #2 of 3
    if (write2) {
        MultiSMREntry smrEntries = new MultiSMREntry();
        if (objects != null) {
            for (int i = 0; i < objects.length; i++) {
                smrEntries.addTo(new SMREntry("put", (Object[]) objects[i], Serializers.JSON));
            }
        }
        CheckpointEntry cp2 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.CONTINUATION, checkpointAuthor, checkpointId, mdKV, smrEntries);
        sv.append(cp2, null, null);
    }
    // Interleaving opportunity #2
    l2.run();
    // Write cp #3 of 3
    if (write3) {
        CheckpointEntry cp3 = new CheckpointEntry(CheckpointEntry.CheckpointEntryType.END, checkpointAuthor, checkpointId, mdKV, null);
        sv.append(cp3, null, null);
    }
}
Also used : CheckpointEntry(org.corfudb.protocols.logprotocol.CheckpointEntry) TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) SMREntry(org.corfudb.protocols.logprotocol.SMREntry) BackpointerStreamView(org.corfudb.runtime.view.stream.BackpointerStreamView) MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry)

Aggregations

CheckpointEntry (org.corfudb.protocols.logprotocol.CheckpointEntry)1 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)1 SMREntry (org.corfudb.protocols.logprotocol.SMREntry)1 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)1 BackpointerStreamView (org.corfudb.runtime.view.stream.BackpointerStreamView)1