use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class LayoutServer method handleMessageLayoutPropose.
/**
* Accepts a proposal for which it had accepted in the prepare phase.
* A minor optimization is to reject any duplicate propose messages.
* @param msg
* @param ctx
* @param r
*/
@ServerHandler(type = CorfuMsgType.LAYOUT_PROPOSE, opTimer = metricsPrefix + "propose")
public synchronized void handleMessageLayoutPropose(CorfuPayloadMsg<LayoutProposeRequest> msg, ChannelHandlerContext ctx, IServerRouter r, boolean isMetricsEnabled) {
// Check if the propose is for the correct epoch
if (!checkBootstrap(msg, ctx, r)) {
return;
}
Rank proposeRank = new Rank(msg.getPayload().getRank(), msg.getClientID());
Layout proposeLayout = msg.getPayload().getLayout();
Rank phase1Rank = getPhase1Rank();
Rank phase2Rank = getPhase2Rank();
long serverEpoch = getServerEpoch();
if (msg.getPayload().getEpoch() != serverEpoch) {
r.sendResponse(ctx, msg, new CorfuPayloadMsg<>(CorfuMsgType.WRONG_EPOCH, serverEpoch));
log.trace("Incoming message with wrong epoch, got {}, expected {}, message was: {}", msg.getPayload().getEpoch(), serverEpoch, msg);
return;
}
// This is a propose. If no prepare, reject.
if (phase1Rank == null) {
log.debug("Rejected phase 2 propose of rank={}, phase1Rank=none", proposeRank);
r.sendResponse(ctx, msg, CorfuMsgType.LAYOUT_PROPOSE_REJECT.payloadMsg(new LayoutProposeResponse(-1)));
return;
}
// This is a propose. If the rank is less than or equal to the phase 1 rank, reject.
if (!proposeRank.equals(phase1Rank)) {
log.debug("Rejected phase 2 propose of rank={}, phase1Rank={}", proposeRank, phase1Rank);
r.sendResponse(ctx, msg, CorfuMsgType.LAYOUT_PROPOSE_REJECT.payloadMsg(new LayoutProposeResponse(phase1Rank.getRank())));
return;
}
// This can happen in case of duplicate messages.
if (phase2Rank != null && proposeRank.equals(phase2Rank)) {
log.debug("Rejected phase 2 propose of rank={}, phase2Rank={}", proposeRank, phase2Rank);
r.sendResponse(ctx, msg, CorfuMsgType.LAYOUT_PROPOSE_REJECT.payloadMsg(new LayoutProposeResponse(phase2Rank.getRank())));
return;
}
log.debug("New phase 2 rank={}, layout={}", proposeRank, proposeLayout);
setPhase2Data(new Phase2Data(proposeRank, proposeLayout));
r.sendResponse(ctx, msg, new CorfuMsg(CorfuMsgType.ACK));
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class LayoutServer method getSingleNodeLayout.
private void getSingleNodeLayout() {
String localAddress = opts.get("--address") + ":" + opts.get("<port>");
setCurrentLayout(new Layout(Collections.singletonList(localAddress), Collections.singletonList(localAddress), Collections.singletonList(new LayoutSegment(Layout.ReplicationMode.CHAIN_REPLICATION, 0L, -1L, Collections.singletonList(new Layout.LayoutStripe(Collections.singletonList(localAddress))))), 0L));
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class BackpointerStreamViewTest method testGetHasNext.
/**
* Tests the hasNext functionality of the streamView.
*/
@Test
public void testGetHasNext() {
addServer(SERVERS.PORT_0);
Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
bootstrapAllServers(layout);
CorfuRuntime runtime = getRuntime(layout).connect();
IStreamView sv = runtime.getStreamsView().get(CorfuRuntime.getStreamID("streamA"));
sv.append("hello world".getBytes());
assertThat(sv.hasNext()).isTrue();
sv.next();
assertThat(sv.hasNext()).isFalse();
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class QCLayout method getLayout.
private static Layout getLayout(Map<String, Object> opts) {
Layout oLayout = null;
if ((Boolean) opts.getOrDefault("--single", false)) {
String localAddress = (String) opts.get("<address>:<port>");
log.info("Single-node mode requested, initializing layout with single log unit and sequencer at {}.", localAddress);
oLayout = new Layout(Collections.singletonList(localAddress), Collections.singletonList(localAddress), Collections.singletonList(new Layout.LayoutSegment(Layout.ReplicationMode.CHAIN_REPLICATION, 0L, -1L, Collections.singletonList(new Layout.LayoutStripe(Collections.singletonList(localAddress))))), 0L);
} else if (opts.get("--layout-file") != null) {
try {
String f = (String) opts.get("--layout-file");
String layoutJson = new String(Files.readAllBytes(Paths.get((String) opts.get("--layout-file"))));
Gson g = new GsonBuilder().create();
oLayout = g.fromJson(layoutJson, Layout.class);
} catch (Exception e) {
throw new RuntimeException("Failed to read from file (not a JSON file?)", e);
}
}
if (oLayout == null) {
log.trace("Reading layout from stdin.");
try {
String s = new String(ByteStreams.toByteArray(System.in));
Gson g = new GsonBuilder().create();
oLayout = g.fromJson(s, Layout.class);
} catch (Exception e) {
throw new RuntimeException("Failed to read from stdin (not valid JSON?)", e);
}
}
log.debug("Parsed layout to {}", oLayout);
return oLayout;
}
Aggregations