blob: d23a3bf73d8b5ceb7cb5fb0cf7dd244e3e29deb5 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// 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;
import com.yahoo.document.FixedBucketSpaces;
import java.util.HashMap;
import java.util.Map;
/**
* Class tracking whether we have changes in current and previous aggregated cluster stats.
*
* The cluster stats are considered changed if the current and previous stats differs in whether
* they may have buckets pending in the 'global' bucket space. This signals that the ClusterStateBundle should be recomputed.
*/
public class ClusterStatsChangeTracker {
private AggregatedClusterStats aggregatedStats;
private AggregatedStatsMergePendingChecker checker;
private Map<Integer, Boolean> prevMayHaveMergesPending = null;
public ClusterStatsChangeTracker(AggregatedClusterStats aggregatedStats,
double minMergeCompletionRatio) {
setAggregatedStats(aggregatedStats, minMergeCompletionRatio);
}
private void setAggregatedStats(AggregatedClusterStats aggregatedStats,
double minMergeCompletionRatio) {
this.aggregatedStats = aggregatedStats;
checker = new AggregatedStatsMergePendingChecker(this.aggregatedStats, minMergeCompletionRatio);
}
public void syncAggregatedStats() {
prevMayHaveMergesPending = new HashMap<>();
for (ContentNodeStats contentNodeStats : aggregatedStats.getStats()) {
int nodeIndex = contentNodeStats.getNodeIndex();
prevMayHaveMergesPending.put(nodeIndex, mayHaveMergesPendingInGlobalSpace(nodeIndex));
}
}
public void updateAggregatedStats(AggregatedClusterStats newAggregatedStats,
double minMergeCompletionRatio) {
syncAggregatedStats();
setAggregatedStats(newAggregatedStats, minMergeCompletionRatio);
}
public boolean statsHaveChanged() {
if (!aggregatedStats.hasUpdatesFromAllDistributors()) {
return false;
}
for (ContentNodeStats contentNodeStats : aggregatedStats.getStats()) {
int nodeIndex = contentNodeStats.getNodeIndex();
boolean currValue = mayHaveMergesPendingInGlobalSpace(nodeIndex);
Boolean prevValue = prevMayHaveMergesPendingInGlobalSpace(nodeIndex);
if (prevValue != null) {
if (prevValue != currValue) {
return true;
}
} else {
return true;
}
}
return false;
}
private boolean mayHaveMergesPendingInGlobalSpace(int nodeIndex) {
return checker.mayHaveMergesPending(FixedBucketSpaces.globalSpace(), nodeIndex);
}
private Boolean prevMayHaveMergesPendingInGlobalSpace(int nodeIndex) {
if (prevMayHaveMergesPending != null) {
return prevMayHaveMergesPending.get(nodeIndex);
}
return null;
}
}
|