1
0
Fork 0

issue 465.5: when renaming a datasource use the object from within vocbase (#6413)

This commit is contained in:
Vasiliy 2018-09-07 16:01:04 +03:00 committed by Andrey Abramov
parent 95345fff8f
commit b509e2e70a
7 changed files with 67 additions and 43 deletions

View File

@ -713,16 +713,18 @@ bool MMFilesWalRecoverState::ReplayMarker(MMFilesMarker const* marker,
} }
} }
int res = vocbase->renameCollection(collection, name, true); auto res = vocbase->renameCollection(collection->id(), name, true);
if (res != TRI_ERROR_NO_ERROR) { if (!res.ok()) {
LOG_TOPIC(WARN, arangodb::Logger::ENGINES) LOG_TOPIC(WARN, arangodb::Logger::ENGINES)
<< "cannot rename collection " << collectionId << " in database " << "cannot rename collection " << collectionId << " in database "
<< databaseId << " to '" << name << databaseId << " to '" << name
<< "': " << TRI_errno_string(res); << "': " << res.errorMessage();
++state->errorCount; ++state->errorCount;
return state->canContinue(); return state->canContinue();
} }
break; break;
} }
@ -835,10 +837,12 @@ bool MMFilesWalRecoverState::ReplayMarker(MMFilesMarker const* marker,
bool const forceSync = state->willViewBeDropped(databaseId, viewId); bool const forceSync = state->willViewBeDropped(databaseId, viewId);
VPackSlice nameSlice = payloadSlice.get("name"); VPackSlice nameSlice = payloadSlice.get("name");
if (nameSlice.isString() && !nameSlice.isEqualString(view->name())) { if (nameSlice.isString() && !nameSlice.isEqualString(view->name())) {
std::string name = nameSlice.copyString(); std::string name = nameSlice.copyString();
// check if other view exists with target name // check if other view exists with target name
std::shared_ptr<arangodb::LogicalView> other = vocbase->lookupView(name); std::shared_ptr<arangodb::LogicalView> other = vocbase->lookupView(name);
if (other != nullptr) { if (other != nullptr) {
if (other->id() == view->id()) { if (other->id() == view->id()) {
LOG_TOPIC(TRACE, arangodb::Logger::ENGINES) LOG_TOPIC(TRACE, arangodb::Logger::ENGINES)
@ -848,13 +852,16 @@ bool MMFilesWalRecoverState::ReplayMarker(MMFilesMarker const* marker,
} }
vocbase->dropView(other->id(), true); vocbase->dropView(other->id(), true);
} }
int res = vocbase->renameView(view, name);
if (res != TRI_ERROR_NO_ERROR) { auto res = vocbase->renameView(view->id(), name);
if (!res.ok()) {
LOG_TOPIC(WARN, arangodb::Logger::ENGINES) LOG_TOPIC(WARN, arangodb::Logger::ENGINES)
<< "cannot rename view " << viewId << " in database " << "cannot rename view " << viewId << " in database "
<< databaseId << " to '" << name << databaseId << " to '" << name
<< "': " << TRI_errno_string(res); << "': " << res.errorMessage();
++state->errorCount; ++state->errorCount;
return state->canContinue(); return state->canContinue();
} }
} }

View File

@ -632,7 +632,7 @@ Result TailingSyncer::renameCollection(VPackSlice const& slice) {
<< "Renaming system collection " << col->name(); << "Renaming system collection " << col->name();
} }
return Result(vocbase->renameCollection(col, name, true)); return vocbase->renameCollection(col->id(), name, true);
} }
/// @brief changes the properties of a collection, /// @brief changes the properties of a collection,
@ -736,6 +736,7 @@ Result TailingSyncer::changeView(VPackSlice const& slice) {
} }
VPackSlice data = slice.get("data"); VPackSlice data = slice.get("data");
if (!data.isObject()) { if (!data.isObject()) {
return Result(TRI_ERROR_REPLICATION_INVALID_RESPONSE, return Result(TRI_ERROR_REPLICATION_INVALID_RESPONSE,
"data slice is no object in view change marker"); "data slice is no object in view change marker");
@ -745,6 +746,7 @@ Result TailingSyncer::changeView(VPackSlice const& slice) {
bool const isDeleted = (d.isBool() && d.getBool()); bool const isDeleted = (d.isBool() && d.getBool());
TRI_vocbase_t* vocbase = resolveVocbase(slice); TRI_vocbase_t* vocbase = resolveVocbase(slice);
if (vocbase == nullptr) { if (vocbase == nullptr) {
if (isDeleted) { if (isDeleted) {
// not a problem if a view that is going to be deleted anyway // not a problem if a view that is going to be deleted anyway
@ -755,34 +757,42 @@ Result TailingSyncer::changeView(VPackSlice const& slice) {
} }
VPackSlice guidSlice = data.get(StaticStrings::DataSourceGuid); VPackSlice guidSlice = data.get(StaticStrings::DataSourceGuid);
if (!guidSlice.isString() || guidSlice.getStringLength() == 0) { if (!guidSlice.isString() || guidSlice.getStringLength() == 0) {
return Result(TRI_ERROR_REPLICATION_INVALID_RESPONSE, return Result(TRI_ERROR_REPLICATION_INVALID_RESPONSE,
"no guid specified for view"); "no guid specified for view");
} }
auto view = vocbase->lookupView(guidSlice.copyString()); auto view = vocbase->lookupView(guidSlice.copyString());
if (view == nullptr) { if (view == nullptr) {
if (isDeleted) { if (isDeleted) {
// not a problem if a collection that is going to be deleted anyway // not a problem if a collection that is going to be deleted anyway
// does not exist on slave // does not exist on slave
return Result(); return Result();
} }
return Result(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND); return Result(TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
} }
VPackSlice nameSlice = data.get(StaticStrings::DataSourceName); VPackSlice nameSlice = data.get(StaticStrings::DataSourceName);
if (nameSlice.isString() && !nameSlice.isEqualString(view->name())) { if (nameSlice.isString() && !nameSlice.isEqualString(view->name())) {
int res = vocbase->renameView(view, nameSlice.copyString()); auto res = vocbase->renameView(view->id(), nameSlice.copyString());
if (res != TRI_ERROR_NO_ERROR) {
if (!res.ok()) {
return res; return res;
} }
} }
VPackSlice properties = data.get("properties"); VPackSlice properties = data.get("properties");
if (properties.isObject()) { if (properties.isObject()) {
bool doSync = DatabaseFeature::DATABASE->forceSyncProperties(); bool doSync = DatabaseFeature::DATABASE->forceSyncProperties();
return view->updateProperties(properties, false, doSync); return view->updateProperties(properties, false, doSync);
} }
return {}; return {};
} }

View File

@ -303,12 +303,12 @@ void RestViewHandler::modifyView(bool partialUpdate) {
} }
auto newNameStr = newName.copyString(); auto newNameStr = newName.copyString();
int res = _vocbase.renameView(view, newNameStr); auto res = _vocbase.renameView(view->id(), newNameStr);
if (res == TRI_ERROR_NO_ERROR) { if (res.ok()) {
getView(newNameStr, false); getView(newNameStr, false);
} else { } else {
generateError(GeneralResponse::responseCode(res), res); generateError(res);
} }
return; return;

View File

@ -650,14 +650,10 @@ static void JS_RenameViewVocbase(
TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); // skip view TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); // skip view
} }
// need to get the sharedPtr from the vocbase auto res = view->vocbase().renameView(view->id(), name);
arangodb::CollectionNameResolver resolver(view->vocbase());
auto viewPtr = resolver.getView(view->id());
int res = view->vocbase().renameView(viewPtr, name); if (!res.ok()) {
TRI_V8_THROW_EXCEPTION(res);
if (res != TRI_ERROR_NO_ERROR) {
TRI_V8_THROW_EXCEPTION_MESSAGE(res, "cannot rename view");
} }
TRI_V8_RETURN_UNDEFINED(); TRI_V8_RETURN_UNDEFINED();

View File

@ -481,10 +481,10 @@ Result Collections::rename(LogicalCollection* coll, std::string const& newName,
} }
std::string const oldName(coll->name()); std::string const oldName(coll->name());
int res = coll->vocbase().renameCollection(coll, newName, doOverride); auto res = coll->vocbase().renameCollection(coll->id(), newName, doOverride);
if (res != TRI_ERROR_NO_ERROR) { if (!res.ok()) {
return Result(res, "cannot rename collection"); return res;
} }
// rename collection inside _graphs as well // rename collection inside _graphs as well

View File

@ -1303,7 +1303,7 @@ arangodb::Result TRI_vocbase_t::dropCollection(
bool allowDropSystem, bool allowDropSystem,
double timeout double timeout
) { ) {
auto* collection = lookupCollection(cid).get(); auto collection = lookupCollection(cid);
if (!collection) { if (!collection) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND; return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
@ -1328,7 +1328,7 @@ arangodb::Result TRI_vocbase_t::dropCollection(
int res; int res;
{ {
READ_LOCKER(readLocker, _inventoryLock); READ_LOCKER(readLocker, _inventoryLock);
res = dropCollectionWorker(collection, state, timeout); res = dropCollectionWorker(collection.get(), state, timeout);
} }
if (state == DROP_PERFORM) { if (state == DROP_PERFORM) {
@ -1356,10 +1356,16 @@ arangodb::Result TRI_vocbase_t::dropCollection(
} }
/// @brief renames a view /// @brief renames a view
int TRI_vocbase_t::renameView( arangodb::Result TRI_vocbase_t::renameView(
std::shared_ptr<arangodb::LogicalView> const& view, TRI_voc_cid_t cid,
std::string const& newName std::string const& newName
) { ) {
auto const view = lookupView(cid);
if (!view) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
// lock collection because we are going to copy its current name // lock collection because we are going to copy its current name
std::string oldName = view->name(); std::string oldName = view->name();
@ -1422,11 +1428,17 @@ int TRI_vocbase_t::renameView(
} }
/// @brief renames a collection /// @brief renames a collection
int TRI_vocbase_t::renameCollection( arangodb::Result TRI_vocbase_t::renameCollection(
arangodb::LogicalCollection* collection, TRI_voc_cid_t cid,
std::string const& newName, std::string const& newName,
bool doOverride bool doOverride
) { ) {
auto collection = lookupCollection(cid);
if (!collection) {
return TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND;
}
if (collection->system()) { if (collection->system()) {
return TRI_set_errno(TRI_ERROR_FORBIDDEN); return TRI_set_errno(TRI_ERROR_FORBIDDEN);
} }
@ -1520,11 +1532,10 @@ int TRI_vocbase_t::renameCollection(
return res.errorNumber(); // rename failed return res.errorNumber(); // rename failed
} }
auto col = std::static_pointer_cast<arangodb::LogicalCollection>(itr1->second); // cast validated above
auto* engine = EngineSelectorFeature::ENGINE; auto* engine = EngineSelectorFeature::ENGINE;
TRI_ASSERT(engine); TRI_ASSERT(engine);
res = engine->renameCollection(*this, *col, oldName); // tell the engine res = engine->renameCollection(*this, *collection, oldName); // tell the engine
if (!res.ok()) { if (!res.ok()) {
return res.errorNumber(); // rename failed return res.errorNumber(); // rename failed

View File

@ -325,15 +325,15 @@ struct TRI_vocbase_t {
) const; ) const;
/// @brief renames a collection /// @brief renames a collection
int renameCollection( arangodb::Result renameCollection(
arangodb::LogicalCollection* collection, TRI_voc_cid_t cid,
std::string const& newName, std::string const& newName,
bool doOverride bool doOverride
); );
/// @brief renames a view /// @brief renames a view
int renameView( arangodb::Result renameView(
std::shared_ptr<arangodb::LogicalView> const& view, TRI_voc_cid_t cid,
std::string const& newName std::string const& newName
); );