aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/AggregatedStatsMergePendingChecker.java
blob: 4f2b8a2cb77e8ef7f14b9ef9e2f47da013d1eabe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;

/**
 * Class checking whether a particular bucket space on a content node might have buckets pending.
 *
 * Aggregated stats over the entire content cluster is used to check this.
 */
public class AggregatedStatsMergePendingChecker implements MergePendingChecker {

    private final AggregatedClusterStats stats;
    private final double minMergeCompletionRatio;

    public AggregatedStatsMergePendingChecker(AggregatedClusterStats stats,
                                              double minMergeCompletionRatio) {
        this.stats = stats;
        this.minMergeCompletionRatio = minMergeCompletionRatio;
    }

    @Override
    public boolean mayHaveMergesPending(String bucketSpace, int contentNodeIndex) {
        if (!stats.hasUpdatesFromAllDistributors()) {
            return true;
        }
        ContentNodeStats nodeStats = stats.getStats().getNodeStats(contentNodeIndex);
        if (nodeStats != null) {
            ContentNodeStats.BucketSpaceStats bucketSpaceStats = nodeStats.getBucketSpace(bucketSpace);
            return (bucketSpaceStats != null &&
                    bucketSpaceStats.mayHaveBucketsPending(minMergeCompletionRatio));
        }
        return true;
    }

}