Search in sources :

Example 11 with LogData

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

the class QuorumReplicationProtocolAdditionalTests method checkRecoveryWriteTriggeredFromReadRecoversDataWhenTheQuorumIsLost.

@Test
@SuppressWarnings("unchecked")
public void checkRecoveryWriteTriggeredFromReadRecoversDataWhenTheQuorumIsLost() throws Exception {
    //configure the layout accordingly
    CorfuRuntime r = getDefaultRuntime();
    LogUnitServer u0 = getLogUnit(SERVERS.PORT_0);
    LogUnitServer u1 = getLogUnit(SERVERS.PORT_1);
    LogUnitServer u2 = getLogUnit(SERVERS.PORT_2);
    final long ADDRESS_0 = 0L;
    //write at 0
    ByteBuf b = Unpooled.buffer();
    Serializers.CORFU.serialize("0".getBytes(), b);
    WriteRequest m = WriteRequest.builder().writeMode(WriteMode.NORMAL).data(new LogData(DataType.DATA, b)).build();
    m.setGlobalAddress(ADDRESS_0);
    m.setRank(new IMetadata.DataRank(0));
    m.setBackpointerMap(Collections.emptyMap());
    sendMessage(u1, CorfuMsgType.WRITE.payloadMsg(m));
    sendMessage(u2, CorfuMsgType.WRITE.payloadMsg(m));
    u2.setShutdown(true);
    u2.shutdown();
    LogUnitServerAssertions.assertThat(u0).isEmptyAtAddress(ADDRESS_0);
    assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).isEqualTo("0".getBytes());
    LogUnitServerAssertions.assertThat(u1).matchesDataAtAddress(ADDRESS_0, "0".getBytes());
    LogUnitServerAssertions.assertThat(u0).matchesDataAtAddress(ADDRESS_0, "0".getBytes());
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) IMetadata(org.corfudb.protocols.wireprotocol.IMetadata) WriteRequest(org.corfudb.protocols.wireprotocol.WriteRequest) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 12 with LogData

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

the class AbstractReplicationProtocolTest method canWriteRead.

/** Check if we can write and then read the value
     * that was written.
     */
@Test
@SuppressWarnings("unchecked")
public void canWriteRead() throws Exception {
    setupNodes();
    //begin tests
    final CorfuRuntime r = getDefaultRuntime();
    final IReplicationProtocol rp = getProtocol();
    final Layout layout = r.getLayoutView().getLayout();
    LogData data = getLogData(0, "hello world".getBytes());
    rp.write(layout, data);
    ILogData read = rp.read(layout, 0);
    assertThat(read.getType()).isEqualTo(DataType.DATA);
    assertThat(read.getGlobalAddress()).isEqualTo(0);
    assertThat(read.getPayload(r)).isEqualTo("hello world".getBytes());
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 13 with LogData

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

the class ChainReplicationProtocolTest method failedWriteCanBeRead.

/** Check to see that a read correctly
     * completes a failed write from another client.
     */
@Test
public void failedWriteCanBeRead() throws Exception {
    setupNodes();
    //begin tests
    final CorfuRuntime r = getDefaultRuntime();
    final IReplicationProtocol rp = getProtocol();
    final Layout layout = r.getLayoutView().getLayout();
    LogData incompleteWrite = getLogData(0, "incomplete".getBytes());
    // Write the incomplete write to the head of the chain
    r.getRouter(SERVERS.ENDPOINT_0).getClient(LogUnitClient.class).write(incompleteWrite);
    // At this point, a read
    // reflect the -other- clients value
    ILogData readResult = rp.read(layout, 0);
    assertThat(readResult.getPayload(r)).isEqualTo("incomplete".getBytes());
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) LogUnitClient(org.corfudb.runtime.clients.LogUnitClient) Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 14 with LogData

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

the class AddressSpaceView method write.

/** Write the given log data using a token, returning
     * either when the write has been completed successfully,
     * or throwing an OverwriteException if another value
     * has been adopted, or a WrongEpochException if the
     * token epoch is invalid.
     *
     * @param token     The token to use for the write.
     * @param data      The data to write.
     * @throws OverwriteException   If the globalAddress given
     *                              by the token has adopted
     *                              another value.
     * @throws WrongEpochException  If the token epoch is invalid.
     */
public void write(IToken token, Object data) throws OverwriteException {
    final ILogData ld = new LogData(DataType.DATA, data);
    layoutHelper(l -> {
        if (token.getEpoch() != l.getEpoch()) {
            throw new WrongEpochException(l.getEpoch());
        }
        ld.useToken(token);
        l.getReplicationMode(token.getTokenValue()).getReplicationProtocol(runtime).write(l, ld);
        return null;
    });
    // Cache the successful write
    if (!runtime.isCacheDisabled()) {
        readCache.put(token.getTokenValue(), ld);
    }
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) WrongEpochException(org.corfudb.runtime.exceptions.WrongEpochException)

Example 15 with LogData

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

the class StreamLogFiles method getLogData.

private LogData getLogData(LogEntry entry) {
    ByteBuf data = Unpooled.wrappedBuffer(entry.getData().toByteArray());
    LogData logData = new LogData(org.corfudb.protocols.wireprotocol.DataType.typeMap.get((byte) entry.getDataType().getNumber()), data);
    // Checkpoint-related metadata are set by LogData constructor.
    logData.setBackpointerMap(getUUIDLongMap(entry.getBackpointersMap()));
    logData.setGlobalAddress(entry.getGlobalAddress());
    logData.setRank(createDataRank(entry));
    return logData;
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf)

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