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