Example #1
0
void Codec20::readNewTopologyAndHash(Transport& transport, HeaderParams& params) const{
    // Just consume the header's byte
	// Do not evaluate new topology right now
	int newTopologyId = transport.readVInt();
    params.topologyId.setId(newTopologyId); //update topologyId reference
    uint32_t clusterSize = transport.readVInt();
    TRACE("Coded20::readNewToplogyAndhash(): clusterSize=%d",clusterSize);
    std::vector<InetSocketAddress> addresses(clusterSize);
    for (uint32_t i = 0; i < clusterSize; i++) {
       std::string host(transport.readString());
       int16_t port = transport.readUnsignedShort();
       addresses[i] = InetSocketAddress(host, port);
    }

    uint8_t hashFunctionVersion = transport.readByte();
    uint32_t numSegments = transport.readVInt();

    std::vector<std::vector<InetSocketAddress>> segmentOwners(numSegments);

    if (hashFunctionVersion > 0) {
       TRACE("Codec20::readNewTopologyAndHash: numSegments=%d", numSegments);
       for (uint32_t i = 0; i < numSegments; i++) {
          uint8_t numOwners = transport.readByte();
          segmentOwners[i]=std::vector<InetSocketAddress>(numOwners);
          for (uint8_t j = 0; j < numOwners; j++) {
             uint32_t memberIndex = transport.readVInt();
             segmentOwners[i][j] = addresses[memberIndex];
          }
       }
    }

    TransportFactory &tf = transport.getTransportFactory();
    bool noTopologyInfo=false;
    int currentTopology = 0;
    try
    {
      currentTopology = tf.getTopologyId(params.cacheName);
    }
    catch (std::exception &e)
    {
    	noTopologyInfo=true;
    }
    int topologyAge = tf.getTopologyAge();
    if (noTopologyInfo || (params.topologyAge == topologyAge && currentTopology != newTopologyId)) {
       params.topologyId = newTopologyId;
       tf.updateServers(addresses);
       if (hashFunctionVersion == 0) {
             TRACE("Not using a consistent hash function (hash function version == 0).");
       } else {
             TRACE("Updating client hash function with %u number of segments", numSegments);
       }
       tf.updateHashFunction(segmentOwners,
          numSegments, hashFunctionVersion, params.cacheName, params.topologyId.getId());
    } else {
       TRACE("Outdated topology received (topology id = %d, topology age = %d), so ignoring it: s",
             newTopologyId, topologyAge/*, Arrays.toString(addresses)*/);
    }
}
Example #2
0
std::map<std::string, std::string> StatsOperation::executeOperation(Transport& transport)
{
    TRACE("Executing Stats");
    hr_scoped_ptr<HeaderParams> params(&(RetryOnFailureOperation<std::map<std::string, std::string> >::writeHeader(transport, STATS_REQUEST)));
    transport.flush();
    RetryOnFailureOperation<std::map<std::string, std::string> >::readHeaderAndValidate(transport, *params);

    int nrOfStats = transport.readVInt();
    TRACE("Stats returning map of %d entries:", nrOfStats);
    std::map<std::string, std::string> result;
    for (int i = 0; i < nrOfStats; i++) {
        std::string statName = transport.readString();
        std::string statValue = transport.readString();
        result[statName] = statValue;
        TRACE("%s -> %s", statName.c_str(), statValue.c_str());
    }
    return result;
}
Example #3
0
void Codec20::checkForErrorsInResponseStatus(Transport& transport, HeaderParams& params, uint8_t status) const {
    try {
        switch (status) {
        case HotRodConstants::INVALID_MAGIC_OR_MESSAGE_ID_STATUS:
        case HotRodConstants::REQUEST_PARSING_ERROR_STATUS:
        case HotRodConstants::UNKNOWN_COMMAND_STATUS:
        case HotRodConstants::SERVER_ERROR_STATUS:
        case HotRodConstants::COMMAND_TIMEOUT_STATUS:
        case HotRodConstants::UNKNOWN_VERSION_STATUS: {
            // If error, the body of the message just contains a message
            std::string msgFromServer = transport.readString();
            if (msgFromServer.find("SuspectException") != std::string::npos || msgFromServer.find("SuspectedException") != std::string::npos) {
                // Handle both Infinispan's and JGroups' suspicions
                // TODO: This will be better handled with its own status id in version 2 of protocol
                throw RemoteNodeSuspectException(msgFromServer, params.messageId, status);
            } else {
                throw HotRodClientException(msgFromServer); //, params.messageId, status);
            }
        }
        default: {
            throw InternalException("Unknown status: " + status);
        }
        }
    } catch (const Exception &) {
        // Some operations require invalidating the transport
        switch (status) {
        case HotRodConstants::INVALID_MAGIC_OR_MESSAGE_ID_STATUS:
        case HotRodConstants::REQUEST_PARSING_ERROR_STATUS:
        case HotRodConstants::UNKNOWN_COMMAND_STATUS:
        case HotRodConstants::UNKNOWN_VERSION_STATUS: {
            transport.invalidate();
        }
        }
        throw;
    }
}