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