Search in sources :

Example 1 with ISerializer

use of org.corfudb.util.serializer.ISerializer in project CorfuDB by CorfuDB.

the class MultiCheckpointWriter method appendCheckpoints.

/** Checkpoint multiple SMRMaps serially.
     *
     * @param rt CorfuRuntime
     * @param author Author's name, stored in checkpoint metadata
     * @param postAppendFunc User-supplied lambda for post-append action on each
     *                       checkpoint entry type.
     * @return Global log address of the first record of
     * @throws Exception
     */
public long appendCheckpoints(CorfuRuntime rt, String author, BiConsumer<CheckpointEntry, Long> postAppendFunc) throws Exception {
    long globalAddress = CheckpointWriter.startGlobalSnapshotTxn(rt);
    try {
        for (ICorfuSMR<Map> map : maps) {
            UUID streamID = map.getCorfuStreamID();
            CheckpointWriter cpw = new CheckpointWriter(rt, streamID, author, (SMRMap) map);
            ISerializer serializer = ((CorfuCompileProxy<Map>) map.getCorfuSMRProxy()).getSerializer();
            cpw.setSerializer(serializer);
            cpw.setPostAppendFunc(postAppendFunc);
            List<Long> addresses = cpw.appendCheckpoint();
            checkpointLogAddresses.addAll(addresses);
        }
    } finally {
        rt.getObjectsView().TXEnd();
    }
    return globalAddress;
}
Also used : CorfuCompileProxy(org.corfudb.runtime.object.CorfuCompileProxy) UUID(java.util.UUID) Map(java.util.Map) SMRMap(org.corfudb.runtime.collections.SMRMap) ISerializer(org.corfudb.util.serializer.ISerializer)

Example 2 with ISerializer

use of org.corfudb.util.serializer.ISerializer in project CorfuDB by CorfuDB.

the class CorfuSMRObjectProxyTest method canUseCustomSerializer.

/** Disabled pending resolution of issue #285
    @Test
    public void deadLockTest() throws Exception {
        CorfuRuntime runtime = getDefaultRuntime().connect();
        Map<String, Integer> map =
                runtime.getObjectsView()
                        .build()
                        .setStreamName("M")
                        .setType(SMRMap.class)
                        .open();

        for(int x = 0; x < PARAMETERS.NUM_ITERATIONS_LOW; x++) {
            // thread 1: update "a" and "b" atomically
            Thread t1 = new Thread(() -> {
                runtime.getObjectsView().TXBegin();
                map.put("a", 1);
                map.put("b", 1);
                runtime.getObjectsView().TXEnd();
            }
            );
            t1.start();

            // thread 2: read "a", then "b"
            Thread t2 = new Thread(() -> {
                map.get("a");
                map.get("b");
            });
            t2.start();

            t1.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());
            t2.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());

            assertThat(t1.isAlive()).isFalse();
            assertThat(t2.isAlive()).isFalse();
        }
    }

    @Test
    @SuppressWarnings("unchecked")
    public void canUsePrimitiveSerializer()
            throws Exception {
        //begin tests
        CorfuRuntime r = getDefaultRuntime().connect();
        TestClassWithPrimitives test = r.getObjectsView().build()
                .setType(TestClassWithPrimitives.class)
                .setStreamName("test")
                .setSerializer(Serializers.PRIMITIVE)
                .open();

        test.setPrimitive("hello world".getBytes());
        assertThat(test.getPrimitive())
                .isEqualTo("hello world".getBytes());
    }
     **/
@Test
@SuppressWarnings("unchecked")
public void canUseCustomSerializer() throws Exception {
    //Register a custom serializer and use it with an SMR object
    ISerializer customSerializer = new CustomSerializer((byte) (Serializers.SYSTEM_SERIALIZERS_COUNT + 1));
    Serializers.registerSerializer(customSerializer);
    CorfuRuntime r = getDefaultRuntime();
    Map<String, String> test = r.getObjectsView().build().setType(SMRMap.class).setStreamName("test").setSerializer(customSerializer).open();
    test.put("a", "b");
    test.get("a");
    assertThat(test.get("a")).isEqualTo("b");
}
Also used : SMRMap(org.corfudb.runtime.collections.SMRMap) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) CustomSerializer(org.corfudb.CustomSerializer) ISerializer(org.corfudb.util.serializer.ISerializer) Test(org.junit.Test)

Aggregations

SMRMap (org.corfudb.runtime.collections.SMRMap)2 ISerializer (org.corfudb.util.serializer.ISerializer)2 Map (java.util.Map)1 UUID (java.util.UUID)1 CustomSerializer (org.corfudb.CustomSerializer)1 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)1 CorfuCompileProxy (org.corfudb.runtime.object.CorfuCompileProxy)1 Test (org.junit.Test)1