1
0
Fork 0

refactoring

This commit is contained in:
jsteemann 2016-07-27 17:15:52 +02:00
parent c994b68ac4
commit 31407c3561
15 changed files with 129 additions and 192 deletions

View File

@ -282,7 +282,7 @@ bool State::createCollections() {
/// Check collection by name
bool State::checkCollection(std::string const& name) {
if (!_collectionsChecked) {
return (TRI_LookupCollectionByNameVocBase(_vocbase, name) != nullptr);
return (_vocbase->lookupCollection(name) != nullptr);
}
return true;
}

View File

@ -150,13 +150,8 @@ class CollectionInfo {
_slice, "status", (int)TRI_VOC_COL_STATUS_CORRUPTED);
}
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the collection status as a string
//////////////////////////////////////////////////////////////////////////////
std::string statusString() const {
return TRI_GetStatusStringCollectionVocBase(status());
}
std::string statusString() const { return TRI_vocbase_col_t::statusString(status()); }
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the deleted flag

View File

@ -755,7 +755,7 @@ int ContinuousSyncer::renameCollection(VPackSlice const& slice) {
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
return TRI_RenameCollectionVocBase(_vocbase, col, name, true, true);
return _vocbase->rename(col, name, true, true);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -342,12 +342,12 @@ TRI_vocbase_col_t* Syncer::getCollectionByIdOrName(TRI_voc_cid_t cid, std::strin
TRI_vocbase_col_t* nameCol = nullptr;
if (_useCollectionId) {
idCol = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
idCol = _vocbase->lookupCollection(cid);
}
if (!name.empty()) {
// try looking up the collection by name then
nameCol = TRI_LookupCollectionByNameVocBase(_vocbase, name);
nameCol = _vocbase->lookupCollection(name);
}
if (idCol != nullptr && nameCol != nullptr) {

View File

@ -959,7 +959,7 @@ void RestReplicationHandler::handleCommandLoggerFollow() {
std::string const& value6 = _request->value("collection", found);
if (found) {
TRI_vocbase_col_t* c = TRI_LookupCollectionByNameVocBase(_vocbase, value6);
TRI_vocbase_col_t* c = _vocbase->lookupCollection(value6);
if (c == nullptr) {
generateError(GeneralResponse::ResponseCode::NOT_FOUND,
@ -1154,8 +1154,8 @@ void RestReplicationHandler::handleCommandInventory() {
// collections and indexes
std::shared_ptr<VPackBuilder> collectionsBuilder;
try {
collectionsBuilder = TRI_InventoryCollectionsVocBase(
_vocbase, tick, &filterCollection, (void*)&includeSystem, true,
collectionsBuilder = _vocbase->inventory(
tick, &filterCollection, (void*)&includeSystem, true,
RestReplicationHandler::sortCollections);
VPackSlice const collections = collectionsBuilder->slice();
@ -1310,7 +1310,7 @@ int RestReplicationHandler::createCollection(VPackSlice const& slice,
TRI_vocbase_col_t* col = nullptr;
if (cid > 0) {
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
col = _vocbase->lookupCollection(cid);
}
if (col != nullptr && (TRI_col_type_t)col->_type == (TRI_col_type_t)type) {
@ -1557,12 +1557,12 @@ int RestReplicationHandler::processRestoreCollection(
TRI_voc_cid_t cid = StringUtils::uint64(tmp.c_str(), tmp.length());
// first look up the collection by the cid
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
col = _vocbase->lookupCollection(cid);
}
if (col == nullptr) {
// not found, try name next
col = TRI_LookupCollectionByNameVocBase(_vocbase, name);
col = _vocbase->lookupCollection(name);
}
// drop an existing collection if it exists
@ -2765,8 +2765,7 @@ void RestReplicationHandler::handleCommandCreateKeys() {
tickEnd = static_cast<TRI_voc_tick_t>(StringUtils::uint64(value));
}
TRI_vocbase_col_t* c =
TRI_LookupCollectionByNameVocBase(_vocbase, collection);
TRI_vocbase_col_t* c = _vocbase->lookupCollection(collection);
if (c == nullptr) {
generateError(GeneralResponse::ResponseCode::NOT_FOUND,
@ -3152,8 +3151,7 @@ void RestReplicationHandler::handleCommandDump() {
compat28 = StringUtils::boolean(value8);
}
TRI_vocbase_col_t* c =
TRI_LookupCollectionByNameVocBase(_vocbase, collection);
TRI_vocbase_col_t* c = _vocbase->lookupCollection(collection);
if (c == nullptr) {
generateError(GeneralResponse::ResponseCode::NOT_FOUND,
@ -3849,7 +3847,8 @@ void RestReplicationHandler::handleCommandAddFollower() {
return;
}
auto col = TRI_LookupCollectionByNameVocBase(_vocbase, shard.copyString());
auto col = _vocbase->lookupCollection(shard.copyString());
if (col == nullptr) {
generateError(GeneralResponse::ResponseCode::SERVER_ERROR,
TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND,
@ -3905,7 +3904,8 @@ void RestReplicationHandler::handleCommandRemoveFollower() {
return;
}
auto col = TRI_LookupCollectionByNameVocBase(_vocbase, shard.copyString());
auto col = _vocbase->lookupCollection(shard.copyString());
if (col == nullptr) {
generateError(GeneralResponse::ResponseCode::SERVER_ERROR,
TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND,
@ -3965,8 +3965,8 @@ void RestReplicationHandler::handleCommandHoldReadLockCollection() {
}
std::string id = idSlice.copyString();
auto col =
TRI_LookupCollectionByNameVocBase(_vocbase, collection.copyString());
auto col = _vocbase->lookupCollection(collection.copyString());
if (col == nullptr) {
generateError(GeneralResponse::ResponseCode::SERVER_ERROR,
TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND,

View File

@ -301,8 +301,7 @@ void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
collectionName = value.copyString();
if (!collectionName.empty()) {
auto const* col =
TRI_LookupCollectionByNameVocBase(_vocbase, collectionName);
auto const* col = _vocbase->lookupCollection(collectionName);
if (col != nullptr && collectionName.compare(col->_name) != 0) {
// user has probably passed in a numeric collection id.

View File

@ -89,8 +89,7 @@ void RestSimpleQueryHandler::allDocuments() {
std::string collectionName = value.copyString();
if (!collectionName.empty()) {
auto const* col =
TRI_LookupCollectionByNameVocBase(_vocbase, collectionName);
auto const* col = _vocbase->lookupCollection(collectionName);
if (col != nullptr && collectionName.compare(col->_name) != 0) {
// user has probably passed in a numeric collection id.

View File

@ -150,8 +150,7 @@ class CollectionNameResolver {
return (*it).second;
}
TRI_vocbase_col_t const* collection =
TRI_LookupCollectionByNameVocBase(_vocbase, name);
TRI_vocbase_col_t const* collection = _vocbase->lookupCollection(name);
if (collection != nullptr) {
_resolvedNames.emplace(name, collection);
@ -295,7 +294,7 @@ class CollectionNameResolver {
}
} else {
// exactly as in the non-cluster case
name = TRI_GetCollectionNameByIdVocBase(_vocbase, cid);
name = _vocbase->collectionName(cid);
}
if (name.empty()) {

View File

@ -1187,7 +1187,7 @@ static void JS_NameVocbaseCol(v8::FunctionCallbackInfo<v8::Value> const& args) {
// if we wouldn't do this, we would risk other threads modifying the name
// while
// we're reading it
std::string name(TRI_GetCollectionNameByIdVocBase(collection->_vocbase, collection->_cid));
std::string name(collection->_vocbase->collectionName(collection->_cid));
v8::Handle<v8::Value> result = TRI_V8_STD_STRING(name);
@ -1564,8 +1564,7 @@ static void JS_RenameVocbaseCol(
std::string const oldName(collection->_name);
int res = TRI_RenameCollectionVocBase(collection->_vocbase, collection,
name, doOverride, true);
int res = collection->_vocbase->rename(collection, name, doOverride, true);
if (res != TRI_ERROR_NO_ERROR) {
TRI_V8_THROW_EXCEPTION_MESSAGE(res, "cannot rename collection");
@ -2077,10 +2076,10 @@ static TRI_vocbase_col_t* GetCollectionFromArgument(
// number
if (val->IsNumber() || val->IsNumberObject()) {
uint64_t cid = TRI_ObjectToUInt64(val, true);
return TRI_LookupCollectionByIdVocBase(vocbase, cid);
return vocbase->lookupCollection(cid);
}
return TRI_LookupCollectionByNameVocBase(vocbase, TRI_ObjectToString(val));
return vocbase->lookupCollection(TRI_ObjectToString(val));
}
////////////////////////////////////////////////////////////////////////////////
@ -2752,7 +2751,7 @@ static void JS_CollectionsVocbase(
if (ServerState::instance()->isCoordinator()) {
colls = GetCollectionsCluster(vocbase);
} else {
colls = TRI_CollectionsVocBase(vocbase);
colls = vocbase->collections();
}
std::sort(colls.begin(), colls.end(), [](TRI_vocbase_col_t const* lhs, TRI_vocbase_col_t const* rhs) -> bool {
@ -2808,7 +2807,7 @@ static void JS_CompletionsVocbase(
names = GetCollectionNamesCluster(vocbase);
}
} else {
names = TRI_CollectionNamesVocBase(vocbase);
names = vocbase->collectionNames();
}
uint32_t j = 0;

View File

@ -562,7 +562,7 @@ static void JS_WaitCollectorWal(
std::string const name = TRI_ObjectToString(args[0]);
TRI_vocbase_col_t* col = TRI_LookupCollectionByNameVocBase(vocbase, name);
TRI_vocbase_col_t* col = vocbase->lookupCollection(name);
if (col == nullptr) {
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND);
@ -1905,7 +1905,7 @@ static void MapGetVocBase(v8::Local<v8::String> const name,
}
}
} else {
collection = TRI_LookupCollectionByNameVocBase(vocbase, std::string(key));
collection = vocbase->lookupCollection(std::string(key));
}
if (collection == nullptr) {

View File

@ -87,7 +87,7 @@ static char const* NameFromCid(TRI_replication_dump_t* dump,
}
// collection name not in cache yet
std::string name(TRI_GetCollectionNameByIdVocBase(dump->_vocbase, cid));
std::string name(dump->_vocbase->collectionName(cid));
if (!name.empty()) {
// insert into cache

View File

@ -462,8 +462,7 @@ static int UseCollections(TRI_transaction_t* trx, int nestingLevel) {
trx->_vocbase, trxCollection->_cid, status);
} else {
// use without usage-lock (lock already set externally)
trxCollection->_collection =
TRI_LookupCollectionByIdVocBase(trx->_vocbase, trxCollection->_cid);
trxCollection->_collection = trx->_vocbase->lookupCollection(trxCollection->_cid);
}
if (trxCollection->_collection == nullptr ||

View File

@ -1061,10 +1061,27 @@ std::shared_ptr<VPackBuilder> TRI_vocbase_col_t::toVelocyPackIndexes(
return builder;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief closes a database and all collections
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a translation of a collection status
char const* TRI_vocbase_col_t::statusString(TRI_vocbase_col_status_e status) {
switch (status) {
case TRI_VOC_COL_STATUS_UNLOADED:
return "unloaded";
case TRI_VOC_COL_STATUS_LOADED:
return "loaded";
case TRI_VOC_COL_STATUS_UNLOADING:
return "unloading";
case TRI_VOC_COL_STATUS_DELETED:
return "deleted";
case TRI_VOC_COL_STATUS_LOADING:
return "loading";
case TRI_VOC_COL_STATUS_CORRUPTED:
case TRI_VOC_COL_STATUS_NEW_BORN:
default:
return "unknown";
}
}
/// @brief closes a database and all collections
void TRI_DestroyVocBase(TRI_vocbase_t* vocbase) {
// stop replication
if (vocbase->_replicationApplier != nullptr) {
@ -1141,32 +1158,26 @@ void TRI_DestroyVocBase(TRI_vocbase_t* vocbase) {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns all known (document) collections
////////////////////////////////////////////////////////////////////////////////
std::vector<TRI_vocbase_col_t*> TRI_CollectionsVocBase(TRI_vocbase_t* vocbase) {
std::vector<TRI_vocbase_col_t*> TRI_vocbase_t::collections() {
std::vector<TRI_vocbase_col_t*> result;
READ_LOCKER(readLocker, vocbase->_collectionsLock);
READ_LOCKER(readLocker, _collectionsLock);
for (auto const& it : vocbase->_collectionsById) {
for (auto const& it : _collectionsById) {
result.emplace_back(it.second);
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns names of all known (document) collections
////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> TRI_CollectionNamesVocBase(TRI_vocbase_t* vocbase) {
std::vector<std::string> TRI_vocbase_t::collectionNames() {
std::vector<std::string> result;
READ_LOCKER(readLocker, vocbase->_collectionsLock);
READ_LOCKER(readLocker, _collectionsLock);
for (auto const& it : vocbase->_collectionsById) {
for (auto const& it : _collectionsById) {
result.emplace_back(it.second->name());
}
@ -1181,20 +1192,19 @@ std::vector<std::string> TRI_CollectionNamesVocBase(TRI_vocbase_t* vocbase) {
/// The list of collections will be sorted if sort function is given
////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<VPackBuilder> TRI_InventoryCollectionsVocBase(
TRI_vocbase_t* vocbase, TRI_voc_tick_t maxTick,
std::shared_ptr<VPackBuilder> TRI_vocbase_t::inventory(TRI_voc_tick_t maxTick,
bool (*filter)(TRI_vocbase_col_t*, void*), void* data, bool shouldSort,
std::function<bool(TRI_vocbase_col_t*, TRI_vocbase_col_t*)> sortCallback) {
std::vector<TRI_vocbase_col_t*> collections;
// cycle on write-lock
WRITE_LOCKER_EVENTUAL(writeLock, vocbase->_inventoryLock, 1000);
WRITE_LOCKER_EVENTUAL(writeLock, _inventoryLock, 1000);
// copy collection pointers into vector so we can work with the copy without
// the global lock
{
READ_LOCKER(readLocker, vocbase->_collectionsLock);
collections = vocbase->_collections;
READ_LOCKER(readLocker, _collectionsLock);
collections = _collections;
}
if (shouldSort && collections.size() > 1) {
@ -1231,52 +1241,23 @@ std::shared_ptr<VPackBuilder> TRI_InventoryCollectionsVocBase(
return builder;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a translation of a collection status
////////////////////////////////////////////////////////////////////////////////
char const* TRI_GetStatusStringCollectionVocBase(
TRI_vocbase_col_status_e status) {
switch (status) {
case TRI_VOC_COL_STATUS_UNLOADED:
return "unloaded";
case TRI_VOC_COL_STATUS_LOADED:
return "loaded";
case TRI_VOC_COL_STATUS_UNLOADING:
return "unloading";
case TRI_VOC_COL_STATUS_DELETED:
return "deleted";
case TRI_VOC_COL_STATUS_LOADING:
return "loading";
case TRI_VOC_COL_STATUS_CORRUPTED:
case TRI_VOC_COL_STATUS_NEW_BORN:
default:
return "unknown";
}
}
/// @brief gets a collection name by a collection id
/// the name is fetched under a lock to make this thread-safe.
/// returns empty string if the collection does not exist.
std::string TRI_GetCollectionNameByIdVocBase(TRI_vocbase_t* vocbase,
TRI_voc_cid_t id) {
READ_LOCKER(readLocker, vocbase->_collectionsLock);
std::string TRI_vocbase_t::collectionName(TRI_voc_cid_t id) {
READ_LOCKER(readLocker, _collectionsLock);
auto it = vocbase->_collectionsById.find(id);
auto it = _collectionsById.find(id);
if (it == vocbase->_collectionsById.end()) {
return "";
if (it == _collectionsById.end()) {
return StaticStrings::Empty;
}
return (*it).second->name();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief looks up a (document) collection by name
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_col_t* TRI_LookupCollectionByNameVocBase(TRI_vocbase_t* vocbase,
std::string const& name) {
TRI_vocbase_col_t* TRI_vocbase_t::lookupCollection(std::string const& name) {
if (name.empty()) {
return nullptr;
}
@ -1285,31 +1266,27 @@ TRI_vocbase_col_t* TRI_LookupCollectionByNameVocBase(TRI_vocbase_t* vocbase,
// function
// this is safe because collection names must not start with a digit
if (name[0] >= '0' && name[0] <= '9') {
return TRI_LookupCollectionByIdVocBase(vocbase, StringUtils::uint64(name));
return lookupCollection(StringUtils::uint64(name));
}
// otherwise we'll look up the collection by name
READ_LOCKER(readLocker, vocbase->_collectionsLock);
READ_LOCKER(readLocker, _collectionsLock);
auto it = vocbase->_collectionsByName.find(name);
auto it = _collectionsByName.find(name);
if (it == vocbase->_collectionsByName.end()) {
if (it == _collectionsByName.end()) {
return nullptr;
}
return (*it).second;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief looks up a (document) collection by identifier
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_col_t* TRI_LookupCollectionByIdVocBase(TRI_vocbase_t* vocbase,
TRI_voc_cid_t id) {
READ_LOCKER(readLocker, vocbase->_collectionsLock);
TRI_vocbase_col_t* TRI_vocbase_t::lookupCollection(TRI_voc_cid_t id) {
READ_LOCKER(readLocker, _collectionsLock);
auto it = vocbase->_collectionsById.find(id);
auto it = _collectionsById.find(id);
if (it == vocbase->_collectionsById.end()) {
if (it == _collectionsById.end()) {
return nullptr;
}
return (*it).second;
@ -1512,14 +1489,10 @@ int TRI_DropCollectionVocBase(TRI_vocbase_t* vocbase,
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief renames a (document) collection
////////////////////////////////////////////////////////////////////////////////
int TRI_RenameCollectionVocBase(TRI_vocbase_t* vocbase,
TRI_vocbase_col_t* collection,
std::string const& newName, bool doOverride,
bool writeMarker) {
/// @brief renames a collection
int TRI_vocbase_t::rename(TRI_vocbase_col_t* collection,
std::string const& newName, bool doOverride,
bool writeMarker) {
if (!collection->_canRename) {
return TRI_set_errno(TRI_ERROR_FORBIDDEN);
}
@ -1557,13 +1530,13 @@ int TRI_RenameCollectionVocBase(TRI_vocbase_t* vocbase,
}
}
READ_LOCKER(readLocker, vocbase->_inventoryLock);
READ_LOCKER(readLocker, _inventoryLock);
TRI_EVENTUAL_WRITE_LOCK_STATUS_VOCBASE_COL(collection);
int res = RenameCollection(vocbase, collection, oldName, newName);
TRI_WRITE_UNLOCK_STATUS_VOCBASE_COL(collection);
int res;
{
WRITE_LOCKER_EVENTUAL(locker, collection->_lock, 1000);
res = RenameCollection(this, collection, oldName, newName);
}
if (res == TRI_ERROR_NO_ERROR && writeMarker) {
// now log the operation
@ -1575,7 +1548,7 @@ int TRI_RenameCollectionVocBase(TRI_vocbase_t* vocbase,
builder.add("name", VPackValue(newName));
builder.close();
arangodb::wal::CollectionMarker marker(TRI_DF_MARKER_VPACK_RENAME_COLLECTION, vocbase->_id, collection->_cid, builder.slice());
arangodb::wal::CollectionMarker marker(TRI_DF_MARKER_VPACK_RENAME_COLLECTION, _id, collection->_cid, builder.slice());
arangodb::wal::SlotInfoCopy slotInfo =
arangodb::wal::LogfileManager::instance()->allocateAndWrite(marker, false);

View File

@ -310,9 +310,34 @@ struct TRI_vocbase_t {
getReplicationClients();
/// @brief returns whether the database is the system database
bool isSystem() {
return name() == TRI_VOC_SYSTEM_DATABASE;
}
bool isSystem() { return name() == TRI_VOC_SYSTEM_DATABASE; }
/// @brief returns all known collections
std::vector<TRI_vocbase_col_t*> collections();
/// @brief returns names of all known collections
std::vector<std::string> collectionNames();
/// @brief get a collection name by a collection id
/// the name is fetched under a lock to make this thread-safe.
/// returns empty string if the collection does not exist.
std::string collectionName(TRI_voc_cid_t id);
/// @brief looks up a collection by name
TRI_vocbase_col_t* lookupCollection(std::string const& name);
/// @brief looks up a collection by identifier
TRI_vocbase_col_t* lookupCollection(TRI_voc_cid_t id);
/// @brief returns all known collections with their parameters
/// and optionally indexes
/// the result is sorted by type and name (vertices before edges)
std::shared_ptr<arangodb::velocypack::Builder> inventory(
TRI_voc_tick_t, bool (*)(TRI_vocbase_col_t*, void*), void*,
bool, std::function<bool(TRI_vocbase_col_t*, TRI_vocbase_col_t*)>);
/// @brief renames a collection
int rename(TRI_vocbase_col_t* collection, std::string const& newName,
bool doOverride, bool writeMarker);
};
////////////////////////////////////////////////////////////////////////////////
@ -363,6 +388,11 @@ class TRI_vocbase_col_t {
bool canRename() const { return _canRename; }
public:
/// @brief returns a translation of a collection status
char const* statusString() const { return statusString(_status); }
static char const* statusString(TRI_vocbase_col_status_e status);
//////////////////////////////////////////////////////////////////////////////
/// @brief Transform the information for this collection to velocypack
//////////////////////////////////////////////////////////////////////////////
@ -424,34 +454,6 @@ class TRI_vocbase_col_t {
void TRI_DestroyVocBase(TRI_vocbase_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns all known collections
////////////////////////////////////////////////////////////////////////////////
std::vector<TRI_vocbase_col_t*> TRI_CollectionsVocBase(TRI_vocbase_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns names of all known collections
////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> TRI_CollectionNamesVocBase(TRI_vocbase_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns all known (document) collections with their parameters
/// and optionally indexes
/// The result is sorted by type and name (vertices before edges)
////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<arangodb::velocypack::Builder> TRI_InventoryCollectionsVocBase(
TRI_vocbase_t*, TRI_voc_tick_t, bool (*)(TRI_vocbase_col_t*, void*), void*,
bool, std::function<bool(TRI_vocbase_col_t*, TRI_vocbase_col_t*)>);
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a translation of a collection status
////////////////////////////////////////////////////////////////////////////////
char const* TRI_GetStatusStringCollectionVocBase(TRI_vocbase_col_status_e);
/// @brief adds a new collection
/// caller must hold _collectionsLock in write mode or set doLock
TRI_vocbase_col_t* TRI_AddCollectionVocBase(bool doLock,
@ -461,25 +463,6 @@ TRI_vocbase_col_t* TRI_AddCollectionVocBase(bool doLock,
TRI_voc_cid_t planId,
std::string const& path);
/// @brief get a collection name by a collection id
/// the name is fetched under a lock to make this thread-safe.
/// returns empty string if the collection does not exist.
std::string TRI_GetCollectionNameByIdVocBase(TRI_vocbase_t*, TRI_voc_cid_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief looks up a (document) collection by name
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_col_t* TRI_LookupCollectionByNameVocBase(TRI_vocbase_t* vocbase,
std::string const& name);
////////////////////////////////////////////////////////////////////////////////
/// @brief looks up a (document) collection by identifier
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_col_t* TRI_LookupCollectionByIdVocBase(TRI_vocbase_t* vocbase,
TRI_voc_cid_t cid);
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a new (document) collection from parameter set
////////////////////////////////////////////////////////////////////////////////
@ -500,13 +483,6 @@ int TRI_UnloadCollectionVocBase(TRI_vocbase_t*, TRI_vocbase_col_t*, bool);
int TRI_DropCollectionVocBase(TRI_vocbase_t*, TRI_vocbase_col_t*, bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief renames a (document) collection
////////////////////////////////////////////////////////////////////////////////
int TRI_RenameCollectionVocBase(TRI_vocbase_t*, TRI_vocbase_col_t*, std::string const&,
bool, bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief locks a (document) collection for usage, loading or manifesting it
///

View File

@ -576,7 +576,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
TRI_vocbase_col_t* collection = state->releaseCollection(collectionId);
if (collection == nullptr) {
collection = TRI_LookupCollectionByIdVocBase(vocbase, collectionId);
collection = vocbase->lookupCollection(collectionId);
}
if (collection == nullptr) {
@ -594,8 +594,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
std::string name = nameSlice.copyString();
// check if other collection exist with target name
TRI_vocbase_col_t* other =
TRI_LookupCollectionByNameVocBase(vocbase, name);
TRI_vocbase_col_t* other = vocbase->lookupCollection(name);
if (other != nullptr) {
TRI_voc_cid_t otherCid = other->_cid;
@ -603,8 +602,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
TRI_DropCollectionVocBase(vocbase, other, false);
}
int res =
TRI_RenameCollectionVocBase(vocbase, collection, name, true, false);
int res = vocbase->rename(collection, name, true, false);
if (res != TRI_ERROR_NO_ERROR) {
LOG(WARN) << "cannot rename collection " << collectionId << " in database " << databaseId << " to '" << name << "': " << TRI_errno_string(res);
@ -698,7 +696,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
return true;
}
TRI_vocbase_col_t* col = TRI_LookupCollectionByIdVocBase(vocbase, collectionId);
TRI_vocbase_col_t* col = vocbase->lookupCollection(collectionId);
if (col == nullptr) {
// if the underlying collection gone, we can go on
@ -769,7 +767,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
TRI_vocbase_col_t* collection = state->releaseCollection(collectionId);
if (collection == nullptr) {
collection = TRI_LookupCollectionByIdVocBase(vocbase, collectionId);
collection = vocbase->lookupCollection(collectionId);
}
if (collection != nullptr) {
@ -788,7 +786,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
if (nameSlice.isString()) {
name = nameSlice.copyString();
collection = TRI_LookupCollectionByNameVocBase(vocbase, name);
collection = vocbase->lookupCollection(name);
if (collection != nullptr) {
TRI_voc_cid_t otherCid = collection->_cid;
@ -934,7 +932,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
return true;
}
TRI_vocbase_col_t* col = TRI_LookupCollectionByIdVocBase(vocbase, collectionId);
TRI_vocbase_col_t* col = vocbase->lookupCollection(collectionId);
if (col == nullptr) {
// if the underlying collection gone, we can go on
@ -978,7 +976,7 @@ bool RecoverState::ReplayMarker(TRI_df_marker_t const* marker, void* data,
TRI_vocbase_col_t* collection = state->releaseCollection(collectionId);
if (collection == nullptr) {
collection = TRI_LookupCollectionByIdVocBase(vocbase, collectionId);
collection = vocbase->lookupCollection(collectionId);
}
if (collection != nullptr) {