Search in sources :

Example 6 with Int32Value

use of com.yahoo.jrt.Int32Value in project vespa by vespa-engine.

the class FileReferenceDownloader method startDownloadRpc.

private boolean startDownloadRpc(FileReferenceDownload fileReferenceDownload) {
    Connection connection = connectionPool.getCurrent();
    Request request = new Request("filedistribution.serveFile");
    String fileReference = fileReferenceDownload.fileReference().value();
    request.parameters().add(new StringValue(fileReference));
    request.parameters().add(new Int32Value(fileReferenceDownload.downloadFromOtherSourceIfNotFound() ? 0 : 1));
    execute(request, connection);
    if (validateResponse(request)) {
        log.log(LogLevel.DEBUG, () -> "Request callback, OK. Req: " + request + "\nSpec: " + connection);
        if (request.returnValues().get(0).asInt32() == 0) {
            log.log(LogLevel.DEBUG, () -> "Found file reference '" + fileReference + "' available at " + connection.getAddress());
            return true;
        } else {
            log.log(LogLevel.DEBUG, "File reference '" + fileReference + "' not found for " + connection.getAddress());
            connectionPool.setNewCurrentConnection();
            return false;
        }
    } else {
        log.log(LogLevel.DEBUG, "Request failed. Req: " + request + "\nSpec: " + connection.getAddress() + ", error code: " + request.errorCode() + ", set error for connection and use another for next request");
        connectionPool.setError(connection, request.errorCode());
        return false;
    }
}
Also used : Connection(com.yahoo.vespa.config.Connection) Request(com.yahoo.jrt.Request) Int32Value(com.yahoo.jrt.Int32Value) StringValue(com.yahoo.jrt.StringValue)

Example 7 with Int32Value

use of com.yahoo.jrt.Int32Value in project vespa by vespa-engine.

the class RpcServer method handleRpcRequests.

public boolean handleRpcRequests(ContentCluster cluster, ClusterState systemState, NodeStateOrHostInfoChangeHandler changeListener, NodeAddedOrRemovedListener addedListener) {
    boolean handledAnyRequests = false;
    if (!isConnected()) {
        long time = timer.getCurrentTimeInMillis();
        try {
            connect();
        } catch (ListenFailedException e) {
            if (!e.getMessage().equals(lastConnectError) || time - lastConnectErrorTime > 60 * 1000) {
                lastConnectError = e.getMessage();
                lastConnectErrorTime = time;
                log.log(LogLevel.WARNING, "Failed to bind RPC server to port " + port + ": " + e.getMessage());
            }
        } catch (Exception e) {
            if (!e.getMessage().equals(lastConnectError) || time - lastConnectErrorTime > 60 * 1000) {
                lastConnectError = e.getMessage();
                lastConnectErrorTime = time;
                log.log(LogLevel.WARNING, "Failed to initailize RPC server socket: " + e.getMessage());
            }
        }
    }
    for (int j = 0; j < 10; ++j) {
        // Max perform 10 RPC requests per cycle.
        Request req;
        synchronized (monitor) {
            if (rpcRequests.isEmpty())
                break;
            Iterator<Request> it = rpcRequests.iterator();
            req = it.next();
            it.remove();
            handledAnyRequests = true;
        }
        try {
            if (req.methodName().equals("getMaster")) {
                log.log(LogLevel.DEBUG, "Resolving RPC getMaster request");
                Integer master = masterHandler.getMaster();
                String masterReason = masterHandler.getMasterReason();
                req.returnValues().add(new Int32Value(master == null ? -1 : master));
                req.returnValues().add(new StringValue(masterReason == null ? "No reason given" : masterReason));
                req.returnRequest();
                continue;
            }
            if (!masterHandler.isMaster()) {
                throw new IllegalStateException("Refusing to answer RPC calls as we are not the master fleetcontroller.");
            }
            if (req.methodName().equals("getNodeList")) {
                log.log(LogLevel.DEBUG, "Resolving RPC getNodeList request");
                List<String> slobrok = new ArrayList<String>();
                List<String> rpc = new ArrayList<String>();
                for (NodeInfo node : cluster.getNodeInfo()) {
                    String s1 = node.getSlobrokAddress();
                    String s2 = node.getRpcAddress();
                    assert (s1 != null);
                    slobrok.add(s1);
                    rpc.add(s2 == null ? "" : s2);
                }
                req.returnValues().add(new StringArray(slobrok.toArray(new String[slobrok.size()])));
                req.returnValues().add(new StringArray(rpc.toArray(new String[rpc.size()])));
                req.returnRequest();
            } else if (req.methodName().equals("getSystemState")) {
                log.log(LogLevel.DEBUG, "Resolving RPC getSystemState request");
                req.returnValues().add(new StringValue(""));
                req.returnValues().add(new StringValue(systemState.toString(true)));
                req.returnRequest();
            } else if (req.methodName().equals("getNodeState")) {
                log.log(LogLevel.DEBUG, "Resolving RPC getNodeState request");
                NodeType nodeType = NodeType.get(req.parameters().get(0).asString());
                int nodeIndex = req.parameters().get(1).asInt32();
                Node node = new Node(nodeType, nodeIndex);
                // First parameter is current state in system state
                NodeState ns = systemState.getNodeState(node);
                req.returnValues().add(new StringValue(systemState.getNodeState(node).serialize()));
                // Second parameter is state node is reporting
                NodeInfo nodeInfo = cluster.getNodeInfo(node);
                if (nodeInfo == null)
                    throw new RuntimeException("No node " + node + " exists in cluster " + cluster.getName());
                NodeState fromNode = nodeInfo.getReportedState();
                req.returnValues().add(new StringValue(fromNode == null ? "unknown" : fromNode.serialize()));
                // Third parameter is state node has been requested to be in
                req.returnValues().add(new StringValue(nodeInfo.getWantedState().serialize()));
                // Fourth parameter is RPC address of node
                req.returnValues().add(new StringValue(nodeInfo.getRpcAddress() == null ? "" : nodeInfo.getRpcAddress()));
                req.returnRequest();
            } else if (req.methodName().equals("setNodeState")) {
                String slobrokAddress = req.parameters().get(0).asString();
                int lastSlash = slobrokAddress.lastIndexOf('/');
                int nextButLastSlash = slobrokAddress.lastIndexOf('/', lastSlash - 1);
                if (lastSlash == -1 || nextButLastSlash == -1) {
                    throw new IllegalStateException("Invalid slobrok address '" + slobrokAddress + "'.");
                }
                NodeType nodeType = NodeType.get(slobrokAddress.substring(nextButLastSlash + 1, lastSlash));
                Integer nodeIndex = Integer.valueOf(slobrokAddress.substring(lastSlash + 1));
                NodeInfo node = cluster.getNodeInfo(new Node(nodeType, nodeIndex));
                if (node == null)
                    throw new IllegalStateException("Cannot set wanted state of node " + new Node(nodeType, nodeIndex) + ". Index does not correspond to a configured node.");
                NodeState nodeState = NodeState.deserialize(nodeType, req.parameters().get(1).asString());
                if (nodeState.getDescription().equals("") && !nodeState.getState().equals(State.UP) && !nodeState.getState().equals(State.RETIRED)) {
                    nodeState.setDescription("Set by remote RPC client");
                }
                NodeState oldState = node.getUserWantedState();
                String message = (nodeState.getState().equals(State.UP) ? "Clearing wanted nodeState for node " + node : "New wantedstate '" + nodeState.toString() + "' stored for node " + node);
                if (!oldState.equals(nodeState) || !oldState.getDescription().equals(nodeState.getDescription())) {
                    if (!nodeState.getState().validWantedNodeState(nodeType)) {
                        throw new IllegalStateException("State " + nodeState.getState() + " can not be used as wanted state for node of type " + nodeType);
                    }
                    node.setWantedState(nodeState);
                    changeListener.handleNewWantedNodeState(node, nodeState);
                } else {
                    message = "Node " + node + " already had wanted state " + nodeState.toString();
                    log.log(LogLevel.DEBUG, message);
                }
                req.returnValues().add(new StringValue(message));
                req.returnRequest();
                if (nodeState.getState() == State.UP && node.getPrematureCrashCount() > 0) {
                    log.log(LogLevel.INFO, "Clearing premature crash count of " + node.getPrematureCrashCount() + " as wanted state was set to up");
                    node.setPrematureCrashCount(0);
                }
            }
        } catch (Exception e) {
            if (log.isLoggable(LogLevel.DEBUG)) {
                StringWriter sw = new StringWriter();
                e.printStackTrace(new PrintWriter(sw));
                log.log(LogLevel.DEBUG, "Failed RPC Request: " + sw);
            }
            String errorMsg = e.getMessage();
            if (errorMsg == null) {
                errorMsg = e.toString();
            }
            req.setError(ErrorCode.METHOD_FAILED, errorMsg);
            req.returnRequest();
        }
    }
    return handledAnyRequests;
}
Also used : NodeState(com.yahoo.vdslib.state.NodeState) Node(com.yahoo.vdslib.state.Node) Request(com.yahoo.jrt.Request) ArrayList(java.util.ArrayList) ListenFailedException(com.yahoo.jrt.ListenFailedException) UnknownHostException(java.net.UnknownHostException) ListenFailedException(com.yahoo.jrt.ListenFailedException) StringArray(com.yahoo.jrt.StringArray) StringWriter(java.io.StringWriter) NodeInfo(com.yahoo.vespa.clustercontroller.core.NodeInfo) NodeType(com.yahoo.vdslib.state.NodeType) Int32Value(com.yahoo.jrt.Int32Value) StringValue(com.yahoo.jrt.StringValue) PrintWriter(java.io.PrintWriter)

Example 8 with Int32Value

use of com.yahoo.jrt.Int32Value in project vespa by vespa-engine.

the class FileServer method serveFile.

private void serveFile(String fileReference, Request request, Receiver receiver) {
    FileApiErrorCodes result;
    try {
        log.log(LogLevel.DEBUG, () -> "Received request for reference '" + fileReference + "' from " + request.target());
        result = hasFile(fileReference) ? FileApiErrorCodes.OK : FileApiErrorCodes.NOT_FOUND;
        if (result == FileApiErrorCodes.OK) {
            startFileServing(fileReference, receiver);
        } else {
            // This is to avoid config servers asking each other for a file that does not exist
            if (request.parameters().size() == 1 || request.parameters().get(1).asInt32() == 0) {
                log.log(LogLevel.DEBUG, "File not found, downloading from another source");
                downloader.getFile(new FileReferenceDownload(new FileReference(fileReference), false));
            } else {
                log.log(LogLevel.DEBUG, "File not found, will not download from another source since request came from another config server");
                result = FileApiErrorCodes.NOT_FOUND;
            }
        }
    } catch (IllegalArgumentException e) {
        result = FileApiErrorCodes.NOT_FOUND;
        log.warning("Failed serving file reference '" + fileReference + "', request was from " + request.target() + ", with error " + e.toString());
    }
    request.returnValues().add(new Int32Value(result.getCode())).add(new StringValue(result.getDescription()));
    request.returnRequest();
}
Also used : FileReferenceDownload(com.yahoo.vespa.filedistribution.FileReferenceDownload) Int32Value(com.yahoo.jrt.Int32Value) FileReference(com.yahoo.config.FileReference) CompressedFileReference(com.yahoo.vespa.filedistribution.CompressedFileReference) StringValue(com.yahoo.jrt.StringValue)

Example 9 with Int32Value

use of com.yahoo.jrt.Int32Value in project vespa by vespa-engine.

the class RpcServer method setFileReferencesToDownload.

@SuppressWarnings({ "UnusedDeclaration" })
public final void setFileReferencesToDownload(Request req) {
    String[] fileReferenceStrings = req.parameters().get(0).asStringArray();
    Stream.of(fileReferenceStrings).map(FileReference::new).forEach(fileReference -> downloader.queueForAsyncDownload(new FileReferenceDownload(fileReference, false)));
    req.returnValues().add(new Int32Value(0));
}
Also used : FileReferenceDownload(com.yahoo.vespa.filedistribution.FileReferenceDownload) Int32Value(com.yahoo.jrt.Int32Value)

Example 10 with Int32Value

use of com.yahoo.jrt.Int32Value in project vespa by vespa-engine.

the class RpcClient method getDocsums.

@Override
public void getDocsums(List<FastHit> hits, NodeConnection node, CompressionType compression, int uncompressedLength, byte[] compressedSlime, Dispatcher.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) {
    Request request = new Request("proton.getDocsums");
    request.parameters().add(new Int8Value(compression.getCode()));
    request.parameters().add(new Int32Value(uncompressedLength));
    request.parameters().add(new DataValue(compressedSlime));
    request.setContext(hits);
    RpcNodeConnection rpcNode = ((RpcNodeConnection) node);
    rpcNode.invokeAsync(request, timeoutSeconds, new RpcResponseWaiter(rpcNode, responseReceiver));
}
Also used : DataValue(com.yahoo.jrt.DataValue) Request(com.yahoo.jrt.Request) Int8Value(com.yahoo.jrt.Int8Value) Int32Value(com.yahoo.jrt.Int32Value)

Aggregations

Int32Value (com.yahoo.jrt.Int32Value)13 Request (com.yahoo.jrt.Request)6 StringValue (com.yahoo.jrt.StringValue)5 FileReference (com.yahoo.config.FileReference)4 DataValue (com.yahoo.jrt.DataValue)4 Int8Value (com.yahoo.jrt.Int8Value)4 Compressor (com.yahoo.compress.Compressor)2 Values (com.yahoo.jrt.Values)2 Cursor (com.yahoo.slime.Cursor)2 Slime (com.yahoo.slime.Slime)2 NodeState (com.yahoo.vdslib.state.NodeState)2 FileReferenceDownload (com.yahoo.vespa.filedistribution.FileReferenceDownload)2 IOException (java.io.IOException)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 Int64Value (com.yahoo.jrt.Int64Value)1 ListenFailedException (com.yahoo.jrt.ListenFailedException)1 Spec (com.yahoo.jrt.Spec)1 StringArray (com.yahoo.jrt.StringArray)1 Supervisor (com.yahoo.jrt.Supervisor)1 Target (com.yahoo.jrt.Target)1