From 1edcd6a9e996b2bdd50524d957e8185b873fac3d Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Wed, 29 Jan 2014 11:24:09 +0100 Subject: [PATCH] Report cluster wide collection name in _id --- arangod/Utils/CollectionNameResolver.h | 47 +++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/arangod/Utils/CollectionNameResolver.h b/arangod/Utils/CollectionNameResolver.h index 6ec7cdf260..7a8d01ffb3 100644 --- a/arangod/Utils/CollectionNameResolver.h +++ b/arangod/Utils/CollectionNameResolver.h @@ -33,6 +33,11 @@ #include "Basics/StringUtils.h" #include "VocBase/vocbase.h" +#ifdef TRI_ENABLE_CLUSTER +#include "Cluster/ServerState.h" +#include "Cluster/ClusterInfo.h" +#endif + namespace triagens { namespace arango { @@ -137,15 +142,47 @@ namespace triagens { } } - char* n = TRI_GetCollectionNameByIdVocBase(_vocbase, cid); - if (n == 0) { - return "_unknown"; + string name; +#ifndef TRI_ENABLE_CLUSTER + char *n = TRI_GetCollectionNameByIdVocBase(_vocbase, cid); + if (0 != n) { + name = n; + TRI_Free(TRI_UNKNOWN_MEM_ZONE, n); } +#else + if (ServerState::instance()->isDBserver()) { + TRI_READ_LOCK_COLLECTIONS_VOCBASE(_vocbase); - string name(n); + TRI_vocbase_col_t* found + = static_cast( + TRI_LookupByKeyAssociativePointer + (&_vocbase->_collectionsById, &cid)); + if (0 != found) { + name = triagens::basics::StringUtils::itoa(found->_planId); + } + + TRI_READ_UNLOCK_COLLECTIONS_VOCBASE(_vocbase); + + if (!name.empty()) { + TRI_shared_ptr ci + = ClusterInfo::instance()->getCollection(found->_dbName, name); + name = ci->name(); + } + } + else { + // exactly as in the non-cluster case + char *n = TRI_GetCollectionNameByIdVocBase(_vocbase, cid); + if (0 != n) { + name = n; + TRI_Free(TRI_UNKNOWN_MEM_ZONE, n); + } + } +#endif + if (name.empty()) { + name = "_unknown"; + } _resolvedIds[cid] = name; - TRI_Free(TRI_UNKNOWN_MEM_ZONE, n); return name; }