mirror of https://gitee.com/bigwinds/arangodb
match collections by either id or name
This commit is contained in:
parent
f2c13546dd
commit
91f806ef2b
|
@ -489,17 +489,12 @@ int ContinuousSyncer::processDocument(TRI_replication_operation_e type,
|
|||
std::string const cnameString = cname.copyString();
|
||||
isSystem = (!cnameString.empty() && cnameString[0] == '_');
|
||||
|
||||
if (!cnameString.empty()) {
|
||||
TRI_vocbase_col_t* col = nullptr;
|
||||
if (_useCollectionId) {
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, cnameString.c_str());
|
||||
}
|
||||
TRI_vocbase_col_t* col = getCollectionByIdOrName(cid, cnameString);
|
||||
|
||||
if (col != nullptr && col->_cid != cid) {
|
||||
// cid change? this may happen for system collections or if we restored
|
||||
// from a dump
|
||||
cid = col->_cid;
|
||||
}
|
||||
if (col != nullptr && col->_cid != cid) {
|
||||
// cid change? this may happen for system collections or if we restored
|
||||
// from a dump
|
||||
cid = col->_cid;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -753,14 +748,7 @@ int ContinuousSyncer::renameCollection(VPackSlice const& slice) {
|
|||
}
|
||||
|
||||
TRI_voc_cid_t const cid = getCid(slice);
|
||||
TRI_vocbase_col_t* col = nullptr;
|
||||
if (_useCollectionId) {
|
||||
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (col == nullptr && !cname.empty()) {
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, cname.c_str());
|
||||
}
|
||||
TRI_vocbase_col_t* col = getCollectionByIdOrName(cid, cname);
|
||||
|
||||
if (col == nullptr) {
|
||||
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||
|
@ -781,19 +769,8 @@ int ContinuousSyncer::changeCollection(VPackSlice const& slice) {
|
|||
|
||||
TRI_voc_cid_t cid = getCid(slice);
|
||||
std::string const cname = getCName(slice);
|
||||
TRI_vocbase_col_t* col = nullptr;
|
||||
TRI_vocbase_col_t* col = getCollectionByIdOrName(cid, cname);
|
||||
|
||||
if (col == nullptr) {
|
||||
TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (col == nullptr && !cname.empty()) {
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, cname.c_str());
|
||||
if (col != nullptr) {
|
||||
cid = col->_cid;
|
||||
}
|
||||
}
|
||||
|
||||
if (col == nullptr) {
|
||||
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||
}
|
||||
|
|
|
@ -1705,15 +1705,7 @@ int InitialSyncer::handleCollection(VPackSlice const& parameters,
|
|||
if (phase == PHASE_DROP_CREATE) {
|
||||
if (!incremental) {
|
||||
// first look up the collection by the cid
|
||||
TRI_vocbase_col_t* col = nullptr;
|
||||
if (_useCollectionId) {
|
||||
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (col == nullptr && !masterName.empty()) {
|
||||
// not found, try name next
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, masterName);
|
||||
}
|
||||
TRI_vocbase_col_t* col = getCollectionByIdOrName(cid, masterName);
|
||||
|
||||
if (col != nullptr) {
|
||||
bool truncate = false;
|
||||
|
@ -1777,14 +1769,7 @@ int InitialSyncer::handleCollection(VPackSlice const& parameters,
|
|||
TRI_vocbase_col_t* col = nullptr;
|
||||
|
||||
if (incremental) {
|
||||
if (_useCollectionId) {
|
||||
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (col == nullptr && !masterName.empty()) {
|
||||
// not found, try name next
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, masterName);
|
||||
}
|
||||
col = getCollectionByIdOrName(cid, masterName);
|
||||
|
||||
if (col != nullptr) {
|
||||
// collection is already present
|
||||
|
@ -1817,15 +1802,7 @@ int InitialSyncer::handleCollection(VPackSlice const& parameters,
|
|||
std::string const progress = "dumping data for " + collectionMsg;
|
||||
setProgress(progress.c_str());
|
||||
|
||||
TRI_vocbase_col_t* col = nullptr;
|
||||
if (_useCollectionId) {
|
||||
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (col == nullptr && !masterName.empty()) {
|
||||
// not found, try name next
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, masterName);
|
||||
}
|
||||
TRI_vocbase_col_t* col = getCollectionByIdOrName(cid, masterName);
|
||||
|
||||
if (col == nullptr) {
|
||||
errorMsg = "cannot dump: " + collectionMsg + " not found";
|
||||
|
|
|
@ -333,6 +333,48 @@ std::string Syncer::getCName(VPackSlice const& slice) const {
|
|||
return arangodb::basics::VelocyPackHelper::getStringValue(slice, "cname", "");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief extract the collection by either id or name, may return nullptr!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_vocbase_col_t* Syncer::getCollectionByIdOrName(TRI_voc_cid_t cid, std::string const& name) {
|
||||
TRI_vocbase_col_t* idCol = nullptr;
|
||||
TRI_vocbase_col_t* nameCol = nullptr;
|
||||
|
||||
if (_useCollectionId) {
|
||||
idCol = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (!name.empty()) {
|
||||
// try looking up the collection by name then
|
||||
nameCol = TRI_LookupCollectionByNameVocBase(_vocbase, name);
|
||||
}
|
||||
|
||||
if (idCol != nullptr && nameCol != nullptr) {
|
||||
if (idCol->cid() == nameCol->cid()) {
|
||||
// found collection by id and name, and both are identical!
|
||||
return idCol;
|
||||
}
|
||||
// found different collections by id and name
|
||||
TRI_ASSERT(!name.empty());
|
||||
if (name[0] == '_') {
|
||||
// system collection. always return collection by name when in doubt
|
||||
return nameCol;
|
||||
}
|
||||
|
||||
// no system collection. still prefer local collection
|
||||
return nameCol;
|
||||
}
|
||||
|
||||
if (nameCol != nullptr) {
|
||||
TRI_ASSERT(idCol == nullptr);
|
||||
return nameCol;
|
||||
}
|
||||
|
||||
// may be nullptr
|
||||
return idCol;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief apply the data from a collection dump or the continuous log
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -440,15 +482,7 @@ int Syncer::createCollection(VPackSlice const& slice, TRI_vocbase_col_t** dst) {
|
|||
TRI_col_type_e const type = static_cast<TRI_col_type_e>(VelocyPackHelper::getNumericValue<int>(
|
||||
slice, "type", static_cast<int>(TRI_COL_TYPE_DOCUMENT)));
|
||||
|
||||
TRI_vocbase_col_t* col = nullptr;
|
||||
if (_useCollectionId) {
|
||||
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (col == nullptr) {
|
||||
// try looking up the collection by name then
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, name);
|
||||
}
|
||||
TRI_vocbase_col_t* col = getCollectionByIdOrName(cid, name);
|
||||
|
||||
if (col != nullptr && static_cast<TRI_col_type_t>(col->_type) == static_cast<TRI_col_type_t>(type)) {
|
||||
// collection already exists. TODO: compare attributes
|
||||
|
@ -483,19 +517,7 @@ int Syncer::createCollection(VPackSlice const& slice, TRI_vocbase_col_t** dst) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Syncer::dropCollection(VPackSlice const& slice, bool reportError) {
|
||||
TRI_voc_cid_t const cid = getCid(slice);
|
||||
TRI_vocbase_col_t* col = nullptr;
|
||||
|
||||
if (_useCollectionId) {
|
||||
col = TRI_LookupCollectionByIdVocBase(_vocbase, cid);
|
||||
}
|
||||
|
||||
if (col == nullptr) {
|
||||
std::string cname = getCName(slice);
|
||||
if (!cname.empty()) {
|
||||
col = TRI_LookupCollectionByNameVocBase(_vocbase, cname);
|
||||
}
|
||||
}
|
||||
TRI_vocbase_col_t* col = getCollectionByIdOrName(getCid(slice), getCName(slice));
|
||||
|
||||
if (col == nullptr) {
|
||||
if (reportError) {
|
||||
|
|
|
@ -120,6 +120,12 @@ class Syncer {
|
|||
|
||||
std::string getCName(arangodb::velocypack::Slice const&) const;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief extract the collection by either id or name, may return nullptr!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_vocbase_col_t* getCollectionByIdOrName(TRI_voc_cid_t cid, std::string const& name);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief apply a single marker from the collection dump
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue