Search in sources :

Example 1 with DataOutrankedException

use of org.corfudb.runtime.exceptions.DataOutrankedException in project CorfuDB by CorfuDB.

the class QuorumReplicationProtocol method recoveryWrite.

private boolean recoveryWrite(Layout layout, ILogData logData) {
    long address = logData.getGlobalAddress();
    log.debug("Recovery write at {} " + address);
    Holder<ILogData> dh = new Holder<>(logData);
    AtomicBoolean otherValueAdopted = new AtomicBoolean(false);
    AtomicInteger retryCount = new AtomicInteger(0);
    if (logData.getRank() == null) {
        logData.setRank(new IMetadata.DataRank(0));
    }
    try {
        IRetry.build(ExponentialBackoffRetry.class, () -> {
            QuorumFuturesFactory.CompositeFuture<Boolean> future = null;
            try {
                log.debug("Recovery write loop for " + log);
                // increment the rank
                dh.getRef().releaseBuffer();
                dh.getRef().setRank(dh.getRef().getRank().buildHigherRank());
                // peek for existing
                if (retryCount.getAndIncrement() > 0) {
                    try {
                        return holeFillPolicy.peekUntilHoleFillRequired(address, a -> peek(layout, a));
                    } catch (HoleFillRequiredException e) {
                        log.debug(e.getMessage(), e);
                    // continuing
                    }
                }
                // phase 1
                try (ILogData.SerializationHandle ph1 = createEmptyData(dh.getRef().getGlobalAddress(), DataType.RANK_ONLY, dh.getRef().getRank())) {
                    future = getWriteFuture(layout, ph1.getSerialized());
                    CFUtils.getUninterruptibly(future, QuorumUnreachableException.class, OverwriteException.class, DataOutrankedException.class);
                } catch (LogUnitException | QuorumUnreachableException e) {
                    e.printStackTrace();
                    ReadResponse rr = getAdoptedValueWithHighestRankIfPresent(address, future.getThrowables());
                    if (rr != null) {
                        // check
                        LogData logDataExisting = rr.getReadSet().get(address);
                        logDataExisting.releaseBuffer();
                        logDataExisting.setRank(dh.getRef().getRank());
                        dh.setRef(logDataExisting.getSerializedForm().getSerialized());
                        otherValueAdopted.set(true);
                    // value adopted - continue on phase 2
                    } else {
                        throw e;
                    }
                }
                // phase 2 - only if exception is not thrown from phase 1
                future = getWriteFuture(layout, dh.getRef());
                CFUtils.getUninterruptibly(future, QuorumUnreachableException.class, OverwriteException.class, DataOutrankedException.class);
                log.trace("Write done[{}]: {}", address);
                return dh.getRef();
            } catch (QuorumUnreachableException | DataOutrankedException e) {
                e.printStackTrace();
                throw new RetryNeededException();
            } catch (RuntimeException e) {
                e.printStackTrace();
                throw e;
            }
        }).setOptions(WRITE_RETRY_SETTINGS).run();
        return otherValueAdopted.get();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException("interrupted", e);
    } catch (RuntimeException e) {
        throw e;
    }
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) QuorumFuturesFactory(org.corfudb.runtime.view.QuorumFuturesFactory) QuorumUnreachableException(org.corfudb.runtime.exceptions.QuorumUnreachableException) Holder(org.corfudb.util.Holder) HoleFillRequiredException(org.corfudb.runtime.exceptions.HoleFillRequiredException) RetryNeededException(org.corfudb.util.retry.RetryNeededException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMetadata(org.corfudb.protocols.wireprotocol.IMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReadResponse(org.corfudb.protocols.wireprotocol.ReadResponse) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogUnitException(org.corfudb.runtime.exceptions.LogUnitException)

Example 2 with DataOutrankedException

use of org.corfudb.runtime.exceptions.DataOutrankedException in project CorfuDB by CorfuDB.

the class StreamLogWithRankedAddressSpaceTest method testProposalsLowerRank.

@Test
public void testProposalsLowerRank() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.RANK_ONLY, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.RANK_ONLY, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 3 with DataOutrankedException

use of org.corfudb.runtime.exceptions.DataOutrankedException in project CorfuDB by CorfuDB.

the class StreamLogWithRankedAddressSpaceTest method testLowerRankAgainstProposal.

@Test
public void testLowerRankAgainstProposal() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.RANK_ONLY, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.DATA, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 4 with DataOutrankedException

use of org.corfudb.runtime.exceptions.DataOutrankedException in project CorfuDB by CorfuDB.

the class StreamLogWithRankedAddressSpaceTest method testProposalWithLowerRankAgainstData.

@Test
public void testProposalWithLowerRankAgainstData() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.DATA, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.RANK_ONLY, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 5 with DataOutrankedException

use of org.corfudb.runtime.exceptions.DataOutrankedException in project CorfuDB by CorfuDB.

the class StreamLogWithRankedAddressSpaceTest method testLowerRank.

@Test
public void testLowerRank() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.DATA, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.DATA, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Aggregations

LogData (org.corfudb.protocols.wireprotocol.LogData)6 DataOutrankedException (org.corfudb.runtime.exceptions.DataOutrankedException)6 AbstractCorfuTest (org.corfudb.AbstractCorfuTest)4 Test (org.junit.Test)4 ReadResponse (org.corfudb.protocols.wireprotocol.ReadResponse)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ILogData (org.corfudb.protocols.wireprotocol.ILogData)1 IMetadata (org.corfudb.protocols.wireprotocol.IMetadata)1 HoleFillRequiredException (org.corfudb.runtime.exceptions.HoleFillRequiredException)1 LogUnitException (org.corfudb.runtime.exceptions.LogUnitException)1 OverwriteException (org.corfudb.runtime.exceptions.OverwriteException)1 QuorumUnreachableException (org.corfudb.runtime.exceptions.QuorumUnreachableException)1 ValueAdoptedException (org.corfudb.runtime.exceptions.ValueAdoptedException)1 QuorumFuturesFactory (org.corfudb.runtime.view.QuorumFuturesFactory)1 Holder (org.corfudb.util.Holder)1 RetryNeededException (org.corfudb.util.retry.RetryNeededException)1