8000 Completely export views dump restore by maierlars · Pull Request #6466 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Completely export views dump restore< 8000 /bdi> #6466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added support setting links during view creation.
  • Loading branch information
lamai93 committed Sep 12, 2018
commit 5c841275304ec6256441f9cc9e7f8675ccde0687
1 change: 1 addition & 0 deletions arangod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ if (USE_IRESEARCH)
IResearch/IResearchViewNode.cpp IResearch/IResearchViewNode.h
IResearch/IResearchViewBlock.cpp IResearch/IResearchViewBlock.h
IResearch/IResearchViewMeta.cpp IResearch/IResearchViewMeta.h
IResearch/IResearchViewSingleServer.cpp IResearch/IResearchViewSingleServer.h
IResearch/IResearchFeature.cpp IResearch/IResearchFeature.h
IResearch/IResearchDocument.cpp IResearch/IResearchDocument.h
IResearch/IResearchFilterFactory.cpp IResearch/IResearchFilterFactory.h
Expand Down
5 changes: 3 additions & 2 deletions arangod/IResearch/IResearchFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "IResearchView.h"
#include "IResearchViewCoordinator.h"
#include "IResearchViewDBServer.h"
#include "IResearchViewSingleServer.h"
#include "Aql/AqlValue.h"
#include "Aql/AqlFunctionFeature.h"
#include "Aql/Function.h"
Expand Down Expand Up @@ -348,8 +349,8 @@ void registerViewFactory() {
res = viewTypes->emplace(viewType, arangodb::iresearch::IResearchViewCoordinator::make);
} else if (arangodb::ServerState::instance()->isDBServer()) {
res = viewTypes->emplace(viewType, arangodb::iresearch::IResearchViewDBServer::make);
} else {
res = viewTypes->emplace(viewType, arangodb::iresearch::IResearchView::make);
} else if (arangodb::ServerState::instance()->isSingleServer()) {
res = viewTypes->emplace(viewType, arangodb::iresearch::IResearchViewSingleServer::make);
}

if (!res.ok()) {
Expand Down
2 changes: 1 addition & 1 deletion arangod/IResearch/IResearchView.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class PrimaryKeyIndexReader: public irs::index_reader {
/// which may be, but are not explicitly required to be, triggered via
/// the IResearchLink or IResearchViewBlock
///////////////////////////////////////////////////////////////////////////////
class IResearchView final
class IResearchView
: public arangodb::LogicalViewStorageEngine,
public arangodb::FlushTransaction {
public:
Expand Down
74 changes: 72 additions & 2 deletions arangod/IResearch/IResearchViewCoordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,54 @@ bool IResearchViewCoordinator::emplace(
uint64_t planVersion,
LogicalView::PreCommitCallback const& preCommit
) {
auto& properties = info.isObject() ? info : emptyObjectSlice(); // if no 'info' then assume defaults
std::string error;

bool hasLinks = properties.hasKey("links");

auto view = std::shared_ptr<IResearchViewCoordinator>(
new IResearchViewCoordinator(vocbase, info, planVersion)
);
auto& properties = info.isObject() ? info : emptyObjectSlice(); // if no 'info' then assume defaults
std::string error;

if (hasLinks) {
auto* engine = arangodb::ClusterInfo::instance();

if (!engine) {
return nullptr;
}

// check link auth as per https://github.com/arangodb/backlog/issues/459
if (arangodb::ExecContext::CURRENT) {
// check existing links
for (auto& entry: view->_collections) {
auto collection =
engine->getCollection(vocbase.name(), std::to_string(entry.first));

if (collection
&& !arangodb::ExecContext::CURRENT->canUseCollection(vocbase.name(), collection->name(), arangodb::auth::Level::RO)) {
return nullptr;
}
}

// check new links
if (info.hasKey(StaticStrings::LinksField)) {
for (arangodb::velocypack::ObjectIterator itr(info.get(StaticStrings::LinksField)); itr.valid(); ++itr) {
if (!itr.key().isString()) {
continue; // not a resolvable collection (invalid jSON)
}

auto collection =
engine->getCollection(vocbase.name(), itr.key().copyString());

if (collection
&& !arangodb::ExecContext::CURRENT->canUseCollection(vocbase.name(), collection->name(), arangodb::auth::Level::RO)) {
return nullptr;
}
}
}
}
}


if (!view->_meta.init(properties, error)) {
TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
Expand Down Expand Up @@ -187,6 +230,33 @@ bool IResearchViewCoordinator::emplace(

return nullptr;
}

// create links - "on a best-effort basis"
if (info.hasKey("links")) {
arangodb::velocypack::Builder viewNewProperties;
viewNewProperties.openObject();
bool modified = false;
std::unordered_set<TRI_voc_cid_t> newCids;

std::unordered_set<TRI_voc_cid_t> currentCids;

auto result = updateLinks(
info.get("links"),
emptyObjectSlice(),
*view.get(),
false,
currentCids,
modified,
viewNewProperties,
newCids
);

if (result.fail()) {
TRI_set_errno(result.errorNumber());
LOG_TOPIC(ERR, arangodb::iresearch::TOPIC)
<< "Failure to construct links on new view in database '" << vocbase.id() << "', error: " << error;
}
}
}

return view;
Expand Down
111 changes: 111 additions & 0 deletions arangod/IResearch/IResearchViewSingleServer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2017 EMC Corporation
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is EMC Corporation
///
/// @author Lars Maier
////////////////////////////////////////////////////////////////////////////////

#include "IResearchCommon.h"
#include "IResearchDocument.h"
#include "IResearchFeature.h"
#include "IResearchFilterFactory.h"
#include "IResearchLink.h"
#include "IResearchLinkHelper.h"

#include "StorageEngine/TransactionState.h"
#include "StorageEngine/StorageEngine.h"
#include "RestServer/DatabaseFeature.h"
#include "RestServer/DatabasePathFeature.h"
#include "RestServer/FlushFeature.h"
#include "Transaction/Methods.h"
#include "Transaction/StandaloneContext.h"
#include "Utils/ExecContext.h"
#include "velocypack/Iterator.h"
#include "VocBase/LogicalCollection.h"
#include "VocBase/vocbase.h"
#include "VocBase/LogicalView.h"
#include "Logger/LogMacros.h"

#include "IResearchView.h"
#include "IResearchViewSingleServer.h"

namespace arangodb {
namespace iresearch {

/*static*/ std::shared_ptr<LogicalView> IResearchViewSingleServer::make(
TRI_vocbase_t& vocbase,
arangodb::velocypack::Slice const& info,
bool isNew,
uint64_t planVersion,
LogicalView::PreCommitCallback const& preCommit /*= {}*/
) {
auto& properties = info.isObject() ? info : emptyObjectSlice(); // if no 'info' then assume defaults
std::string error;

LOG_TOPIC(ERR, Logger::VIEWS) << "IResearchViewCoordinator::make info: " << info.toJson() << ", new: " << isNew;

bool hasLinks = properties.hasKey("links");

if (hasLinks && isNew) {

// check link auth as per https://github.com/arangodb/backlog/issues/459
if (arangodb::ExecContext::CURRENT) {

// check new links
if (info.hasKey(StaticStrings::LinksField)) {
for (arangodb::velocypack::ObjectIterator itr(info.get(StaticStrings::LinksField)); itr.valid(); ++itr) {
if (!itr.key().isString()) {
continue; // not a resolvable collection (invalid jSON)
}

9E88 auto collection= vocbase.lookupCollection(itr.key().copyString());

if (collection
&& !arangodb::ExecContext::CURRENT->canUseCollection(vocbase.name(), collection->name(), arangodb::auth::Level::RO)) {
return nullptr;
}
}
}
}
}

auto view = IResearchView::make(vocbase, info, isNew, planVersion, preCommit);

// create links - "on a best-effort basis"
if (properties.hasKey("links") && isNew) {

std::unordered_set<TRI_voc_cid_t> collections;
auto result = IResearchLinkHelper::updateLinks(
collections, vocbase, *view.get(), properties.get("links")
);

if (result.fail()) {
TRI_set_errno(result.errorNumber());
LOG_TOPIC(ERR, arangodb::iresearch::TOPIC)
<< "Failure to construct links on new view in database '" << vocbase.id() << "', error: " << error;
return nullptr;
}
}

return view;
}

}
}


57 changes: 57 additions & 0 deletions arangod/IResearch/IResearchViewSingleServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2018 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Lars Maier
////////////////////////////////////////////////////////////////////////////////

#ifndef ARANGODB_IRESEARCH__IRESEARCH_VIEW_SINGLE_SERVER_H
#define ARANGODB_IRESEARCH__IRESEARCH_VIEW_SINGLE_SERVER_H 1

#include "IResearchView.h"

#include <velocypack/Builder.h>
#include <velocypack/Slice.h>

namespace arangodb {
namespace iresearch {

///////////////////////////////////////////////////////////////////////////////
/// @class IResearchViewSingleServer
/// @brief an abstraction over the distributed IResearch index implementing the
/// LogicalView interface
///////////////////////////////////////////////////////////////////////////////
class IResearchViewSingleServer final {
public:
///////////////////////////////////////////////////////////////////////////////
/// @brief view factory
/// @returns initialized view object
///////////////////////////////////////////////////////////////////////////////
static std::shared_ptr<LogicalView> make(
TRI_vocbase_t& vocbase,
velocypack::Slice const& info,
bool isNew,
uint64_t planVersion,
LogicalView::PreCommitCallback const& preCommit
);
};

} // iresearch
} // arangodb

#endif // ARANGODB_IRESEARCH__IRESEARCH_VIEW_SINGLE_SERVER_H
0