Exemplo n.º 1
0
TRI_voc_cid_t CollectionNameResolver::getCollectionIdCluster(
    std::string const& name) const {
    if (!ServerState::isRunningInCluster(_serverRole)) {
        return getCollectionIdLocal(name);
    }
    if (name[0] >= '0' && name[0] <= '9') {
        // name is a numeric id
        TRI_voc_cid_t cid = static_cast<TRI_voc_cid_t>(arangodb::basics::StringUtils::uint64(name));
        // Now validate the cid
        TRI_col_type_e type = getCollectionTypeCluster(getCollectionNameCluster(cid));
        if (type == TRI_COL_TYPE_UNKNOWN) {
            return 0;
        }
        return cid;
    }

    try {
        // We have to look up the collection info:
        ClusterInfo* ci = ClusterInfo::instance();
        auto cinfo = ci->getCollection(_vocbase->name(), name);
        TRI_ASSERT(cinfo != nullptr);
        return cinfo->cid();
    } catch (...) {
    }
    return 0;
}
Exemplo n.º 2
0
TRI_col_type_e CollectionNameResolver::getCollectionTypeCluster(
    std::string const& name) const {
    // This fires in Single server case as well
    if (!ServerState::isCoordinator(_serverRole)) {
        return getCollectionType(name);
    }
    if (name[0] >= '0' && name[0] <= '9') {
        // name is a numeric id
        return getCollectionTypeCluster(
                   getCollectionName(static_cast<TRI_voc_cid_t>(
                                         arangodb::basics::StringUtils::uint64(name))));
    }

    try {
        // We have to look up the collection info:
        ClusterInfo* ci = ClusterInfo::instance();
        auto cinfo = ci->getCollection(_vocbase->name(), name);
        TRI_ASSERT(cinfo != nullptr);
        return cinfo->type();
    } catch(...) {
    }
    return TRI_COL_TYPE_UNKNOWN;
}