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;
}
}
}
Aggregations