Search in sources :

Example 1 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class ReplaySequencer method poll.

// Return the next correctly sequenced message or null if none exists.
public VoltMessage poll() {
    if (m_mustDrain || m_replayEntries.isEmpty()) {
        return null;
    }
    if (m_replayEntries.firstEntry().getValue().isEmpty()) {
        m_replayEntries.pollFirstEntry();
    }
    // All the drain conditions depend on being blocked, which
    // we will only really know for sure when we try to poll().
    checkDrainCondition();
    if (m_mustDrain || m_replayEntries.isEmpty()) {
        return null;
    }
    VoltMessage m = m_replayEntries.firstEntry().getValue().poll();
    updateLastPolledUniqueId(m_replayEntries.firstEntry().getKey(), (TransactionInfoBaseMessage) m);
    return m;
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage)

Example 2 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class TestRepairLog method testTruncationAfterPromotion.

@Test
public void testTruncationAfterPromotion() {
    final AtomicLong lastCommitted = new AtomicLong(Long.MIN_VALUE);
    final TransactionCommitInterest interest = lastCommitted::set;
    RepairLog rl = new RepairLog();
    rl.registerTransactionCommitInterest(interest);
    VoltMessage m1 = truncInitMsg(0L, 1L);
    rl.deliver(m1);
    VoltMessage m2 = truncInitMsg(0L, 2L);
    rl.deliver(m2);
    assertEquals(3, rl.contents(1L, false).size());
    rl.setLeaderState(true);
    assertEquals(1, rl.contents(1L, false).size());
    assertEquals(2, lastCommitted.get());
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.Test)

Example 3 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class TestRepairLog method testOfferUneededMessage.

@Test
public void testOfferUneededMessage() {
    RepairLog rl = new RepairLog();
    VoltMessage m1 = truncInitMsg(0L, 1L);
    rl.deliver(m1);
    // deliver a non-logged message (this is the test).
    rl.deliver(new FooMessage());
    VoltMessage m2 = truncInitMsg(0L, 2L);
    rl.deliver(m2);
    assertEquals(3, rl.contents(1L, false).size());
    assertEquals(m1, rl.contents(1L, false).get(1).getPayload());
    assertEquals(m2, rl.contents(1L, false).get(2).getPayload());
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage) Test(org.junit.Test)

Example 4 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class SnapshotDaemon method initiateSnapshotSave.

private void initiateSnapshotSave(final long handle, final Object[] params, boolean blocking) {
    boolean success = true;
    VoltTable checkResult = SnapshotUtil.constructNodeResultsTable();
    final String jsString = String.class.cast(params[0]);
    if (m_lastInitiationTs != null) {
        final long elapsedMs = System.currentTimeMillis() - m_lastInitiationTs.getFirst();
        // Blocking snapshot may take a long time to finish, don't time it out if it's blocking
        if (!m_lastInitiationTs.getSecond() && elapsedMs > INITIATION_RESPONSE_TIMEOUT_MS) {
            SNAP_LOG.warn(String.format("A snapshot was initiated %d minutes ago and hasn't received a response yet.", TimeUnit.MILLISECONDS.toMinutes(elapsedMs)));
            m_lastInitiationTs = null;
        } else {
            checkResult.addRow(CoreUtils.getHostIdFromHSId(m_mb.getHSId()), CoreUtils.getHostnameOrAddress(), null, "FAILURE", "SNAPSHOT IN PROGRESS");
            success = false;
        }
    }
    if (success) {
        try {
            final JSONObject jsObj = new JSONObject(jsString);
            boolean initiateSnapshot;
            // Do scan work on all known live hosts
            VoltMessage msg = new SnapshotCheckRequestMessage(jsString);
            SnapshotPathType pathType = SnapshotPathType.valueOf(jsObj.getString(SnapshotUtil.JSON_PATH_TYPE));
            Set<Integer> liveHosts = VoltDB.instance().getHostMessenger().getLiveHostIds();
            for (int hostId : liveHosts) {
                m_mb.send(CoreUtils.getHSIdFromHostAndSite(hostId, HostMessenger.SNAPSHOT_IO_AGENT_ID), msg);
            }
            // Wait for responses from all hosts for a certain amount of time
            Map<Integer, VoltTable> responses = Maps.newHashMap();
            // 10s timeout
            final long timeoutMs = 10 * 1000;
            final long endTime = System.currentTimeMillis() + timeoutMs;
            SnapshotCheckResponseMessage response;
            while ((response = (SnapshotCheckResponseMessage) m_mb.recvBlocking(timeoutMs)) != null) {
                final String nonce = jsObj.getString(SnapshotUtil.JSON_NONCE);
                boolean nonceFound = false;
                if (pathType == SnapshotPathType.SNAP_PATH) {
                    // If request was explicitely PATH check path too.
                    if (nonce.equals(response.getNonce()) && response.getPath().equals(jsObj.getString(SnapshotUtil.JSON_PATH))) {
                        nonceFound = true;
                    }
                } else {
                    // If request is with type other than path just check type.
                    if (nonce.equals(response.getNonce()) && response.getSnapshotPathType() == pathType) {
                        nonceFound = true;
                    }
                }
                if (nonceFound) {
                    responses.put(CoreUtils.getHostIdFromHSId(response.m_sourceHSId), response.getResponse());
                }
                if (responses.size() == liveHosts.size() || System.currentTimeMillis() > endTime) {
                    break;
                }
            }
            if (responses.size() != liveHosts.size()) {
                checkResult.addRow(CoreUtils.getHostIdFromHSId(m_mb.getHSId()), CoreUtils.getHostnameOrAddress(), null, "FAILURE", "TIMED OUT CHECKING SNAPSHOT FEASIBILITY");
                success = false;
            }
            if (success) {
                // TRAIL [TruncSnap:12] all participating nodes have initiated successfully
                // Call @SnapshotSave if check passed, return the failure otherwise
                checkResult = VoltTableUtil.unionTables(responses.values());
                initiateSnapshot = SnapshotUtil.didSnapshotRequestSucceed(new VoltTable[] { checkResult });
                if (initiateSnapshot) {
                    m_lastInitiationTs = Pair.of(System.currentTimeMillis(), blocking);
                    m_initiator.initiateSnapshotDaemonWork("@SnapshotSave", handle, params);
                } else {
                    success = false;
                }
            }
        } catch (JSONException e) {
            success = false;
            checkResult.addRow(CoreUtils.getHostIdFromHSId(m_mb.getHSId()), CoreUtils.getHostnameOrAddress(), null, "FAILURE", "ERROR PARSING JSON");
            SNAP_LOG.warn("Error parsing JSON string: " + jsString, e);
        }
    }
    if (!success) {
        final ClientResponseImpl failureResponse = new ClientResponseImpl(ClientResponseImpl.SUCCESS, new VoltTable[] { checkResult }, null);
        failureResponse.setClientHandle(handle);
        processClientResponse(Callables.returning(failureResponse));
    }
}
Also used : JSONException(org.json_voltpatches.JSONException) SnapshotCheckRequestMessage(org.voltdb.messaging.SnapshotCheckRequestMessage) SnapshotPathType(org.voltdb.sysprocs.saverestore.SnapshotPathType) VoltMessage(org.voltcore.messaging.VoltMessage) SnapshotCheckResponseMessage(org.voltdb.messaging.SnapshotCheckResponseMessage) JSONObject(org.json_voltpatches.JSONObject)

Example 5 with VoltMessage

use of org.voltcore.messaging.VoltMessage in project voltdb by VoltDB.

the class MpPromoteAlgo method prepareForFaultRecovery.

/** Start fixing survivors: setup scoreboard and request repair logs. */
void prepareForFaultRecovery() {
    for (Long hsid : m_survivors) {
        m_replicaRepairStructs.put(hsid, new ReplicaRepairStruct());
    }
    m_replicaRepairStructs.put(m_mailbox.getHSId(), new ReplicaRepairStruct());
    tmLog.info(m_whoami + "found " + m_survivors.size() + " surviving leaders to repair. " + " Survivors: " + CoreUtils.hsIdCollectionToString(m_survivors));
    VoltMessage logRequest = makeRepairLogRequestMessage(m_requestId);
    m_mailbox.send(com.google_voltpatches.common.primitives.Longs.toArray(m_survivors), logRequest);
    m_mailbox.send(m_mailbox.getHSId(), logRequest);
}
Also used : VoltMessage(org.voltcore.messaging.VoltMessage)

Aggregations

VoltMessage (org.voltcore.messaging.VoltMessage)31 Test (org.junit.Test)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 FaultMessage (org.voltcore.messaging.FaultMessage)4 SiteFailureMessage (org.voltcore.messaging.SiteFailureMessage)4 Subject (org.voltcore.messaging.Subject)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Iv2RepairLogResponseMessage (org.voltdb.messaging.Iv2RepairLogResponseMessage)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Message (org.voltcore.agreement.FakeMesh.Message)2 SiteFailureForwardMessage (org.voltcore.messaging.SiteFailureForwardMessage)2 InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)2 LocalMailbox (org.voltdb.messaging.LocalMailbox)2 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)1 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)1 List (java.util.List)1