use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class LayoutServerTest method commitReturnsAck.
private void commitReturnsAck(LayoutServer s1, Integer reboot, long baseEpoch) {
long newEpoch = baseEpoch + reboot;
sendMessage(new CorfuPayloadMsg<>(CorfuMsgType.SET_EPOCH, newEpoch));
Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
layout.setEpoch(newEpoch);
sendPrepare(newEpoch, HIGH_RANK);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_ACK);
sendPropose(newEpoch, HIGH_RANK, layout);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.ACK);
sendCommitted(newEpoch, layout);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.ACK);
sendCommitted(newEpoch, layout);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.ACK);
requestLayout(newEpoch);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_RESPONSE);
Assertions.assertThat(((LayoutMsg) getLastMessage()).getLayout()).isEqualTo(layout);
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class LayoutServerTest method checkPaxosPhasesPersisted.
/**
* The test verifies that the data in accepted phase1 and phase2 messages
* is persisted to disk and survives layout server restarts.
*
* @throws Exception
*/
@Test
public void checkPaxosPhasesPersisted() throws Exception {
String serviceDir = PARAMETERS.TEST_TEMP_DIR;
LayoutServer s1 = getDefaultServer(serviceDir);
Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
bootstrapServer(layout);
long newEpoch = layout.getEpoch() + 1;
Layout newLayout = TestLayoutBuilder.single(SERVERS.PORT_0);
newLayout.setEpoch(newEpoch);
setEpoch(newEpoch);
// validate phase 1
sendPrepare(newEpoch, 1);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_ACK);
assertThat(s1).isPhase1Rank(new Rank(1L, AbstractServerTest.testClientId));
//shutdown this instance of server
s1.shutdown();
//bring up a new instance of server with the previously persisted data
LayoutServer s2 = getDefaultServer(serviceDir);
assertThat(s2).isInEpoch(newEpoch);
assertThat(s2).isPhase1Rank(new Rank(1L, AbstractServerTest.testClientId));
// validate phase2 data persistence
sendPropose(newEpoch, 1, newLayout);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.ACK);
//shutdown this instance of server
s2.shutdown();
//bring up a new instance of server with the previously persisted data
LayoutServer s3 = getDefaultServer(serviceDir);
assertThat(s3).isInEpoch(newEpoch);
assertThat(s3).isPhase1Rank(new Rank(1L, AbstractServerTest.testClientId));
assertThat(s3).isPhase2Rank(new Rank(1L, AbstractServerTest.testClientId));
assertThat(s3).isProposedLayout(newLayout);
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class LayoutServerTest method checkMessagesValidatedAgainstPhase1PersistedData.
/**
* Validates that the layout server accept or rejects incoming phase1 messages based on
* the last persisted phase1 rank.
*
* @throws Exception
*/
@Test
public void checkMessagesValidatedAgainstPhase1PersistedData() throws Exception {
String serviceDir = PARAMETERS.TEST_TEMP_DIR;
LayoutServer s1 = getDefaultServer(serviceDir);
Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
bootstrapServer(layout);
long newEpoch = layout.getEpoch() + 1;
Layout newLayout = TestLayoutBuilder.single(SERVERS.PORT_0);
newLayout.setEpoch(newEpoch);
setEpoch(newEpoch);
// validate phase 1
sendPrepare(newEpoch, HIGH_RANK);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_ACK);
assertThat(s1).isInEpoch(newEpoch);
assertThat(s1).isPhase1Rank(new Rank(HIGH_RANK, AbstractServerTest.testClientId));
s1.shutdown();
// reboot
LayoutServer s2 = getDefaultServer(serviceDir);
assertThat(s2).isInEpoch(newEpoch);
assertThat(s2).isPhase1Rank(new Rank(HIGH_RANK, AbstractServerTest.testClientId));
//new LAYOUT_PREPARE message with a lower phase1 rank should be rejected
sendPrepare(newEpoch, HIGH_RANK - 1);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_REJECT);
//new LAYOUT_PREPARE message with a higher phase1 rank should be accepted
sendPrepare(newEpoch, HIGH_RANK + 1);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_ACK);
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class ManagementServerTest method bootstrapManagementServer.
/**
* Bootstrapping the management server multiple times.
*/
@Test
public void bootstrapManagementServer() {
Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
sendMessage(CorfuMsgType.MANAGEMENT_BOOTSTRAP_REQUEST.payloadMsg(layout));
assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.ACK);
sendMessage(CorfuMsgType.MANAGEMENT_BOOTSTRAP_REQUEST.payloadMsg(layout));
assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.MANAGEMENT_ALREADY_BOOTSTRAP_ERROR);
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class FailureHandlerDispatcherTest method updateLayoutOnFailure.
/**
* triggers the handler with failure and checks for update in layout.
*/
@Test
public void updateLayoutOnFailure() {
addServer(SERVERS.PORT_0);
addServer(SERVERS.PORT_1);
addServer(SERVERS.PORT_2);
Layout originalLayout = new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_1).addSequencer(SERVERS.PORT_2).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
bootstrapAllServers(originalLayout);
CorfuRuntime corfuRuntime = new CorfuRuntime();
corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_0));
corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_1));
corfuRuntime.addLayoutServer(getEndpoint(SERVERS.PORT_2));
corfuRuntime.connect();
Set<String> failedServers = new HashSet<>();
failedServers.add(getEndpoint(SERVERS.PORT_2));
FailureHandlerDispatcher failureHandlerDispatcher = new FailureHandlerDispatcher();
IFailureHandlerPolicy failureHandlerPolicy = new PurgeFailurePolicy();
failureHandlerDispatcher.dispatchHandler(failureHandlerPolicy, originalLayout, corfuRuntime, failedServers);
Layout expectedLayout = new TestLayoutBuilder().setEpoch(2L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_1).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addToSegment().addToLayout().build();
assertThat(getLayoutServer(SERVERS.PORT_0).getCurrentLayout()).isEqualTo(getLayoutServer(SERVERS.PORT_1).getCurrentLayout()).isEqualTo(expectedLayout);
}
Aggregations