1
0
Fork 0

Removed cluster-wide CollectionInfo and replaced it with a logical collection. The Logical collection shall be always available, in cluster and single server.

This commit is contained in:
Michael Hackstein 2016-08-15 09:08:24 +02:00
parent 79fd589ac0
commit 94ca36fdb2
17 changed files with 270 additions and 626 deletions

View File

@ -97,7 +97,7 @@ TRI_voc_cid_t Collection::getPlanId() const {
vocbase->name().c_str(), name.c_str());
}
return collectionInfo.get()->id();
return collectionInfo.get()->cid();
}
/// @brief returns the shard ids of a collection

View File

@ -96,46 +96,6 @@ static std::string extractErrorMessage(std::string const& shardId,
return msg;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates an empty collection info object
////////////////////////////////////////////////////////////////////////////////
CollectionInfo::CollectionInfo()
: _vpack(std::make_shared<VPackBuilder>()) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a collection info object from json
////////////////////////////////////////////////////////////////////////////////
CollectionInfo::CollectionInfo(std::shared_ptr<VPackBuilder> vpack, VPackSlice slice)
: _vpack(vpack), _slice(slice) {}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a collection info object from another
////////////////////////////////////////////////////////////////////////////////
CollectionInfo::CollectionInfo(CollectionInfo const& other)
: _vpack(other._vpack), _slice(other._slice) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief copy assigns a collection info object from another one
////////////////////////////////////////////////////////////////////////////////
CollectionInfo& CollectionInfo::operator=(CollectionInfo const& other) {
_vpack = other._vpack;
_slice = other._slice;
return *this;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a collection info object
////////////////////////////////////////////////////////////////////////////////
CollectionInfo::~CollectionInfo() {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief creates an empty collection info object
////////////////////////////////////////////////////////////////////////////////
@ -473,7 +433,7 @@ void ClusterInfo::loadPlan() {
}
std::string const collectionId = collectionPairSlice.key.copyString();
auto newCollection = std::make_shared<CollectionInfo>(planBuilder, collectionSlice);
auto newCollection = std::make_shared<LogicalCollection>(collectionSlice);
std::string const collectionName = newCollection->name();
// mop: register with name as well as with id
@ -498,6 +458,7 @@ void ClusterInfo::loadPlan() {
});
newShards.emplace(std::make_pair(collectionId, shards));
}
newCollections.emplace(std::make_pair(databaseName, databaseCollections));
swapCollections = true;
}
@ -646,9 +607,8 @@ void ClusterInfo::loadCurrent() {
/// @brief ask about a collection
/// If it is not found in the cache, the cache is reloaded once
////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<CollectionInfo> ClusterInfo::getCollection(
std::shared_ptr<LogicalCollection> ClusterInfo::getCollection(
DatabaseID const& databaseID, CollectionID const& collectionID) {
int tries = 0;
@ -680,37 +640,16 @@ std::shared_ptr<CollectionInfo> ClusterInfo::getCollection(
// must load collections outside the lock
loadPlan();
}
return std::make_shared<CollectionInfo>();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get properties of a collection
////////////////////////////////////////////////////////////////////////////////
arangodb::VocbaseCollectionInfo ClusterInfo::getCollectionProperties(
CollectionInfo const& collection) {
arangodb::VocbaseCollectionInfo info(collection);
return info;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get properties of a collection
////////////////////////////////////////////////////////////////////////////////
VocbaseCollectionInfo ClusterInfo::getCollectionProperties(
DatabaseID const& databaseID, CollectionID const& collectionID) {
auto ci = getCollection(databaseID, collectionID);
return getCollectionProperties(*ci);
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief ask about all collections
////////////////////////////////////////////////////////////////////////////////
std::vector<std::shared_ptr<CollectionInfo>> const ClusterInfo::getCollections(
std::vector<std::shared_ptr<LogicalCollection>> const ClusterInfo::getCollections(
DatabaseID const& databaseID) {
std::vector<std::shared_ptr<CollectionInfo>> result;
std::vector<std::shared_ptr<LogicalCollection>> result;
// always reload
loadPlan();
@ -1518,7 +1457,7 @@ int ClusterInfo::ensureIndexCoordinator(
auto collectionBuilder = std::make_shared<VPackBuilder>();
{
std::shared_ptr<CollectionInfo> c =
std::shared_ptr<LogicalCollection> c =
getCollection(databaseName, collectionID);
// Note that nobody is removing this collection in the plan, since
@ -1528,7 +1467,7 @@ int ClusterInfo::ensureIndexCoordinator(
//
READ_LOCKER(readLocker, _planProt.lock);
if (c->empty()) {
if (c == nullptr) {
return setErrormsg(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, errorMsg);
}
@ -1579,7 +1518,7 @@ int ClusterInfo::ensureIndexCoordinator(
}
// now create a new index
collectionBuilder->add(c->getSlice());
c->toVelocyPack(*collectionBuilder);
}
VPackSlice const collectionSlice = collectionBuilder->slice();
@ -1770,12 +1709,12 @@ int ClusterInfo::dropIndexCoordinator(std::string const& databaseName,
VPackSlice indexes;
{
std::shared_ptr<CollectionInfo> c =
std::shared_ptr<LogicalCollection> c =
getCollection(databaseName, collectionID);
READ_LOCKER(readLocker, _planProt.lock);
if (c->empty()) {
if (c == nullptr) {
return setErrormsg(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, errorMsg);
}
indexes = c->getIndexes();

View File

@ -32,6 +32,7 @@
#include "Basics/ReadWriteLock.h"
#include "Cluster/AgencyComm.h"
#include "Cluster/AgencyCallbackRegistry.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/voc-types.h"
#include "VocBase/vocbase.h"
@ -44,351 +45,13 @@ namespace velocypack {
class Slice;
}
class ClusterInfo;
class LogicalCollection;
typedef std::string ServerID; // ID of a server
typedef std::string DatabaseID; // ID/name of a database
typedef std::string CollectionID; // ID of a collection
typedef std::string ShardID; // ID of a shard
class CollectionInfo {
friend class ClusterInfo;
public:
CollectionInfo();
CollectionInfo(std::shared_ptr<VPackBuilder>, VPackSlice);
CollectionInfo(CollectionInfo const&);
CollectionInfo(CollectionInfo&&);
CollectionInfo& operator=(CollectionInfo const&);
CollectionInfo& operator=(CollectionInfo&&);
~CollectionInfo();
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the replication factor
//////////////////////////////////////////////////////////////////////////////
int replicationFactor () const {
if (!_slice.isObject()) {
return 1;
}
return arangodb::basics::VelocyPackHelper::getNumericValue<TRI_voc_size_t>(
_slice, "replicationFactor", 1);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief checks whether there is no info contained
//////////////////////////////////////////////////////////////////////////////
bool empty() const {
return _slice.isNone();
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection id
//////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t id() const {
if (!_slice.isObject()) {
return 0;
}
VPackSlice idSlice = _slice.get("id");
if (idSlice.isString()) {
return arangodb::basics::VelocyPackHelper::stringUInt64(idSlice);
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection id as a string
//////////////////////////////////////////////////////////////////////////////
std::string id_as_string() const {
if (!_slice.isObject()) {
return std::string("");
}
return arangodb::basics::VelocyPackHelper::getStringValue(_slice, "id", "");
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection name
//////////////////////////////////////////////////////////////////////////////
std::string name() const {
if (!_slice.isObject()) {
return std::string("");
}
return arangodb::basics::VelocyPackHelper::getStringValue(_slice, "name", "");
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection type
//////////////////////////////////////////////////////////////////////////////
TRI_col_type_e type() const {
if (!_slice.isObject()) {
return TRI_COL_TYPE_UNKNOWN;
}
return (TRI_col_type_e)arangodb::basics::VelocyPackHelper::getNumericValue<int>(
_slice, "type", (int)TRI_COL_TYPE_UNKNOWN);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection status
//////////////////////////////////////////////////////////////////////////////
TRI_vocbase_col_status_e status() const {
if (!_slice.isObject()) {
return TRI_VOC_COL_STATUS_CORRUPTED;
}
return (TRI_vocbase_col_status_e)
arangodb::basics::VelocyPackHelper::getNumericValue<int>(
_slice, "status", (int)TRI_VOC_COL_STATUS_CORRUPTED);
}
/// @brief returns the collection status as a string
std::string statusString() const { return TRI_vocbase_col_t::statusString(status()); }
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the deleted flag
//////////////////////////////////////////////////////////////////////////////
bool deleted() const {
if (!_slice.isObject()) {
return false;
}
return arangodb::basics::VelocyPackHelper::getBooleanValue(_slice, "deleted",
false);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the docompact flag
//////////////////////////////////////////////////////////////////////////////
bool doCompact() const {
if (!_slice.isObject()) {
return false;
}
return arangodb::basics::VelocyPackHelper::getBooleanValue(_slice, "doCompact",
false);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the issystem flag
//////////////////////////////////////////////////////////////////////////////
bool isSystem() const {
if (!_slice.isObject()) {
return false;
}
return arangodb::basics::VelocyPackHelper::getBooleanValue(_slice, "isSystem",
false);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the isvolatile flag
//////////////////////////////////////////////////////////////////////////////
bool isVolatile() const {
if (!_slice.isObject()) {
return false;
}
return arangodb::basics::VelocyPackHelper::getBooleanValue(_slice, "isVolatile",
false);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the indexes
//////////////////////////////////////////////////////////////////////////////
VPackSlice const getIndexes() const {
if (_slice.isNone()) {
return VPackSlice();
}
return _slice.get("indexes");
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns a copy of the key options
//////////////////////////////////////////////////////////////////////////////
VPackSlice const keyOptions() const {
if (_slice.isNone()) {
return VPackSlice();
}
return _slice.get("keyOptions");
}
//////////////////////////////////////////////////////////////////////////////
/// @brief whether or not a collection allows user-defined keys
//////////////////////////////////////////////////////////////////////////////
bool allowUserKeys() const {
VPackSlice keyOptionsSlice = keyOptions();
if (!keyOptionsSlice.isNone()) {
return arangodb::basics::VelocyPackHelper::getBooleanValue(
keyOptionsSlice, "allowUserKeys", true);
}
return true; // the default value
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the waitforsync flag
//////////////////////////////////////////////////////////////////////////////
bool waitForSync() const {
if (!_slice.isObject()) {
return false;
}
return arangodb::basics::VelocyPackHelper::getBooleanValue(_slice, "waitForSync",
false);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the maximal journal size
//////////////////////////////////////////////////////////////////////////////
TRI_voc_size_t journalSize() const {
if (!_slice.isObject()) {
return 0;
}
return arangodb::basics::VelocyPackHelper::getNumericValue<TRI_voc_size_t>(
_slice, "journalSize", 0);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the number of buckets for indexes
//////////////////////////////////////////////////////////////////////////////
uint32_t indexBuckets() const {
if (!_slice.isObject()) {
return 1;
}
return arangodb::basics::VelocyPackHelper::getNumericValue<uint32_t>(
_slice, "indexBuckets", 1);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the shard keys
//////////////////////////////////////////////////////////////////////////////
std::vector<std::string> shardKeys() const {
std::vector<std::string> shardKeys;
if (_slice.isNone()) {
return shardKeys;
}
auto shardKeysSlice = _slice.get("shardKeys");
if (shardKeysSlice.isArray()) {
for (auto const& shardKey: VPackArrayIterator(shardKeysSlice)) {
shardKeys.push_back(shardKey.copyString());
}
}
return shardKeys;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns true if the default shard key is used
//////////////////////////////////////////////////////////////////////////////
bool usesDefaultShardKeys() const {
if (_slice.isNone()) {
return false;
}
auto shardKeysSlice = _slice.get("shardKeys");
if (!shardKeysSlice.isArray() || shardKeysSlice.length() != 1) {
return false;
}
auto firstElement = shardKeysSlice.at(0);
TRI_ASSERT(firstElement.isString());
std::string shardKey =
arangodb::basics::VelocyPackHelper::getStringValue(firstElement, "");
return shardKey == StaticStrings::KeyString;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the shard ids
//////////////////////////////////////////////////////////////////////////////
typedef std::unordered_map<ShardID, std::vector<ServerID>> ShardMap;
std::shared_ptr<ShardMap> shardIds() const {
std::shared_ptr<ShardMap> res;
{
MUTEX_LOCKER(locker, _mutex);
res = _shardMapCache;
}
if (res.get() != nullptr) {
return res;
}
res.reset(new ShardMap());
auto shardsSlice = _slice.get("shards");
if (shardsSlice.isObject()) {
for (auto const& shardSlice: VPackObjectIterator(shardsSlice)) {
if (shardSlice.key.isString() && shardSlice.value.isArray()) {
ShardID shard = shardSlice.key.copyString();
std::vector<ServerID> servers;
for (auto const& serverSlice: VPackArrayIterator(shardSlice.value)) {
servers.push_back(serverSlice.copyString());
}
(*res).insert(make_pair(shard, servers));
}
}
}
{
MUTEX_LOCKER(locker, _mutex);
_shardMapCache = res;
}
return res;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the number of shards
//////////////////////////////////////////////////////////////////////////////
int numberOfShards() const {
if (_slice.isNone()) {
return 0;
}
auto shardsSlice = _slice.get("shards");
if (shardsSlice.isObject()) {
return static_cast<int>(shardsSlice.length());
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the json
//////////////////////////////////////////////////////////////////////////////
std::shared_ptr<VPackBuilder> const getVPack() const { return _vpack; }
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the slice
//////////////////////////////////////////////////////////////////////////////
VPackSlice const getSlice() const { return _slice; }
private:
std::shared_ptr<VPackBuilder> _vpack;
VPackSlice _slice;
// Only to protect the cache:
mutable Mutex _mutex;
// Just a cache
mutable std::shared_ptr<ShardMap> _shardMapCache;
};
class CollectionInfoCurrent {
friend class ClusterInfo;
@ -549,7 +212,8 @@ class CollectionInfoCurrent {
class ClusterInfo {
private:
typedef std::unordered_map<CollectionID, std::shared_ptr<CollectionInfo>>
typedef std::unordered_map<CollectionID, std::shared_ptr<LogicalCollection>>
DatabaseCollections;
typedef std::unordered_map<DatabaseID, DatabaseCollections> AllCollections;
typedef std::unordered_map<CollectionID,
@ -635,27 +299,14 @@ class ClusterInfo {
/// argument can be a collection ID or a collection name (both cluster-wide).
//////////////////////////////////////////////////////////////////////////////
std::shared_ptr<CollectionInfo> getCollection(DatabaseID const&,
CollectionID const&);
//////////////////////////////////////////////////////////////////////////////
/// @brief get properties of a collection
//////////////////////////////////////////////////////////////////////////////
VocbaseCollectionInfo getCollectionProperties(CollectionInfo const&);
//////////////////////////////////////////////////////////////////////////////
/// @brief get properties of a collection
//////////////////////////////////////////////////////////////////////////////
VocbaseCollectionInfo getCollectionProperties(DatabaseID const&,
std::shared_ptr<LogicalCollection> getCollection(DatabaseID const&,
CollectionID const&);
//////////////////////////////////////////////////////////////////////////////
/// @brief ask about all collections
//////////////////////////////////////////////////////////////////////////////
std::vector<std::shared_ptr<CollectionInfo>> const getCollections(
std::vector<std::shared_ptr<LogicalCollection>> const getCollections(
DatabaseID const&);
//////////////////////////////////////////////////////////////////////////////

View File

@ -223,7 +223,7 @@ static void extractErrorCodes(ClusterCommResult const& res,
static int distributeBabyOnShards(
std::unordered_map<ShardID, std::vector<VPackValueLength>>& shardMap,
ClusterInfo* ci, std::string const& collid,
std::shared_ptr<CollectionInfo> collinfo,
std::shared_ptr<LogicalCollection> collinfo,
std::vector<std::pair<ShardID, VPackValueLength>>& reverseMapping,
VPackSlice const node, VPackValueLength const index) {
// Now find the responsible shard:
@ -264,7 +264,7 @@ static int distributeBabyOnShards(
std::vector<std::pair<VPackValueLength, std::string>>>&
shardMap,
ClusterInfo* ci, std::string const& collid,
std::shared_ptr<CollectionInfo> collinfo,
std::shared_ptr<LogicalCollection> collinfo,
std::vector<std::pair<ShardID, VPackValueLength>>& reverseMapping,
VPackSlice const node, VPackValueLength const index) {
ShardID shardID;
@ -424,7 +424,13 @@ bool shardKeysChanged(std::string const& dbname, std::string const& collname,
}
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> c = ci->getCollection(dbname, collname);
std::shared_ptr<LogicalCollection> c = ci->getCollection(dbname, collname);
TRI_ASSERT(c != nullptr);
if (c == nullptr) {
// Default behaviour if shardKeys is empty
return false;
}
std::vector<std::string> const& shardKeys = c->shardKeys();
for (size_t i = 0; i < shardKeys.size(); ++i) {
@ -475,10 +481,10 @@ int revisionOnCoordinator(std::string const& dbname,
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
@ -546,10 +552,10 @@ int figuresOnCoordinator(std::string const& dbname, std::string const& collname,
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
@ -654,10 +660,10 @@ int countOnCoordinator(std::string const& dbname, std::string const& collname,
result = 0;
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
@ -722,14 +728,14 @@ int createDocumentOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
std::string const collid = StringUtils::itoa(collinfo->id());
std::string const collid = collinfo->cid_as_string();
std::unordered_map<
ShardID, std::vector<std::pair<VPackValueLength, std::string>>> shardMap;
std::vector<std::pair<ShardID, VPackValueLength>> reverseMapping;
@ -854,13 +860,13 @@ int deleteDocumentOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
bool useDefaultSharding = collinfo->usesDefaultShardKeys();
std::string collid = StringUtils::itoa(collinfo->id());
std::string collid = collinfo->cid_as_string();
bool useMultiple = slice.isArray();
std::string const baseUrl =
@ -1080,10 +1086,10 @@ int truncateCollectionOnCoordinator(std::string const& dbname,
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
@ -1135,12 +1141,12 @@ int getDocumentOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
std::string collid = StringUtils::itoa(collinfo->id());
std::string collid = collinfo->cid_as_string();
// If _key is the one and only sharding attribute, we can do this quickly,
// because we can easily determine which shard is responsible for the
@ -1386,13 +1392,13 @@ static void insertIntoShardMap(
TRI_ASSERT(splitId.size() == 2);
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, splitId[0]);
if (collinfo->empty()) {
if (collinfo == nullptr) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND,
"Collection not found: " + splitId[0]);
}
std::string collid = StringUtils::itoa(collinfo->id());
std::string collid = collinfo->cid_as_string();
if (collinfo->usesDefaultShardKeys()) {
// We only need add one resp. shard
VPackBuilder partial;
@ -1552,9 +1558,9 @@ int getFilteredEdgesOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
@ -1672,12 +1678,12 @@ int modifyDocumentOnCoordinator(
ClusterComm* cc = ClusterComm::instance();
// First determine the collection ID from the name:
std::shared_ptr<CollectionInfo> collinfo =
std::shared_ptr<LogicalCollection> collinfo =
ci->getCollection(dbname, collname);
if (collinfo->empty()) {
if (collinfo == nullptr) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
std::string collid = StringUtils::itoa(collinfo->id());
std::string collid = collinfo->cid_as_string();
// We have a fast path and a slow path. The fast path only asks one shard
// to do the job and the slow path asks them all and expects to get

View File

@ -673,11 +673,12 @@ static void JS_GetCollectionInfoClusterInfo(
"getCollectionInfo(<database-id>, <collection-id>)");
}
std::shared_ptr<CollectionInfo> ci = ClusterInfo::instance()->getCollection(
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollection(
TRI_ObjectToString(args[0]), TRI_ObjectToString(args[1]));
TRI_ASSERT(ci == nullptr);
v8::Handle<v8::Object> result = v8::Object::New(isolate);
std::string const cid = arangodb::basics::StringUtils::itoa(ci->id());
std::string const cid = ci->cid_as_string();
std::string const& name = ci->name();
result->Set(TRI_V8_ASCII_STRING("id"), TRI_V8_STD_STRING(cid));
result->Set(TRI_V8_ASCII_STRING("name"), TRI_V8_STD_STRING(name));
@ -748,12 +749,13 @@ static void JS_GetCollectionInfoCurrentClusterInfo(
ShardID shardID = TRI_ObjectToString(args[2]);
std::shared_ptr<CollectionInfo> ci = ClusterInfo::instance()->getCollection(
std::shared_ptr<LogicalCollection> ci = ClusterInfo::instance()->getCollection(
TRI_ObjectToString(args[0]), TRI_ObjectToString(args[1]));
TRI_ASSERT(ci = nullptr);
v8::Handle<v8::Object> result = v8::Object::New(isolate);
// First some stuff from Plan for which Current does not make sense:
std::string const cid = arangodb::basics::StringUtils::itoa(ci->id());
std::string const cid = ci->cid_as_string();
std::string const& name = ci->name();
result->Set(TRI_V8_ASCII_STRING("id"), TRI_V8_STD_STRING(cid));
result->Set(TRI_V8_ASCII_STRING("name"), TRI_V8_STD_STRING(name));

View File

@ -1654,12 +1654,12 @@ int RestReplicationHandler::processRestoreCollectionCoordinator(
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> col = ci->getCollection(dbName, name);
std::shared_ptr<LogicalCollection> col = ci->getCollection(dbName, name);
// drop an existing collection if it exists
if (!col->empty()) {
if (col != nullptr) {
if (dropExisting) {
int res = ci->dropCollectionCoordinator(dbName, col->id_as_string(),
int res = ci->dropCollectionCoordinator(dbName, col->cid_as_string(),
errorMsg, 0.0);
if (res == TRI_ERROR_FORBIDDEN) {
// some collections must not be dropped
@ -1974,9 +1974,9 @@ int RestReplicationHandler::processRestoreIndexesCoordinator(
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> col = ci->getCollection(dbName, name);
std::shared_ptr<LogicalCollection> col = ci->getCollection(dbName, name);
if (col->empty()) {
if (col == nullptr) {
errorMsg = "could not find collection '" + name + "'";
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
@ -1991,7 +1991,7 @@ int RestReplicationHandler::processRestoreIndexesCoordinator(
}
VPackBuilder tmp;
res = ci->ensureIndexCoordinator(dbName, col->id_as_string(), idxDef, true,
res = ci->ensureIndexCoordinator(dbName, col->cid_as_string(), idxDef, true,
arangodb::Index::Compare, tmp, errorMsg,
3600.0);
if (res != TRI_ERROR_NO_ERROR) {
@ -2483,9 +2483,9 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator() {
// in a cluster, we only look up by name:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> col = ci->getCollection(dbName, name);
std::shared_ptr<LogicalCollection> col = ci->getCollection(dbName, name);
if (col->empty()) {
if (col == nullptr) {
generateError(GeneralResponse::ResponseCode::BAD,
TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
return;
@ -2551,7 +2551,7 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator() {
if (!doc.isNone() && type != REPLICATION_MARKER_REMOVE) {
ShardID responsibleShard;
bool usesDefaultSharding;
res = ci->getResponsibleShard(col->id_as_string(), doc, true,
res = ci->getResponsibleShard(col->cid_as_string(), doc, true,
responsibleShard, usesDefaultSharding);
if (res != TRI_ERROR_NO_ERROR) {
errorMsg = "error during determining responsible shard";

View File

@ -97,12 +97,8 @@ class CollectionNameResolver {
// We have to look up the collection info:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> cinfo =
ci->getCollection(_vocbase->name(), name);
if (cinfo->empty()) {
return 0;
}
return cinfo->id();
auto cinfo = ci->getCollection(_vocbase->name(), name);
return cinfo->cid();
}
//////////////////////////////////////////////////////////////////////////////
@ -179,11 +175,7 @@ class CollectionNameResolver {
// We have to look up the collection info:
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> cinfo =
ci->getCollection(_vocbase->name(), name);
if (cinfo->empty()) {
return TRI_COL_TYPE_UNKNOWN;
}
auto cinfo = ci->getCollection(_vocbase->name(), name);
return cinfo->type();
}
@ -238,8 +230,7 @@ class CollectionNameResolver {
int tries = 0;
while (tries++ < 2) {
std::shared_ptr<CollectionInfo> ci =
ClusterInfo::instance()->getCollection(
auto ci = ClusterInfo::instance()->getCollection(
_vocbase->name(), arangodb::basics::StringUtils::itoa(cid));
name = ci->name();
@ -287,8 +278,8 @@ class CollectionNameResolver {
} else {
// DBserver case of a shard:
name = arangodb::basics::StringUtils::itoa((*it).second->planId());
std::shared_ptr<CollectionInfo> ci =
ClusterInfo::instance()->getCollection((*it).second->dbName(), name);
auto ci = ClusterInfo::instance()->getCollection(
(*it).second->dbName(), name);
name = ci->name(); // can be empty, if collection unknown
}
}

View File

@ -47,6 +47,7 @@
#include "VocBase/DatafileHelper.h"
#include "VocBase/Ditch.h"
#include "VocBase/KeyGenerator.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/MasterPointers.h"
#include "VocBase/collection.h"
#include "VocBase/ticks.h"
@ -3118,13 +3119,13 @@ std::shared_ptr<Index> Transaction::indexForCollectionCoordinator(
auto collectionInfo =
clusterInfo->getCollection(_vocbase->name(), name);
if (collectionInfo.get() == nullptr || (*collectionInfo).empty()) {
if (collectionInfo.get() == nullptr) {
THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_INTERNAL,
"collection not found '%s' in database '%s'",
name.c_str(), _vocbase->name().c_str());
}
VPackSlice const slice = (*collectionInfo).getIndexes();
VPackSlice const slice = collectionInfo->getIndexes();
if (slice.isArray()) {
for (auto const& v : VPackArrayIterator(slice)) {
@ -3180,7 +3181,7 @@ std::vector<std::shared_ptr<Index>> Transaction::indexesForCollectionCoordinator
auto collectionInfo =
clusterInfo->getCollection(_vocbase->name(), name);
if (collectionInfo.get() == nullptr || (*collectionInfo).empty()) {
if (collectionInfo.get() == nullptr) {
THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_INTERNAL,
"collection not found '%s' in database '%s'",
name.c_str(), _vocbase->name().c_str());

View File

@ -38,16 +38,6 @@ void ReleaseCollection(TRI_vocbase_col_t const* collection) {
collection->_vocbase->releaseCollection(const_cast<TRI_vocbase_col_t*>(collection));
}
/// @brief convert a collection info into a TRI_vocbase_col_t
TRI_vocbase_col_t* CoordinatorCollection(TRI_vocbase_t* vocbase,
CollectionInfo const& ci) {
auto c = std::make_unique<TRI_vocbase_col_t>(vocbase, ci.type(), ci.id(), ci.name(), ci.id(), "");
c->_isLocal = false;
c->setStatus(ci.status());
return c.release();
}
/// @brief check if a name belongs to a collection
bool EqualCollection(CollectionNameResolver const* resolver,
std::string const& collectionName,
@ -177,3 +167,64 @@ v8::Handle<v8::Object> WrapCollection(v8::Isolate* isolate,
return scope.Escape<v8::Object>(result);
}
/////////////////////////////////////////////////////////////////////////////////
/// @brief wraps a LogicalCollection
////////////////////////////////////////////////////////////////////////////////
v8::Handle<v8::Object> WrapCollection(v8::Isolate* isolate,
arangodb::LogicalCollection const* collection) {
v8::EscapableHandleScope scope(isolate);
TRI_GET_GLOBALS();
TRI_GET_GLOBAL(VocbaseColTempl, v8::ObjectTemplate);
v8::Handle<v8::Object> result = VocbaseColTempl->NewInstance();
if (!result.IsEmpty()) {
LogicalCollection* nonconstCollection =
const_cast<LogicalCollection*>(collection);
result->SetInternalField(SLOT_CLASS_TYPE,
v8::Integer::New(isolate, WRP_VOCBASE_COL_TYPE));
result->SetInternalField(SLOT_CLASS,
v8::External::New(isolate, nonconstCollection));
auto const& it = v8g->JSCollections.find(nonconstCollection);
if (it == v8g->JSCollections.end()) {
// increase the reference-counter for the database
nonconstCollection->vocbase()->use();
try {
auto externalCollection = v8::External::New(isolate, nonconstCollection);
result->SetInternalField(SLOT_COLLECTION, externalCollection);
v8g->JSCollections[nonconstCollection].Reset(isolate, externalCollection);
v8g->JSCollections[nonconstCollection].SetWeak(
&v8g->JSCollections[nonconstCollection], WeakCollectionCallback);
v8g->increaseActiveExternals();
} catch (...) {
nonconstCollection->vocbase()->release();
throw;
}
} else {
auto myCollection = v8::Local<v8::External>::New(isolate, it->second);
result->SetInternalField(SLOT_COLLECTION, myCollection);
}
TRI_GET_GLOBAL_STRING(_IdKey);
TRI_GET_GLOBAL_STRING(_DbNameKey);
TRI_GET_GLOBAL_STRING(VersionKeyHidden);
result->ForceSet(_IdKey, V8CollectionId(isolate, collection->cid()),
v8::ReadOnly);
result->Set(_DbNameKey, TRI_V8_STRING(collection->vocbase()->name().c_str()));
#warning Hardcoded version. Do we need it?! Ask Jan.
result->ForceSet(
VersionKeyHidden,
v8::Integer::NewFromUnsigned(isolate, 5),
v8::DontEnum);
}
return scope.Escape<v8::Object>(result);
}

View File

@ -170,23 +170,18 @@ static int ParseDocumentOrDocumentHandle(v8::Isolate* isolate,
// no collection object was passed, now check the user-supplied collection
// name
#warning FIXME
TRI_vocbase_col_t const* col = nullptr;
std::shared_ptr<LogicalCollection> colNew;
if (ServerState::instance()->isCoordinator()) {
ClusterInfo* ci = ClusterInfo::instance();
std::shared_ptr<CollectionInfo> c =
ci->getCollection(vocbase->name(), collectionName);
col = CoordinatorCollection(vocbase, *c);
if (col != nullptr && col->_cid == 0) {
delete col;
col = nullptr;
}
colNew = ci->getCollection(vocbase->name(), collectionName);
} else {
col = resolver->getCollectionStruct(collectionName);
}
if (col == nullptr) {
if (colNew == nullptr && col == nullptr) {
// collection not found
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
@ -269,25 +264,9 @@ static TRI_vocbase_col_t const* UseCollection(
/// @brief get all cluster collections
////////////////////////////////////////////////////////////////////////////////
static std::vector<TRI_vocbase_col_t*> GetCollectionsCluster(
static std::vector<std::shared_ptr<LogicalCollection>> GetCollectionsCluster(
TRI_vocbase_t* vocbase) {
std::vector<TRI_vocbase_col_t*> result;
std::vector<std::shared_ptr<CollectionInfo>> const collections =
ClusterInfo::instance()->getCollections(vocbase->name());
for (auto& collection : collections) {
TRI_vocbase_col_t* c = CoordinatorCollection(vocbase, *(collection));
try {
result.emplace_back(c);
} catch (...) {
delete c;
throw;
}
}
return result;
return ClusterInfo::instance()->getCollections(vocbase->name());
}
////////////////////////////////////////////////////////////////////////////////
@ -298,7 +277,7 @@ static std::vector<std::string> GetCollectionNamesCluster(
TRI_vocbase_t* vocbase) {
std::vector<std::string> result;
std::vector<std::shared_ptr<CollectionInfo>> const collections =
std::vector<std::shared_ptr<LogicalCollection>> const collections =
ClusterInfo::instance()->getCollections(vocbase->name());
for (auto& collection : collections) {
@ -1256,8 +1235,8 @@ static void JS_PropertiesVocbaseCol(
if (ServerState::instance()->isCoordinator()) {
std::string const databaseName(collection->dbName());
arangodb::VocbaseCollectionInfo info =
ClusterInfo::instance()->getCollectionProperties(
std::shared_ptr<LogicalCollection> info =
ClusterInfo::instance()->getCollection(
databaseName, StringUtils::itoa(collection->_cid));
if (0 < args.Length()) {
@ -1283,13 +1262,13 @@ static void JS_PropertiesVocbaseCol(
"<properties>.journalSize too small");
}
}
if (info.isVolatile() !=
if (info->isVolatile() !=
arangodb::basics::VelocyPackHelper::getBooleanValue(
slice, "isVolatile", info.isVolatile())) {
slice, "isVolatile", info->isVolatile())) {
TRI_V8_THROW_EXCEPTION_PARAMETER(
"isVolatile option cannot be changed at runtime");
}
if (info.isVolatile() && info.waitForSync()) {
if (info->isVolatile() && info->waitForSync()) {
TRI_V8_THROW_EXCEPTION_PARAMETER(
"volatile collections do not support the waitForSync option");
}
@ -1301,17 +1280,15 @@ static void JS_PropertiesVocbaseCol(
TRI_V8_THROW_EXCEPTION_PARAMETER(
"indexBuckets must be a two-power between 1 and 1024");
}
info.update(slice, false, collection->_vocbase);
}
int res = ClusterInfo::instance()->setCollectionPropertiesCoordinator(
databaseName, StringUtils::itoa(collection->_cid), &info);
int res = info->update(slice, false, collection->_vocbase);
if (res != TRI_ERROR_NO_ERROR) {
TRI_V8_THROW_EXCEPTION(res);
}
}
}
// return the current parameter set
v8::Handle<v8::Object> result = v8::Object::New(isolate);
@ -1320,29 +1297,28 @@ static void JS_PropertiesVocbaseCol(
TRI_GET_GLOBAL_STRING(IsVolatileKey);
TRI_GET_GLOBAL_STRING(JournalSizeKey);
TRI_GET_GLOBAL_STRING(WaitForSyncKey);
result->Set(DoCompactKey, v8::Boolean::New(isolate, info.doCompact()));
result->Set(IsSystemKey, v8::Boolean::New(isolate, info.isSystem()));
result->Set(IsVolatileKey, v8::Boolean::New(isolate, info.isVolatile()));
result->Set(JournalSizeKey, v8::Number::New(isolate, info.maximalSize()));
result->Set(WaitForSyncKey, v8::Boolean::New(isolate, info.waitForSync()));
result->Set(DoCompactKey, v8::Boolean::New(isolate, info->doCompact()));
result->Set(IsSystemKey, v8::Boolean::New(isolate, info->isSystem()));
result->Set(IsVolatileKey, v8::Boolean::New(isolate, info->isVolatile()));
result->Set(JournalSizeKey, v8::Number::New(isolate, info->journalSize()));
result->Set(WaitForSyncKey, v8::Boolean::New(isolate, info->waitForSync()));
result->Set(TRI_V8_ASCII_STRING("indexBuckets"),
v8::Number::New(isolate, info.indexBuckets()));
v8::Number::New(isolate, info->indexBuckets()));
std::shared_ptr<CollectionInfo> c = ClusterInfo::instance()->getCollection(
std::shared_ptr<LogicalCollection> c = ClusterInfo::instance()->getCollection(
databaseName, StringUtils::itoa(collection->_cid));
v8::Handle<v8::Array> shardKeys = v8::Array::New(isolate);
std::vector<std::string> const sks = (*c).shardKeys();
std::vector<std::string> const sks = c->shardKeys();
for (size_t i = 0; i < sks.size(); ++i) {
shardKeys->Set((uint32_t)i, TRI_V8_STD_STRING(sks[i]));
}
result->Set(TRI_V8_ASCII_STRING("shardKeys"), shardKeys);
result->Set(TRI_V8_ASCII_STRING("numberOfShards"),
v8::Number::New(isolate, (*c).numberOfShards()));
auto keyOpts = info.keyOptions();
if (keyOpts != nullptr && keyOpts->size() > 0) {
v8::Number::New(isolate, c->numberOfShards()));
auto keyOpts = info->keyOptions();
if (keyOpts.isObject() && keyOpts.length() > 0) {
TRI_GET_GLOBAL_STRING(KeyOptionsKey);
VPackSlice const slice(keyOpts->data());
result->Set(KeyOptionsKey, TRI_VPackToV8(isolate, slice)->ToObject());
result->Set(KeyOptionsKey, TRI_VPackToV8(isolate, keyOpts)->ToObject());
}
result->Set(
TRI_V8_ASCII_STRING("replicationFactor"),
@ -2377,11 +2353,11 @@ static void JS_StatusVocbaseCol(
if (ServerState::instance()->isCoordinator()) {
std::string const databaseName(collection->dbName());
std::shared_ptr<CollectionInfo> const ci =
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(
databaseName, StringUtils::itoa(collection->_cid));
if ((*ci).empty()) {
if (ci == nullptr) {
TRI_V8_RETURN(v8::Number::New(isolate, (int)TRI_VOC_COL_STATUS_DELETED));
}
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->status()));
@ -2548,11 +2524,11 @@ static void JS_TypeVocbaseCol(v8::FunctionCallbackInfo<v8::Value> const& args) {
if (ServerState::instance()->isCoordinator()) {
std::string const databaseName = collection->dbName();
std::shared_ptr<CollectionInfo> const ci =
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(
databaseName, StringUtils::itoa(collection->_cid));
if ((*ci).empty()) {
if (ci == nullptr) {
TRI_V8_RETURN(v8::Number::New(isolate, (int)collection->type()));
} else {
TRI_V8_RETURN(v8::Number::New(isolate, (int)ci->type()));
@ -2725,15 +2701,16 @@ static void JS_CollectionVocbase(
if (ServerState::instance()->isCoordinator()) {
std::string const name = TRI_ObjectToString(val);
std::shared_ptr<CollectionInfo> const ci =
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(vocbase->name(), name);
if ((*ci).id() == 0 || (*ci).empty()) {
if (ci == nullptr) {
// not found
TRI_V8_RETURN_NULL();
}
collection = CoordinatorCollection(vocbase, *ci);
// TODO collection has to be ci.
// collection = CoordinatorCollection(vocbase, *ci);
} else {
collection = GetCollectionFromArgument(vocbase, val);
}
@ -2768,11 +2745,13 @@ static void JS_CollectionsVocbase(
}
std::vector<TRI_vocbase_col_t*> colls;
#warning FIXME
std::vector<std::shared_ptr<LogicalCollection>> collsNew;
// if we are a coordinator, we need to fetch the collection info from the
// agency
if (ServerState::instance()->isCoordinator()) {
colls = GetCollectionsCluster(vocbase);
collsNew = ClusterInfo::instance()->getCollections(vocbase->name());
} else {
colls = vocbase->collections();
}

View File

@ -34,13 +34,6 @@
void ReleaseCollection(TRI_vocbase_col_t const* collection);
////////////////////////////////////////////////////////////////////////////////
/// @brief convert a collection info into a TRI_vocbase_col_t
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_col_t* CoordinatorCollection(TRI_vocbase_t* vocbase,
arangodb::CollectionInfo const& ci);
///////////////////////////////////////////////////////////////////////////////
/// @brief check if a name belongs to a collection
////////////////////////////////////////////////////////////////////////////////
@ -56,6 +49,11 @@ bool EqualCollection(arangodb::CollectionNameResolver const* resolver,
v8::Handle<v8::Object> WrapCollection(v8::Isolate* isolate,
TRI_vocbase_col_t const* collection);
/// @brief wraps a LogicalCollection
v8::Handle<v8::Object> WrapCollection(
v8::Isolate* isolate, arangodb::LogicalCollection const* collection);
void TRI_InitV8Collection(v8::Handle<v8::Context> context,
TRI_vocbase_t* vocbase, size_t const threadNumber,
TRI_v8_global_t* v8g, v8::Isolate* isolate,

View File

@ -1889,21 +1889,12 @@ static void MapGetVocBase(v8::Local<v8::String> const name,
}
if (ServerState::instance()->isCoordinator()) {
std::shared_ptr<CollectionInfo> const ci =
std::shared_ptr<LogicalCollection> const ci =
ClusterInfo::instance()->getCollection(vocbase->name(),
std::string(key));
if ((*ci).empty()) {
// TODO collection has to be ci
collection = nullptr;
} else {
collection = CoordinatorCollection(vocbase, *ci);
if (collection != nullptr && collection->_cid == 0) {
delete collection;
collection = nullptr;
TRI_V8_RETURN(v8::Handle<v8::Value>());
}
}
} else {
collection = vocbase->lookupCollection(std::string(key));
}

View File

@ -793,10 +793,10 @@ static void EnsureIndex(v8::FunctionCallbackInfo<v8::Value> const& args,
std::string const dbname(collection->dbName());
std::string const collname(collection->name());
std::shared_ptr<CollectionInfo> c =
std::shared_ptr<LogicalCollection> c =
ClusterInfo::instance()->getCollection(dbname, collname);
if (c->empty()) {
if (c == nullptr) {
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
}
@ -978,9 +978,9 @@ static void CreateCollectionCoordinator(
if (otherCid != 0) {
std::string otherCidString
= arangodb::basics::StringUtils::itoa(otherCid);
std::shared_ptr<CollectionInfo> collInfo =
std::shared_ptr<LogicalCollection> collInfo =
ci->getCollection(databaseName, otherCidString);
if (!collInfo->empty()) {
if (collInfo != nullptr) {
auto shards = collInfo->shardIds();
auto shardList = ci->getShardList(otherCidString);
for (auto const& s : *shardList) {
@ -1082,9 +1082,8 @@ static void CreateCollectionCoordinator(
}
ci->loadPlan();
std::shared_ptr<CollectionInfo> c = ci->getCollection(databaseName, cid);
TRI_vocbase_col_t* newcoll = CoordinatorCollection(vocbase, *c);
TRI_V8_RETURN(WrapCollection(isolate, newcoll));
std::shared_ptr<LogicalCollection> c = ci->getCollection(databaseName, cid);
TRI_V8_RETURN(WrapCollection(isolate, c.get()));
}
////////////////////////////////////////////////////////////////////////////////
@ -1242,10 +1241,10 @@ static void GetIndexesCoordinator(
std::string const cid = StringUtils::itoa(collection->_cid);
std::string const collectionName(collection->name());
std::shared_ptr<CollectionInfo> c =
std::shared_ptr<LogicalCollection> c =
ClusterInfo::instance()->getCollection(databaseName, cid);
if ((*c).empty()) {
if (c == nullptr) {
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
}

View File

@ -128,7 +128,6 @@ LogicalCollection::LogicalCollection(VPackSlice info)
_allowUserKeys(ReadBooleanValue(info, "allowUserKeys", true)),
_shardIds(new ShardMap()),
_physical(nullptr) {
// TODO read shard id map
if (info.isObject()) {
// Otherwise the cluster communication is broken.
// We cannot store anything further.
@ -149,13 +148,22 @@ LogicalCollection::LogicalCollection(VPackSlice info)
for (auto const& serverSlice : VPackArrayIterator(shardSlice.value)) {
servers.push_back(serverSlice.copyString());
}
(*_shardIds).emplace(shard, servers);
_shardIds->emplace(shard, servers);
}
}
}
}
}
LogicalCollection::~LogicalCollection() {
// TODO Do we have to free _physical
}
size_t LogicalCollection::journalSize() const {
// TODO FIXME should be part of physical collection
return 0;
}
// SECTION: Meta Information
TRI_voc_cid_t LogicalCollection::cid() const {
@ -279,3 +287,52 @@ void LogicalCollection::drop() {
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
_isDeleted = true;
}
void LogicalCollection::toVelocyPack(VPackBuilder& result) const {
result.openObject();
result.add("id", VPackValue(_cid));
result.add("name", VPackValue(_name));
result.add("status", VPackValue(_status));
result.add("deleted", VPackValue(_isDeleted));
result.add("doCompact", VPackValue(_doCompact));
result.add("isSystem", VPackValue(_isSystem));
result.add("isVolatile", VPackValue(_isVolatile));
result.add("waitForSync", VPackValue(_waitForSync));
result.add("keyOptions", VPackSlice(_keyOptions->data()));
result.add("indexBuckets", VPackValue(_indexBuckets));
result.add("indexes", VPackSlice(_indexes->data()));
result.add("replicationFactor", VPackValue(_replicationFactor));
result.add(VPackValue("shards"));
result.openObject();
for (auto const& shards : *_shardIds) {
result.add(VPackValue(shards.first));
result.openArray();
for (auto const& servers : shards.second) {
result.add(VPackValue(servers));
}
result.close(); // server array
}
result.close(); // shards
result.add("allowUserKeys", VPackValue(_allowUserKeys));
result.add(VPackValue("shardKeys"));
result.openArray();
for (auto const& key : _shardKeys) {
result.add(VPackValue(key));
}
result.close(); // shardKeys
result.close(); // Base Object
}
TRI_vocbase_t* LogicalCollection::vocbase() const {
return _vocbase;
}
int LogicalCollection::update(VPackSlice const&, bool, TRI_vocbase_t const*) {
#warning should be cluster aware
return TRI_ERROR_NOT_IMPLEMENTED;
/*
return ClusterInfo::instance()->setCollectionPropertiesCoordinator(
databaseName, StringUtils::itoa(collection->_cid), this);
*/
}

View File

@ -64,6 +64,9 @@ class LogicalCollection {
TRI_vocbase_col_status_e status() const;
std::string const statusString() const;
// TODO this should be part of physical collection!
size_t journalSize() const;
// SECTION: Properties
bool deleted() const;
bool doCompact() const;
@ -94,13 +97,21 @@ class LogicalCollection {
void rename(std::string const&);
void drop();
// SECTION: Serialisation
void toVelocyPack(arangodb::velocypack::Builder&) const;
TRI_vocbase_t* vocbase() const;
// Only Local
void updateCount(size_t);
// Path will be taken from physical
// Probably this can be handled internally only!
int saveToFile(bool) const;
void update(arangodb::velocypack::Slice const&, bool, TRI_vocbase_t const*);
void update(VocbaseCollectionInfo const&);
// Update this collection.
int update(arangodb::velocypack::Slice const&, bool, TRI_vocbase_t const*);
int update(VocbaseCollectionInfo const&);
PhysicalCollection* getPhysical() const;
@ -156,6 +167,8 @@ class LogicalCollection {
// the first one still has a valid copy
std::shared_ptr<ShardMap> _shardIds;
TRI_vocbase_t* _vocbase;
PhysicalCollection* _physical;
};
} // namespace arangodb

View File

@ -1626,37 +1626,6 @@ static std::string GetCollectionDirectory(std::string const& path, TRI_voc_cid_t
return arangodb::basics::FileUtils::buildFilename(path, filename);
}
VocbaseCollectionInfo::VocbaseCollectionInfo(CollectionInfo const& other)
: _version(TRI_COL_VERSION),
_type(other.type()),
_revision(0), // not known in the cluster case on the coordinator
_cid(other.id()), // this is on the coordinator and describes a
// cluster-wide collection, for safety reasons,
// we also set _cid
_planId(other.id()),
_maximalSize(other.journalSize()),
_initialCount(-1),
_indexBuckets(other.indexBuckets()),
_keyOptions(nullptr),
_isSystem(other.isSystem()),
_deleted(other.deleted()),
_doCompact(other.doCompact()),
_isVolatile(other.isVolatile()),
_waitForSync(other.waitForSync()) {
std::string const name = other.name();
memset(_name, 0, sizeof(_name));
memcpy(_name, name.c_str(), name.size());
VPackSlice keyOptionsSlice(other.keyOptions());
if (!keyOptionsSlice.isNone()) {
VPackBuilder builder;
builder.add(keyOptionsSlice);
_keyOptions = builder.steal();
}
}
VocbaseCollectionInfo::VocbaseCollectionInfo(TRI_vocbase_t* vocbase,
std::string const& name,
TRI_col_type_e type,

View File

@ -53,7 +53,6 @@
////////////////////////////////////////////////////////////////////////////////
namespace arangodb {
class CollectionInfo;
class EdgeIndex;
class Index;
class KeyGenerator;
@ -148,8 +147,6 @@ class VocbaseCollectionInfo {
VocbaseCollectionInfo() = default;
~VocbaseCollectionInfo() = default;
explicit VocbaseCollectionInfo(CollectionInfo const&);
VocbaseCollectionInfo(TRI_vocbase_t*, std::string const&, TRI_col_type_e,
TRI_voc_size_t, arangodb::velocypack::Slice const&);