Search in sources :

Example 26 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class LogUnitClientTest method canReadWriteRanked.

@Test
public void canReadWriteRanked() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(1), testString, Collections.emptyMap()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
    byte[] testString2 = "hello world 2".getBytes();
    client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(2), testString2, Collections.emptyMap()).get();
    r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString2);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 27 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class LogUnitClientTest method flushLogunitCache.

@Test
public void flushLogunitCache() throws Exception {
    LogUnitServer server2 = new LogUnitServer(serverContext);
    serverRouter.reset();
    serverRouter.addServer(server2);
    assertThat(server2.getDataCache().asMap().size()).isEqualTo(0);
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
    assertThat(server2.getDataCache().asMap().size()).isEqualTo(1);
    client.flushCache();
    assertThat(server2.getDataCache().asMap().size()).isEqualTo(0);
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(server2.getDataCache().asMap().size()).isEqualTo(1);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class QuorumReplicationProtocol method getAdoptedValueWithHighestRankIfPresent.

private ReadResponse getAdoptedValueWithHighestRankIfPresent(Long position, Set<Throwable> throwables) {
    ReadResponse result = null;
    IMetadata.DataRank maxRank = null;
    for (Throwable t : throwables) {
        if (t instanceof ValueAdoptedException) {
            ValueAdoptedException ve = (ValueAdoptedException) t;
            ReadResponse r = ve.getReadResponse();
            LogData ld = r.getReadSet().get(position);
            if (maxRank == null || maxRank.compareTo(ld.getRank()) < 0) {
                maxRank = ld.getRank();
                result = r;
            }
        }
    }
    return result;
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) IMetadata(org.corfudb.protocols.wireprotocol.IMetadata) ReadResponse(org.corfudb.protocols.wireprotocol.ReadResponse) ValueAdoptedException(org.corfudb.runtime.exceptions.ValueAdoptedException)

Example 29 with LogData

use of org.corfudb.protocols.wireprotocol.LogData 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)

Example 30 with LogData

use of org.corfudb.protocols.wireprotocol.LogData in project CorfuDB by CorfuDB.

the class StreamLogFilesTest method testWriteReadWithChecksum.

@Test
public void testWriteReadWithChecksum() {
    // Enable checksum, then append and read the same entry
    StreamLog log = new StreamLogFiles(getContext(), false);
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = "Payload".getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    long address0 = 0;
    log.append(address0, new LogData(DataType.DATA, b));
    assertThat(log.read(address0).getPayload(null)).isEqualTo(streamEntry);
    // Disable checksum, then append and read then same entry
    // An overwrite exception should occur, since we are writing the
    // same entry.
    final StreamLog newLog = new StreamLogFiles(getContext(), true);
    assertThatThrownBy(() -> {
        newLog.append(address0, new LogData(DataType.DATA, b));
    }).isInstanceOf(OverwriteException.class);
    assertThat(log.read(address0).getPayload(null)).isEqualTo(streamEntry);
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Aggregations

LogData (org.corfudb.protocols.wireprotocol.LogData)45 Test (org.junit.Test)32 ILogData (org.corfudb.protocols.wireprotocol.ILogData)21 AbstractCorfuTest (org.corfudb.AbstractCorfuTest)18 ByteBuf (io.netty.buffer.ByteBuf)15 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)9 UUID (java.util.UUID)8 DataOutrankedException (org.corfudb.runtime.exceptions.DataOutrankedException)8 ExecutionException (java.util.concurrent.ExecutionException)5 ReadResponse (org.corfudb.protocols.wireprotocol.ReadResponse)5 IMetadata (org.corfudb.protocols.wireprotocol.IMetadata)4 ValueAdoptedException (org.corfudb.runtime.exceptions.ValueAdoptedException)4 Layout (org.corfudb.runtime.view.Layout)4 LogUnitServer (org.corfudb.infrastructure.LogUnitServer)3 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)3 File (java.io.File)2 LogUnitClient (org.corfudb.runtime.clients.LogUnitClient)2 OverwriteException (org.corfudb.runtime.exceptions.OverwriteException)2 QuorumUnreachableException (org.corfudb.runtime.exceptions.QuorumUnreachableException)2 QuorumFuturesFactory (org.corfudb.runtime.view.QuorumFuturesFactory)2