Search in sources :

Example 36 with Layout

use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.

the class LayoutMsg method fromBuffer.

/**
     * Parse the rest of the message from the buffer. Classes that extend CorfuMsg
     * should parse their fields in this method.
     *
     * @param buffer
     */
@Override
public void fromBuffer(ByteBuf buffer) {
    super.fromBuffer(buffer);
    int length = buffer.readInt();
    byte[] byteArray = new byte[length];
    buffer.readBytes(byteArray, 0, length);
    String str = new String(byteArray, StandardCharsets.UTF_8);
    layout = parser.fromJson(str, Layout.class);
}
Also used : Layout(org.corfudb.runtime.view.Layout) ToString(lombok.ToString)

Example 37 with Layout

use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.

the class ManagementServer method getCorfuRuntime.

/**
     * Returns a connected instance of the CorfuRuntime.
     *
     * @return A connected instance of runtime.
     */
public synchronized CorfuRuntime getCorfuRuntime() {
    if (corfuRuntime == null) {
        corfuRuntime = new CorfuRuntime();
        if ((Boolean) opts.get("--enable-tls")) {
            corfuRuntime.enableTls((String) opts.get("--keystore"), (String) opts.get("--keystore-password-file"), (String) opts.get("--truststore"), (String) opts.get("--truststore-password-file"));
            if ((Boolean) opts.get("--enable-sasl-plain-text-auth")) {
                corfuRuntime.enableSaslPlainText((String) opts.get("--sasl-plain-text-username-file"), (String) opts.get("--sasl-plain-text-password-file"));
            }
        }
        // Runtime can be set up either using the layout or the bootstrapEndpoint address.
        if (latestLayout != null)
            latestLayout.getLayoutServers().forEach(ls -> corfuRuntime.addLayoutServer(ls));
        else
            corfuRuntime.addLayoutServer(bootstrapEndpoint);
        corfuRuntime.connect();
        log.info("Corfu Runtime connected successfully");
    }
    return corfuRuntime;
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) CorfuPayloadMsg(org.corfudb.protocols.wireprotocol.CorfuPayloadMsg) Getter(lombok.Getter) FailureDetectorMsg(org.corfudb.protocols.wireprotocol.FailureDetectorMsg) MethodHandles(java.lang.invoke.MethodHandles) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CorfuMsgType(org.corfudb.protocols.wireprotocol.CorfuMsgType) Executors(java.util.concurrent.Executors) Layout(org.corfudb.runtime.view.Layout) TimeUnit(java.util.concurrent.TimeUnit) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Slf4j(lombok.extern.slf4j.Slf4j) NodeMetrics(org.corfudb.format.Types.NodeMetrics) Future(java.util.concurrent.Future) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CorfuMsg(org.corfudb.protocols.wireprotocol.CorfuMsg) ManagementClient(org.corfudb.runtime.clients.ManagementClient) Map(java.util.Map) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Collections(java.util.Collections) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 38 with Layout

use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.

the class PurgeFailurePolicy method generateLayout.

/**
     * Modifies the layout by removing/purging the set failed nodes.
     *
     * @param originalLayout Original Layout which needs to be modified.
     * @param corfuRuntime   Connected runtime to attach to the new layout.
     * @param failedNodes    Set of all failed/defected servers.
     * @return The new and modified layout.
     * @throws LayoutModificationException Thrown if attempt to create an invalid layout.
     * @throws CloneNotSupportedException  Clone not supported for layout.
     */
@Override
public Layout generateLayout(Layout originalLayout, CorfuRuntime corfuRuntime, Set<String> failedNodes) throws LayoutModificationException, CloneNotSupportedException {
    LayoutWorkflowManager layoutManager = new LayoutWorkflowManager(originalLayout);
    Layout newLayout = layoutManager.removeLayoutServers(failedNodes).removeSequencerServers(failedNodes).removeLogunitServers(failedNodes).build();
    newLayout.setRuntime(corfuRuntime);
    newLayout.setEpoch(newLayout.getEpoch() + 1);
    return newLayout;
}
Also used : Layout(org.corfudb.runtime.view.Layout)

Example 39 with Layout

use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.

the class ConservativeFailureHandlerPolicy method generateLayout.

/**
     * Modifies the layout by marking the failed nodes as unresponsive but still keeping them in
     * the layout.
     *
     * @param originalLayout Original Layout which needs to be modified.
     * @param corfuRuntime   Connected runtime to attach to the new layout.
     * @param failedNodes    Set of all failed/defected servers.
     * @return The new and modified layout.
     * @throws LayoutModificationException Thrown if attempt to create an invalid layout.
     * @throws CloneNotSupportedException  Clone not supported for layout.
     */
@Override
public Layout generateLayout(Layout originalLayout, CorfuRuntime corfuRuntime, Set<String> failedNodes) throws LayoutModificationException, CloneNotSupportedException {
    LayoutWorkflowManager layoutManager = new LayoutWorkflowManager(originalLayout);
    Layout newLayout = layoutManager.moveResponsiveSequencerToTop(failedNodes).addUnresponsiveServers(failedNodes).build();
    newLayout.setRuntime(corfuRuntime);
    newLayout.setEpoch(newLayout.getEpoch() + 1);
    return newLayout;
}
Also used : Layout(org.corfudb.runtime.view.Layout)

Example 40 with Layout

use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.

the class LayoutServer method handleMessageLayoutCommit.

/**
     * Accepts any committed layouts for the current epoch or newer epochs.
     * As part of the accept, the server changes it's current layout and epoch.
     * @param msg
     * @param ctx
     * @param r
     */
// TODO If a server does not get SET_EPOCH layout commit message cannot reach it
// TODO as this message is not set to ignore EPOCH.
// TODO How do we handle holes in history if let in layout commit message. Maybe we have a hole filling process
// TODO how do reject the older epoch commits, should it be an explicit NACK.
@ServerHandler(type = CorfuMsgType.LAYOUT_COMMITTED, opTimer = metricsPrefix + "committed")
public synchronized void handleMessageLayoutCommit(CorfuPayloadMsg<LayoutCommittedRequest> msg, ChannelHandlerContext ctx, IServerRouter r, boolean isMetricsEnabled) {
    Layout commitLayout = msg.getPayload().getLayout();
    if (!checkBootstrap(msg, ctx, r)) {
        return;
    }
    long serverEpoch = getServerEpoch();
    if (msg.getPayload().getEpoch() < serverEpoch) {
        r.sendResponse(ctx, msg, new CorfuPayloadMsg<>(CorfuMsgType.WRONG_EPOCH, serverEpoch));
        return;
    }
    setCurrentLayout(commitLayout);
    setServerEpoch(msg.getPayload().getEpoch());
    r.sendResponse(ctx, msg, new CorfuMsg(CorfuMsgType.ACK));
}
Also used : Layout(org.corfudb.runtime.view.Layout)

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