Search in sources :

Example 41 with Layout

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));
}
Also used : Layout(org.corfudb.runtime.view.Layout)

Example 42 with Layout

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));
}
Also used : Layout(org.corfudb.runtime.view.Layout) LayoutSegment(org.corfudb.runtime.view.Layout.LayoutSegment)

Example 43 with Layout

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();
}
Also used : Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 44 with Layout

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;
}
Also used : Layout(org.corfudb.runtime.view.Layout) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) OutrankedException(org.corfudb.runtime.exceptions.OutrankedException) ExecutionException(java.util.concurrent.ExecutionException) WrongEpochException(org.corfudb.runtime.exceptions.WrongEpochException)

Aggregations

Layout (org.corfudb.runtime.view.Layout)44 Test (org.junit.Test)29 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)10 ILogData (org.corfudb.protocols.wireprotocol.ILogData)5 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)5 LogData (org.corfudb.protocols.wireprotocol.LogData)4 HashSet (java.util.HashSet)3 ExecutionException (java.util.concurrent.ExecutionException)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ArrayList (java.util.ArrayList)2 FailureDetectorMsg (org.corfudb.protocols.wireprotocol.FailureDetectorMsg)2 LayoutMsg (org.corfudb.protocols.wireprotocol.LayoutMsg)2 OutrankedException (org.corfudb.runtime.exceptions.OutrankedException)2 com.google.common.collect (com.google.common.collect)1 TypeToken (com.google.common.reflect.TypeToken)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 java.lang.invoke (java.lang.invoke)1