Search in sources :

Example 6 with LogData

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

the class StreamLogFilesTest method testStreamLogDataCorruption.

@Test
public void testStreamLogDataCorruption() throws Exception {
    // This test manipulates a log file directly and manipulates
    // log records by overwriting some parts of the record simulating
    // different data corruption scenarios
    String logDir = getContext().getServerConfig().get("--log-path") + File.separator + "log";
    StreamLog log = new StreamLogFiles(getContext(), false);
    ByteBuf b = Unpooled.buffer();
    byte[] streamEntry = "Payload".getBytes();
    Serializers.CORFU.serialize(streamEntry, b);
    // Write to two segments
    long address0 = 0;
    long address1 = StreamLogFiles.RECORDS_PER_LOG_FILE + 1L;
    log.append(address0, new LogData(DataType.DATA, b));
    log.append(address1, new LogData(DataType.DATA, b));
    assertThat(log.read(address0).getPayload(null)).isEqualTo(streamEntry);
    log.close();
    final int OVERWRITE_DELIMITER = 0xFFFF;
    final int OVERWRITE_BYTES = 4;
    // Overwrite 2 bytes of the checksum and 2 bytes of the entry's address
    String logFilePath1 = logDir + File.separator + 0 + ".log";
    String logFilePath2 = logDir + File.separator + 1 + ".log";
    RandomAccessFile file1 = new RandomAccessFile(logFilePath1, "rw");
    RandomAccessFile file2 = new RandomAccessFile(logFilePath2, "rw");
    ByteBuffer metaDataBuf = ByteBuffer.allocate(METADATA_SIZE);
    file1.getChannel().read(metaDataBuf);
    metaDataBuf.flip();
    Metadata metadata = Metadata.parseFrom(metaDataBuf.array());
    final int offset1 = METADATA_SIZE + metadata.getLength();
    final int offset2 = METADATA_SIZE + metadata.getLength() + Short.BYTES + OVERWRITE_BYTES;
    // Corrupt delimiter in the first segment
    file1.seek(offset1);
    file1.writeShort(0);
    file1.close();
    assertThatThrownBy(() -> new StreamLogFiles(getContext(), false).read(0L)).isInstanceOf(DataCorruptionException.class);
    // Corrupt metadata in the second segment
    file2.seek(offset2);
    file2.writeInt(OVERWRITE_DELIMITER);
    file2.close();
    assertThatThrownBy(() -> new StreamLogFiles(getContext(), false)).isInstanceOf(DataCorruptionException.class);
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) RandomAccessFile(java.io.RandomAccessFile) Metadata(org.corfudb.format.Types.Metadata) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 7 with LogData

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

the class StreamLogFilesTest method testStreamLogBadChecksum.

@Test
public void testStreamLogBadChecksum() {
    // This test generates a stream log file without computing checksums, then
    // tries to read from the same log file with checksum enabled. The expected
    // behaviour is to throw a DataCorruptionException because a checksum cannot
    // be computed for stream entries that haven't been written with a checksum
    StreamLog log = new StreamLogFiles(getContext(), true);
    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);
    log.close();
    // Re-open stream log with checksum enabled
    assertThatThrownBy(() -> new StreamLogFiles(getContext(), false)).isInstanceOf(RuntimeException.class);
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 8 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testCompact.

@Test
// compact on ranked address space not activated yet
@Ignore
public void testCompact() throws Exception {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    for (long x = 0; x < RECORDS_TO_WRITE; x++) {
        writeToLog(log, address, DataType.DATA, "Payload", x);
    }
    LogData value1 = log.read(address);
    long size1 = new File(log.getSegmentHandleForAddress(address).getFileName()).length();
    log.compact();
    LogData value2 = log.read(address);
    long size2 = new File(log.getSegmentHandleForAddress(address).getFileName()).length();
    assertEquals(value1.getRank(), value2.getRank());
    assertNotEquals(size2, size1);
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 9 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testProposalsLowerRank.

@Test
public void testProposalsLowerRank() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.RANK_ONLY, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.RANK_ONLY, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Example 10 with LogData

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

the class StreamLogWithRankedAddressSpaceTest method testLowerRankAgainstProposal.

@Test
public void testLowerRankAgainstProposal() {
    StreamLogFiles log = new StreamLogFiles(getContext(), false);
    long address = 0;
    writeToLog(log, address, DataType.RANK_ONLY, "v-1", 2);
    LogData value1 = log.read(address);
    assertTrue(new String(value1.getData()).contains("v-1"));
    try {
        writeToLog(log, address, DataType.DATA, "v-2", 1);
        fail();
    } catch (DataOutrankedException e) {
    // expected
    }
    LogData value2 = log.read(address);
    assertTrue(new String(value2.getData()).contains("v-1"));
    log.close();
}
Also used : LogData(org.corfudb.protocols.wireprotocol.LogData) DataOutrankedException(org.corfudb.runtime.exceptions.DataOutrankedException) 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