Пример #1
0
CounterConfiguration BaseCounterOperation::readConfiguration(infinispan::hotrod::transport::Transport& transport) {
    uint8_t flags;
    CounterType ct;
    Storage st;
    long concurrentLevel = 0;
    long lower = 0;
    long upper = 0;
    long initial = 0;
    flags = transport.readByte();
    switch (flags & 0x03) {
    case 0x00:
        ct = CounterType::UNBOUNDED_STRONG;
        break;
    case 0x01:
        ct = CounterType::WEAK;
        break;
    case 0x02:
        ct = CounterType::BOUNDED_STRONG;
        break;
    default:
        throw HotRodClientException(std::string("Unknown counter type: ") + std::to_string(flags));
    }
    st = (flags & 0x04) ? Storage::PERSISTENT : Storage::VOLATILE;

    if (ct == WEAK) {
        concurrentLevel = transport.readVInt();
    }
    if (ct == BOUNDED_STRONG) {
        lower = transport.readLong();
        upper = transport.readLong();
    }
    initial = transport.readLong();
    return CounterConfiguration(initial, lower, upper, concurrentLevel, ct, st);
}
Пример #2
0
std::map<InetSocketAddress, std::set<int32_t> > Codec11::computeNewHashes(
        infinispan::hotrod::transport::Transport& transport, uint32_t /*newTopologyId*/, int16_t /*numKeyOwners*/,
        uint8_t hashFunctionVersion, uint32_t /*hashSpace*/, uint32_t clusterSize) const {

    uint32_t numVirtualNodes = transport.readVInt();
    std::map<InetSocketAddress, std::set<int32_t> > servers2Hash;

    ConsistentHash* ch;
    if (hashFunctionVersion != 0) {
        ch = transport.getTransportFactory().getConsistentHashFactory().newConsistentHash(hashFunctionVersion);
    } else {
        ch = 0;
        WARN("Could not obtain a consistent hash for version %d", hashFunctionVersion);
    }

    for (uint32_t i = 0; i < clusterSize; i++) {
        std::string host = transport.readString();
        int16_t port = transport.readUnsignedShort();
        // TODO: Performance improvement, since hash positions are fixed, we could
        //maybe only calculate for those nodes that the client is not aware of?
        int32_t baseHashCode = transport.read4ByteInt();
        int32_t normalizedHashCode = getNormalizedHash(baseHashCode, ch);

        cacheHashCode(servers2Hash, host, port, normalizedHashCode);
        if (numVirtualNodes > 1) {
            calcVirtualHashCodes(baseHashCode, numVirtualNodes, servers2Hash,
                    host, port, ch);
        }
    }

    return servers2Hash;
}
Пример #3
0
std::set<std::string> GetCounterNamesOperation::executeOperation(infinispan::hotrod::transport::Transport& transport) {
    TRACE("Executing GetCounterNamesOperation(flags=%u)", flags);
    std::unique_ptr<HeaderParams> params(
            RetryOnFailureOperation<std::set<std::string>>::writeHeader(transport, COUNTER_GET_NAMES_REQUEST));
    uint8_t status = readHeaderAndValidate(transport, *params);
    std::set<std::string> ret;
    if (!isSuccess(status)) {
        auto num = transport.readVInt();
        for (uint32_t i = 0; i < num; i++) {
            auto name = transport.readString();
            ret.insert(name);
        }
    }
    TRACE("Finished GetCounterNamesOperation");
    return ret;
}