Search in sources :

Example 1 with Pong

use of com.yahoo.prelude.Pong in project vespa by vespa-engine.

the class FastSearcher method ping.

public static Pong ping(Ping ping, Backend backend, String name) {
    FS4Channel channel = backend.openPingChannel();
    // com.yahoo.prelude.cluster.TrafficNodeMonitor.failed(ErrorMessage)
    try {
        PingPacket pingPacket = new PingPacket();
        try {
            boolean couldSend = channel.sendPacket(pingPacket);
            if (!couldSend) {
                return new Pong(ErrorMessage.createBackendCommunicationError("Could not ping " + name));
            }
        } catch (InvalidChannelException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel " + name));
        } catch (IllegalStateException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Illegal state in FS4: " + e.getMessage()));
        } catch (IOException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("IO error while sending ping: " + e.getMessage()));
        }
        // We should only get a single packet
        BasicPacket[] packets;
        try {
            packets = channel.receivePackets(ping.getTimeout(), 1);
        } catch (ChannelTimeoutException e) {
            return new Pong(ErrorMessage.createNoAnswerWhenPingingNode("timeout while waiting for fdispatch for " + name));
        } catch (InvalidChannelException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel for " + name));
        }
        if (packets.length == 0) {
            return new Pong(ErrorMessage.createBackendCommunicationError(name + " got no packets back"));
        }
        try {
            ensureInstanceOf(PongPacket.class, packets[0], name);
        } catch (TimeoutException e) {
            return new Pong(ErrorMessage.createTimeout(e.getMessage()));
        } catch (IOException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Unexpected packet class returned after ping: " + e.getMessage()));
        }
        return new Pong((PongPacket) packets[0]);
    } finally {
        if (channel != null) {
            channel.close();
        }
    }
}
Also used : InvalidChannelException(com.yahoo.fs4.mplex.InvalidChannelException) BasicPacket(com.yahoo.fs4.BasicPacket) FS4Channel(com.yahoo.fs4.mplex.FS4Channel) PingPacket(com.yahoo.fs4.PingPacket) IOException(java.io.IOException) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) Pong(com.yahoo.prelude.Pong) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException)

Example 2 with Pong

use of com.yahoo.prelude.Pong in project vespa by vespa-engine.

the class ClusterSearcher method ping.

/**
 * Pinging a node, called from ClusterMonitor
 */
@Override
public final void ping(T p, Executor executor) {
    log(LogLevel.FINE, "Sending ping to: ", p);
    Pinger pinger = new Pinger(p);
    FutureTask<Pong> future = new FutureTask<>(pinger);
    executor.execute(future);
    Pong pong;
    Throwable logThrowable = null;
    try {
        pong = future.get(monitor.getConfiguration().getFailLimit(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        pong = new Pong(ErrorMessage.createUnspecifiedError("Ping was interrupted: " + p));
        logThrowable = e;
    } catch (ExecutionException e) {
        pong = new Pong(ErrorMessage.createUnspecifiedError("Execution was interrupted: " + p));
        logThrowable = e;
    } catch (LinkageError e) {
        // Typically Osgi woes
        pong = new Pong(ErrorMessage.createErrorInPluginSearcher("Class loading problem", e));
        logThrowable = e;
    } catch (TimeoutException e) {
        pong = new Pong(ErrorMessage.createNoAnswerWhenPingingNode("Ping thread timed out."));
    }
    future.cancel(true);
    if (pong.badResponse()) {
        monitor.failed(p, pong.getError(0));
        log(LogLevel.FINE, "Failed ping - ", pong);
    } else {
        monitor.responded(p);
        log(LogLevel.FINE, "Answered ping - ", p);
    }
    if (logThrowable != null) {
        StackTraceElement[] trace = logThrowable.getStackTrace();
        String traceAsString = null;
        if (trace != null) {
            StringBuilder b = new StringBuilder(": ");
            for (StackTraceElement k : trace) {
                if (k == null) {
                    b.append("null\n");
                } else {
                    b.append(k.toString()).append('\n');
                }
            }
            traceAsString = b.toString();
        }
        getLogger().warning("Caught " + logThrowable.getClass().getName() + " exception in " + getId().getName() + " ping" + (trace == null ? ", no stack trace available." : traceAsString));
    }
}
Also used : Pong(com.yahoo.prelude.Pong)

Example 3 with Pong

use of com.yahoo.prelude.Pong in project vespa by vespa-engine.

the class FastSearcherTestCase method testPing.

@Test
public void testPing() throws IOException, InterruptedException {
    Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
    BackendTestCase.MockServer server = new BackendTestCase.MockServer();
    FS4ResourcePool listeners = new FS4ResourcePool(new Fs4Config(new Fs4Config.Builder()));
    Backend backend = listeners.getBackend(server.host.getHostString(), server.host.getPort());
    FastSearcher fastSearcher = new FastSearcher(backend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(0, 0.0d), documentdbInfoConfig);
    server.dispatch.packetData = BackendTestCase.PONG;
    server.dispatch.setNoChannel();
    Chain<Searcher> chain = new Chain<>(fastSearcher);
    Execution e = new Execution(chain, Execution.Context.createContextStub());
    Pong pong = e.ping(new Ping());
    assertTrue(pong.getPongPacket().isPresent());
    assertEquals(127, pong.getPongPacket().get().getDocstamp());
    backend.shutdown();
    server.dispatch.socket.close();
    server.dispatch.connection.close();
    server.worker.join();
    pong.setPingInfo("blbl");
    assertEquals("Result of pinging using blbl", pong.toString());
}
Also used : Chain(com.yahoo.component.chain.Chain) Searcher(com.yahoo.search.Searcher) Fs4Config(com.yahoo.container.search.Fs4Config) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) Execution(com.yahoo.search.searchchain.Execution) Ping(com.yahoo.prelude.Ping) Pong(com.yahoo.prelude.Pong) Test(org.junit.Test)

Example 4 with Pong

use of com.yahoo.prelude.Pong in project vespa by vespa-engine.

the class VdsStreamingSearcherTestCase method testTrivialitiesToIncreaseCoverage.

@Test
public void testTrivialitiesToIncreaseCoverage() {
    VdsStreamingSearcher searcher = new VdsStreamingSearcher();
    assertNull(searcher.getSearchClusterConfigId());
    String searchClusterConfigId = "searchClusterConfigId";
    searcher.setSearchClusterConfigId(searchClusterConfigId);
    assertEquals(searchClusterConfigId, searcher.getSearchClusterConfigId());
    assertNull(searcher.getStorageClusterRouteSpec());
    String storageClusterRouteSpec = "storageClusterRouteSpec";
    searcher.setStorageClusterRouteSpec(storageClusterRouteSpec);
    assertEquals(storageClusterRouteSpec, searcher.getStorageClusterRouteSpec());
    Pong pong = searcher.ping(new Ping(), new Execution(new Execution.Context(null, null, null, null, null)));
    assertEquals(0, pong.getErrorSize());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Ping(com.yahoo.prelude.Ping) Pong(com.yahoo.prelude.Pong) Test(org.junit.Test)

Example 5 with Pong

use of com.yahoo.prelude.Pong in project vespa by vespa-engine.

the class ClusterSearcher method ping.

/**
 * Pinging a node, called from ClusterMonitor.
 */
void ping(VespaBackEndSearcher node) throws InterruptedException {
    log.fine("Sending ping to: " + node);
    Pinger pinger = new Pinger(node);
    getExecutor().execute(pinger);
    // handles timeout
    Pong pong = pinger.getPong();
    if (pong == null) {
        monitor.failed(node, ErrorMessage.createNoAnswerWhenPingingNode("Ping thread timed out."));
    } else if (pong.badResponse()) {
        monitor.failed(node, pong.getError(0));
    } else {
        monitor.responded(node, backendCanServeDocuments(pong));
    }
}
Also used : Pong(com.yahoo.prelude.Pong)

Aggregations

Pong (com.yahoo.prelude.Pong)10 Ping (com.yahoo.prelude.Ping)3 Execution (com.yahoo.search.searchchain.Execution)3 Searcher (com.yahoo.search.Searcher)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Chain (com.yahoo.component.chain.Chain)1 Fs4Config (com.yahoo.container.search.Fs4Config)1 BasicPacket (com.yahoo.fs4.BasicPacket)1 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)1 PingPacket (com.yahoo.fs4.PingPacket)1 FS4Channel (com.yahoo.fs4.mplex.FS4Channel)1 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)1 MockBackend (com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend)1 Query (com.yahoo.search.Query)1 PingableSearcher (com.yahoo.search.cluster.PingableSearcher)1 InterruptedIOException (java.io.InterruptedIOException)1 FutureTask (java.util.concurrent.FutureTask)1 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)1