Search in sources :

Example 1 with LogUnitServer

use of org.corfudb.infrastructure.LogUnitServer 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 2 with LogUnitServer

use of org.corfudb.infrastructure.LogUnitServer in project CorfuDB by CorfuDB.

the class QuorumReplicationProtocolAdditionalTests method checkReadOnEmptyPosition.

@Test
@SuppressWarnings("unchecked")
public void checkReadOnEmptyPosition() throws Exception {
    //configure the layout accordingly
    CorfuRuntime r = getDefaultRuntime();
    LogUnitServer u0 = getLogUnit(SERVERS.PORT_0);
    UUID streamA = CorfuRuntime.getStreamID("stream A");
    byte[] testPayload = "hello world".getBytes();
    //generate a stream hole
    TokenResponse tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
    IStreamView sv = r.getStreamsView().get(streamA);
    sv.append(testPayload);
    tr = r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
    //make sure we can still read the stream.
    assertThat(sv.next().getPayload(getRuntime())).isEqualTo(testPayload);
    int address = 0;
    assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.HOLE);
    assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.DATA);
    assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.HOLE);
//      TODO(mwei) - fix me
//      assertThat(r.getAddressSpaceView().read(address++).getType()).isEqualTo(DataType.EMPTY);
}
Also used : TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 3 with LogUnitServer

use of org.corfudb.infrastructure.LogUnitServer in project CorfuDB by CorfuDB.

the class LogUnitClientTest method getServersForTest.

@Override
Set<AbstractServer> getServersForTest() {
    dirPath = PARAMETERS.TEST_TEMP_DIR;
    serverContext = new ServerContextBuilder().setInitialToken(0).setSingle(false).setNoVerify(false).setMemory(false).setLogPath(dirPath).setServerRouter(serverRouter).build();
    server = new LogUnitServer(serverContext);
    return new ImmutableSet.Builder<AbstractServer>().add(server).build();
}
Also used : ServerContextBuilder(org.corfudb.infrastructure.ServerContextBuilder) ServerContextBuilder(org.corfudb.infrastructure.ServerContextBuilder) LogUnitServer(org.corfudb.infrastructure.LogUnitServer)

Example 4 with LogUnitServer

use of org.corfudb.infrastructure.LogUnitServer in project CorfuDB by CorfuDB.

the class LogUnitClientTest method readingTrimmedAddress.

@Test
public void readingTrimmedAddress() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
    client.write(1, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
    LogData r = client.read(0).get().getReadSet().get(0L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    r = client.read(1).get().getReadSet().get(1L);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
    client.prefixTrim(0);
    client.compact();
    // For logunit cach flush
    LogUnitServer server2 = new LogUnitServer(serverContext);
    serverRouter.reset();
    serverRouter.addServer(server2);
    assertThatThrownBy(() -> client.read(0).get().getReadSet().get(0L)).isInstanceOf(ExecutionException.class).hasCauseInstanceOf(TrimmedException.class);
    assertThat(r.getType()).isEqualTo(DataType.DATA);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with LogUnitServer

use of org.corfudb.infrastructure.LogUnitServer in project CorfuDB by CorfuDB.

the class LogUnitClientTest method CorruptedDataReadThrowsException.

@Test
public void CorruptedDataReadThrowsException() throws Exception {
    byte[] testString = "hello world".getBytes();
    client.write(0, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
    client.write(StreamLogFiles.RECORDS_PER_LOG_FILE + 1, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
    // Corrupt the written log entry
    String logDir = serverContext.getServerConfig().get("--log-path") + File.separator + "log";
    String logFilePath = logDir + File.separator + "0.log";
    RandomAccessFile file = new RandomAccessFile(logFilePath, "rw");
    ByteBuffer metaDataBuf = ByteBuffer.allocate(METADATA_SIZE);
    file.getChannel().read(metaDataBuf);
    metaDataBuf.flip();
    Types.Metadata metadata = Types.Metadata.parseFrom(metaDataBuf.array());
    final int fileOffset = Integer.BYTES + METADATA_SIZE + metadata.getLength() + 20;
    final int CORRUPT_BYTES = 0xFFFF;
    // File header + delimiter
    file.seek(fileOffset);
    file.writeInt(CORRUPT_BYTES);
    file.close();
    LogUnitServer server2 = new LogUnitServer(serverContext);
    serverRouter.reset();
    serverRouter.addServer(server2);
    // Try to read a corrupted log entry
    assertThatThrownBy(() -> client.read(0).get()).isInstanceOf(ExecutionException.class).hasCauseInstanceOf(DataCorruptionException.class);
}
Also used : Types(org.corfudb.format.Types) RandomAccessFile(java.io.RandomAccessFile) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

LogUnitServer (org.corfudb.infrastructure.LogUnitServer)7 Test (org.junit.Test)5 UUID (java.util.UUID)4 ILogData (org.corfudb.protocols.wireprotocol.ILogData)3 LogData (org.corfudb.protocols.wireprotocol.LogData)3 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)3 ExecutionException (java.util.concurrent.ExecutionException)2 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)2 ByteBuf (io.netty.buffer.ByteBuf)1 RandomAccessFile (java.io.RandomAccessFile)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ByteBuffer (java.nio.ByteBuffer)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExceptionUtils (org.codehaus.plexus.util.ExceptionUtils)1 Types (org.corfudb.format.Types)1 CorfuServer (org.corfudb.infrastructure.CorfuServer)1