Search in sources :

Example 6 with OverwriteException

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

the class StreamLogWithRankedAddressSpace method assertAppendPermittedUnsafe.

/**
     * Check whether the data can be appended to a given log address.
     * Note that it is not permitted multiple threads to access the same log address
     * concurrently through this method, this method does not lock or synchronize.
     * This method needs
     * @param address
     * @param newEntry
     * @throws DataOutrankedException if the log entry cannot be assigned to this log address as there is a data with higher rank
     * @throws ValueAdoptedException if the new message is a proposal during the two phase recovery write and there is an existing
     * data at this log address already.
     * @throw OverwriteException if the new data is with rank 0 (not from recovery write). This can happen only if there is a bug in the client implementation.
     */
default default void assertAppendPermittedUnsafe(long address, LogData newEntry) throws DataOutrankedException, ValueAdoptedException {
    LogData oldEntry = read(address);
    if (oldEntry.getType() == DataType.EMPTY) {
        return;
    }
    if (newEntry.getRank().getRank() == 0) {
        // data consistency in danger
        throw new OverwriteException();
    }
    int compare = newEntry.getRank().compareTo(oldEntry.getRank());
    if (compare < 0) {
        throw new DataOutrankedException();
    }
    if (compare > 0) {
        if (newEntry.getType() == DataType.RANK_ONLY && oldEntry.getType() != DataType.RANK_ONLY) {
            // the new data is a proposal, the other data is not, so the old value should be adopted
            ReadResponse resp = new ReadResponse();
            resp.put(address, oldEntry);
            throw new ValueAdoptedException(resp);
        } else {
            return;
        }
    }
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ReadResponse(org.corfudb.protocols.wireprotocol.ReadResponse) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) OverwriteException(org.corfudb.runtime.exceptions.OverwriteException) ValueAdoptedException(org.corfudb.runtime.exceptions.ValueAdoptedException)

Aggregations

OverwriteException (org.corfudb.runtime.exceptions.OverwriteException)6 ILogData (org.corfudb.protocols.wireprotocol.ILogData)2 TrimmedException (org.corfudb.runtime.exceptions.TrimmedException)2 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 StreamCOWEntry (org.corfudb.protocols.logprotocol.StreamCOWEntry)1 IMetadata (org.corfudb.protocols.wireprotocol.IMetadata)1 LogData (org.corfudb.protocols.wireprotocol.LogData)1 ReadResponse (org.corfudb.protocols.wireprotocol.ReadResponse)1 DataOutrankedException (org.corfudb.runtime.exceptions.DataOutrankedException)1 LogUnitException (org.corfudb.runtime.exceptions.LogUnitException)1 QuorumUnreachableException (org.corfudb.runtime.exceptions.QuorumUnreachableException)1 RecoveryException (org.corfudb.runtime.exceptions.RecoveryException)1 ValueAdoptedException (org.corfudb.runtime.exceptions.ValueAdoptedException)1 QuorumFuturesFactory (org.corfudb.runtime.view.QuorumFuturesFactory)1