8000 fix cluster index selectivity (#6467) · arangodb/arangodb@3b16913 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b16913

Browse files
authored
fix cluster index selectivity (#6467)
1 parent ffdd1a0 commit 3b16913

File tree

8 files changed

+26
-13
lines changed

8 files changed

+26
-13
lines changed

arangod/Cluster/ClusterInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void ClusterInfo::loadPlan() {
762762
LOG_TOPIC(TRACE, Logger::CLUSTER) << "copy index estimates";
763763
newCollection->clusterIndexEstimates(std::move(selectivity));
764764
newCollection->clusterIndexEstimatesTTL(selectivityTTL);
765-
for(std::shared_ptr<Index>& idx : newCollection->getIndexes()){
765+
for (std::shared_ptr<Index>& idx : newCollection->getIndexes()) {
766766
auto it = selectivity.find(std::to_string(idx->id()));
767767
if (it != selectivity.end()) {
768768
idx->updateClusterSelectivityEstimate(it->second);

arangod/Cluster/ClusterMethods.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,10 +1028,10 @@ int selectivityEstimatesOnCoordinator(
10281028

10291029
if (answer.isObject()) {
10301030
// add to the total
1031-
for(auto const& identifier : VPackObjectIterator(answer.get("identifiers"))){
1032-
if(identifier.value.hasKey("selectivityEstimate")) {
1031+
for (auto const& identifier : VPackObjectIterator(answer.get("identifiers"))) {
1032+
if (identifier.value.hasKey("selectivityEstimate")) {
10331033
StringRef shard_index_id(identifier.key);
1034-
auto split_point = std::find(shard_index_id.begin(), shard_index_id.end(),'/');
1034+
auto split_point = std::find(shard_index_id.begin(), shard_index_id.end(), '/');
10351035
std::string index(split_point + 1, shard_index_id.end());
10361036

10371037
double estimate = arangodb::basics::VelocyPackHelper::getNumericValue(

arangod/Graph/BaseOptions.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ double BaseOptions::LookupInfo::estimateCost(size_t& nrItems) const {
151151
TRI_ASSERT(!idxHandles.empty());
152152
std::shared_ptr<Index> idx = idxHandles[0].getIndex();
153153
if (idx->hasSelectivityEstimate()) {
154-
double expected = 1 / idx->selectivityEstimate();
155-
nrItems += static_cast<size_t>(expected);
156-
return expected;
154+
double s = idx->selectivityEstimate();
155+
if (s > 0.0) {
156+
double expected = 1 / s;
157+
nrItems += static_cast<size_t>(expected);
158+
return expected;
159+
}
157160
}
158161
// Some hard-coded value
159162
nrItems += 1000;

arangod/Indexes/Index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Index {
255255
arangodb::StringRef const* extra = nullptr) const;
256256

257257
/// @brief update the cluster selectivity estimate
258-
virtual void updateClusterSelectivityEstimate(double estimate = 0.1) {
258+
virtual void updateClusterSelectivityEstimate(double /*estimate*/) {
259259
TRI_ASSERT(false); // should never be called except on Coordinator
260260
}
261261

arangod/Transaction/Methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3372,7 +3372,7 @@ transaction::Methods::indexesForCollectionCoordinator(
33723372
auto selectivity = collection->clusterIndexEstimates();
33733373

33743374
// push updated values into indexes
3375-
for(std::shared_ptr<Index>& idx : indexes){
3375+
for(std::shared_ptr<Index>& idx : indexes) {
33763376
auto it = selectivity.find(std::to_string(idx->id()));
33773377
if (it != selectivity.end()) {
33783378
idx->updateClusterSelectivityEstimate(it->second);

arangod/VocBase/LogicalCollection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ std::unordered_map<std::string, double> LogicalCollection::clusterIndexEstimates
429429

430430
double ctime = TRI_microtime(); // in seconds
431431
auto needEstimateUpdate = [this, ctime]() {
432-
if(_clusterEstimates.empty()) {
432+
if (_clusterEstimates.empty()) {
433433
LOG_TOPIC(TRACE, Logger::CLUSTER) << "update because estimate is not available";
434434
return true;
435435
} else if (ctime - _clusterEstimateTTL > 60.0) {

arangod/VocBase/Methods/Indexes.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ arangodb::Result Indexes::getAll(LogicalCollection const* collection,
114114
return Result(rv, "could not retrieve estimates");
115115
}
116116

117+
// we will merge in the index estimates later
118+
flags &= ~ Index::makeFlags(Index::Serialize::Estimates);
119+
117120
VPackBuilder tmpInner;
118121
auto c = ClusterInfo::instance()->getCollection(databaseName, cid);
119122
#ifdef USE_IRESEARCH
@@ -129,7 +132,7 @@ arangodb::Result Indexes::getAll(LogicalCollection const* collection,
129132
auto id = StringRef(s.get("id"));
130133
auto found = std::find_if(estimates.begin(),
131134
estimates.end(),
132-
[&id](std::pair<std::string,double> const& v){
135+
[&id](std::pair<std::string,double> const& v) {
133136
return id == v.first;
134137
}
135138
);
@@ -451,6 +454,10 @@ Result Indexes::ensureIndex(LogicalCollection* collection,
451454
return Result(create ? TRI_ERROR_OUT_OF_MEMORY
452455
: TRI_ERROR_ARANGO_INDEX_NOT_FOUND);
453456
}
457+
458+
// flush estimates
459+
collection->clusterIndexEstimatesTTL(0.0);
460+
454461
// the cluster won't set a proper id value
455462
std::string iid = tmp.slice().get("id").copyString();
456463
VPackBuilder b;
@@ -573,7 +580,7 @@ Result Indexes::extractHandle(arangodb::LogicalCollection const* collection,
573580
return Result();
574581
}
575582

576-
arangodb::Result Indexes::drop(LogicalCollection const* collection,
583+
arangodb::Result Indexes::drop(LogicalCollection* collection,
577584
VPackSlice const& indexArg) {
578585
if (ExecContext::CURRENT != nullptr) {
579586
if (ExecContext::CURRENT->databaseAuthLevel() != auth::Level::RW ||
@@ -590,6 +597,9 @@ arangodb::Result Indexes::drop(LogicalCollection const* collection,
590597
if (!res.ok()) {
591598
return res;
592599
}
600+
601+
// flush estimates
602+
collection->clusterIndexEstimatesTTL(0.0);
593603

594604
#ifdef USE_ENTERPRISE
595605
return Indexes::dropCoordinatorEE(collection, iid);

arangod/VocBase/Methods/Indexes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct Indexes {
6060
velocypack::Slice const& definition, bool create,
6161
velocypack::Builder& output);
6262

63-
static arangodb::Result drop(LogicalCollection const* collection,
63+
static arangodb::Result drop(LogicalCollection* collection,
6464
velocypack::Slice const& indexArg);
6565

6666
static arangodb::Result extractHandle(

0 commit comments

Comments
 (0)
0