You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
issue 511.4: ensure IResearchLink can be initialized without view as required for db-server, minor code fixes and cleanup (arangodb#7786)
* issue 511.4: ensure IResearchLink can be initialized without view as required for db-server, minor code fixes and cleanup
* remove unnessesary checks
* revert last change due to test failures
* fix typo in change revert
* try to address random test failures
} elseif (arangodb::ServerState::instance()->isDBServer()) { // db-server link
681
+
auto* engine = arangodb::ClusterInfo::instance();
661
682
662
-
if (!view) {
683
+
if (!engine) {
663
684
returnarangodb::Result(
664
-
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
665
-
std::string("error finding view: '") + viewId + "' for link '" + std::to_string(_id) + "'"
685
+
TRI_ERROR_INTERNAL,
686
+
std::string("failure to get storage engine while initializing arangosearch link '") + std::to_string(_id) + "'"
666
687
);
667
688
}
668
689
669
-
if (arangodb::ServerState::instance()->isDBServer()
670
-
&& _collection.id() == _collection.planId()
671
-
&& _collection.isAStub()) { // cluster cluster-wide link
672
-
auto shardIds = _collection.shardIds();
690
+
auto clusterWideLink = _collection.id() == _collection.planId() && _collection.isAStub(); // cluster cluster-wide link
673
691
674
-
// go through all shard IDs of the collection and try to link any links
675
-
// missing links will be populated when they are created in the per-shard collection
676
-
if (shardIds) {
677
-
for (auto& entry: *shardIds) {
678
-
auto collection = vocbase.lookupCollection(entry.first); // per-shard collections are always in 'vocbase'
692
+
if (!clusterWideLink) {
693
+
auto res = initDataStore(); // prepare data-store which can then update options via the IResearchView::link(...) call
679
694
680
-
if (!collection) {
681
-
continue; // missing collection should be created after Plan becomes Current
682
-
}
695
+
if (!res.ok()) {
696
+
return res;
697
+
}
698
+
}
699
+
700
+
auto logicalView = engine->getView(vocbase.name(), viewId); // valid to call ClusterInfo (initialized in ClusterFFeature::prepare()) even from Databasefeature::start()
701
+
702
+
// if there is no logicalView present yet then skip this step
703
+
if (logicalView) {
704
+
if (arangodb::iresearch::DATA_SOURCE_TYPE != logicalView->type()) {
705
+
unload(); // unlock the data store directory
706
+
returnarangodb::Result(
707
+
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
708
+
std::string("error finding view: '") + viewId + "' for link '" + std::to_string(_id) + "' : no such view"
std::string("error finding view: '") + viewId + "' for link '" + std::to_string(_id) + "'"
720
+
);
721
+
}
722
+
723
+
viewId = view->guid(); // ensue that this is a GUID (required by operator==(IResearchView))
724
+
725
+
if (clusterWideLink) { // cluster cluster-wide link
726
+
auto shardIds = _collection.shardIds();
727
+
728
+
// go through all shard IDs of the collection and try to link any links
729
+
// missing links will be populated when they are created in the per-shard collection
730
+
if (shardIds) {
731
+
for (auto& entry: *shardIds) {
732
+
auto collection = vocbase.lookupCollection(entry.first); // per-shard collections are always in 'vocbase'
733
+
734
+
if (!collection) {
735
+
continue; // missing collection should be created after Plan becomes Current
736
+
}
683
737
684
-
auto link = IResearchLinkHelper::find(*collection, *view);
738
+
auto link = IResearchLinkHelper::find(*collection, *view);
685
739
686
-
if (link && !view->link(link->self())) {
687
-
unload(); // unlock the directory
688
-
returnarangodb::Result(
689
-
TRI_ERROR_INTERNAL,
690
-
std::string("failed to link with view '") + view->name() + "' while initializing link '" + std::to_string(_id) + "', collection '" + collection->name() + "'"
691
-
);
740
+
if (link && !view->link(link->self())) {
741
+
returnarangodb::Result(
742
+
TRI_ERROR_INTERNAL,
743
+
std::string("failed to link with view '") + view->name() + "' while initializing link '" + std::to_string(_id) + "', collection '" + collection->name() + "'"
744
+
);
745
+
}
692
746
}
693
747
}
748
+
} else { // cluster per-shard link
749
+
if (!view->link(_asyncSelf)) {
750
+
unload(); // unlock the data store directory
751
+
returnarangodb::Result(
752
+
TRI_ERROR_INTERNAL,
753
+
std::string("failed to link with view '") + view->name() + "' while initializing link '" + std::to_string(_id) + "'"
754
+
);
755
+
}
694
756
}
695
-
}elseif (arangodb::ServerState::instance()->isSingleServer() // single-server link
696
-
|| arangodb::ServerState::instance()->isDBServer()) { //cluster per-shard link
697
-
auto res = initDataStore(*view);
757
+
}
758
+
} elseif (arangodb::ServerState::instance()->isSingleServer()) { //single-server link
759
+
auto res = initDataStore(); // prepare data-store which can then update options via the IResearchView::link(...) call
698
760
699
-
if (!res.ok()) {
700
-
return res;
761
+
if (!res.ok()) {
762
+
return res;
763
+
}
764
+
765
+
auto logicalView = vocbase.lookupView(viewId);
766
+
767
+
// if there is no logicalView present yet then skip this step
768
+
if (logicalView) {
769
+
if (arangodb::iresearch::DATA_SOURCE_TYPE != logicalView->type()) {
770
+
unload(); // unlock the data store directory
771
+
returnarangodb::Result(
772
+
TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND,
773
+
std::string("error finding view: '") + viewId + "' for link '" + std::to_string(_id) + "' : no such view"
0 commit comments