Skip to content

Commit e4c8b5c

Browse files
committed
[DE-380] fixed ConsolidationPolicy API
1 parent 7280906 commit e4c8b5c

File tree

4 files changed

+94
-22
lines changed

4 files changed

+94
-22
lines changed

src/main/java/com/arangodb/entity/arangosearch/ConsolidationPolicy.java

+70-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ public class ConsolidationPolicy {
2929

3030
private ConsolidationType type;
3131
private Double threshold;
32+
@Deprecated
3233
private Long segmentThreshold;
34+
private Long segmentsMin;
35+
private Long segmentsMax;
36+
private Long segmentsBytesMax;
37+
private Long segmentsBytesFloor;
38+
3339

3440
public ConsolidationPolicy() {
3541
}
@@ -44,9 +50,12 @@ public ConsolidationPolicy type(final ConsolidationType type) {
4450
}
4551

4652
/**
47-
* @param threshold Select a given segment for "consolidation" if and only if the formula based on type (as defined above)
48-
* evaluates to true, valid value range [0.0, 1.0] (default: 0.85)
49-
* @return policy
53+
* @param threshold Defines threshold value of [0.0, 1.0] possible range. Consolidation is performed on segments
54+
* which accumulated size in bytes is less than all segments’ byte size multiplied by the
55+
* threshold; i.e. the following formula is applied for each segment:
56+
* {threshold} > (segment_bytes + sum_of_merge_candidate_segment_bytes) / all_segment_bytes.
57+
* (default: 0.1)
58+
* @return this
5059
*/
5160
public ConsolidationPolicy threshold(final Double threshold) {
5261
this.threshold = threshold;
@@ -56,8 +65,10 @@ public ConsolidationPolicy threshold(final Double threshold) {
5665
/**
5766
* @param segmentThreshold Apply the "consolidation" operation if and only if (default: 300): {segmentThreshold} <
5867
* number_of_segments
59-
* @return policy
68+
* @return this
69+
* @deprecated
6070
*/
71+
@Deprecated
6172
public ConsolidationPolicy segmentThreshold(final Long segmentThreshold) {
6273
this.segmentThreshold = segmentThreshold;
6374
return this;
@@ -71,20 +82,73 @@ public Double getThreshold() {
7182
return threshold;
7283
}
7384

85+
@Deprecated
7486
public Long getSegmentThreshold() {
7587
return segmentThreshold;
7688
}
7789

90+
public Long getSegmentsMin() {
91+
return segmentsMin;
92+
}
93+
94+
/**
95+
* @param segmentsMin The minimum number of segments that will be evaluated as candidates for consolidation. (default: 1)
96+
* @return this
97+
*/
98+
public ConsolidationPolicy segmentsMin(final Long segmentsMin) {
99+
this.segmentsMin = segmentsMin;
100+
return this;
101+
}
102+
103+
public Long getSegmentsMax() {
104+
return segmentsMax;
105+
}
106+
107+
/**
108+
* @param segmentsMax The maximum number of segments that will be evaluated as candidates for consolidation. (default: 10)
109+
* @return this
110+
*/
111+
public ConsolidationPolicy segmentsMax(final Long segmentsMax) {
112+
this.segmentsMax = segmentsMax;
113+
return this;
114+
}
115+
116+
public Long getSegmentsBytesMax() {
117+
return segmentsBytesMax;
118+
}
119+
120+
/**
121+
* @param segmentsBytesMax Maximum allowed size of all consolidated segments in bytes. (default: 5368709120)
122+
* @return this
123+
*/
124+
public ConsolidationPolicy segmentsBytesMax(final Long segmentsBytesMax) {
125+
this.segmentsBytesMax = segmentsBytesMax;
126+
return this;
127+
}
128+
129+
public Long getSegmentsBytesFloor() {
130+
return segmentsBytesFloor;
131+
}
132+
133+
/**
134+
* @param segmentsBytesFloor Defines the value (in bytes) to treat all smaller segments as equal for consolidation selection. (default: 2097152)
135+
* @return this
136+
*/
137+
public ConsolidationPolicy segmentsBytesFloor(final Long segmentsBytesFloor) {
138+
this.segmentsBytesFloor = segmentsBytesFloor;
139+
return this;
140+
}
141+
78142
@Override
79143
public boolean equals(Object o) {
80144
if (this == o) return true;
81145
if (o == null || getClass() != o.getClass()) return false;
82146
ConsolidationPolicy that = (ConsolidationPolicy) o;
83-
return type == that.type && Objects.equals(threshold, that.threshold) && Objects.equals(segmentThreshold, that.segmentThreshold);
147+
return type == that.type && Objects.equals(threshold, that.threshold) && Objects.equals(segmentThreshold, that.segmentThreshold) && Objects.equals(segmentsMin, that.segmentsMin) && Objects.equals(segmentsMax, that.segmentsMax) && Objects.equals(segmentsBytesMax, that.segmentsBytesMax) && Objects.equals(segmentsBytesFloor, that.segmentsBytesFloor);
84148
}
85149

86150
@Override
87151
public int hashCode() {
88-
return Objects.hash(type, threshold, segmentThreshold);
152+
return Objects.hash(type, threshold, segmentThreshold, segmentsMin, segmentsMax, segmentsBytesMax, segmentsBytesFloor);
89153
}
90154
}

src/main/java/com/arangodb/entity/arangosearch/ConsolidationType.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
public enum ConsolidationType {
44

5-
BYTES_ACCUM, TIER
5+
/**
6+
* @deprecated The “bytes_accum” policy type is deprecated and remains in ArangoSearch for backwards compatibility
7+
* with the older versions. Please make sure to always use the “tier” policy instead.
8+
*/
9+
@Deprecated
10+
BYTES_ACCUM,
11+
12+
TIER
613

714
}

src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java

+10-14
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,17 @@ protected static FieldLink deserializeField(final Entry<String, VPackSlice> fiel
289289
};
290290

291291
public static final VPackDeserializer<ConsolidationPolicy> CONSOLIDATE = (parent, vpack, context) -> {
292-
final VPackSlice type = vpack.get("type");
293-
if (type.isString()) {
294-
final ConsolidationPolicy consolidate = ConsolidationPolicy
295-
.of(ConsolidationType.valueOf(type.getAsString().toUpperCase(Locale.ENGLISH)));
296-
final VPackSlice threshold = vpack.get("threshold");
297-
if (threshold.isNumber()) {
298-
consolidate.threshold(threshold.getAsDouble());
299-
}
300-
final VPackSlice segmentThreshold = vpack.get("segmentThreshold");
301-
if (segmentThreshold.isInteger()) {
302-
consolidate.segmentThreshold(segmentThreshold.getAsLong());
303-
}
304-
return consolidate;
292+
ConsolidationType type = ConsolidationType.valueOf(vpack.get("type").getAsString().toUpperCase(Locale.ENGLISH));
293+
final ConsolidationPolicy consolidate = ConsolidationPolicy.of(type);
294+
if (ConsolidationType.BYTES_ACCUM.equals(type)) {
295+
consolidate.threshold(vpack.get("threshold").getAsDouble());
296+
} else {
297+
consolidate.segmentsMin(vpack.get("segmentsMin").getAsLong());
298+
consolidate.segmentsMax(vpack.get("segmentsMax").getAsLong());
299+
consolidate.segmentsBytesMax(vpack.get("segmentsBytesMax").getAsLong());
300+
consolidate.segmentsBytesFloor(vpack.get("segmentsBytesFloor").getAsLong());
305301
}
306-
return null;
302+
return consolidate;
307303
};
308304

309305
public static final VPackDeserializer<CollectionSchema> COLLECTION_VALIDATION = (parent, vpack, context) -> {

src/test/java/com/arangodb/InvertedIndexTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ private InvertedIndexOptions createOptions(String analyzerName) {
9898
.consolidationIntervalMsec(11L)
9999
.commitIntervalMsec(22L)
100100
.cleanupIntervalStep(33L)
101-
.consolidationPolicy(ConsolidationPolicy.of(ConsolidationType.BYTES_ACCUM).threshold(1.))
101+
.consolidationPolicy(ConsolidationPolicy.of(ConsolidationType.TIER)
102+
.segmentsMin(3L)
103+
.segmentsMax(44L)
104+
.segmentsBytesMax(55555L)
105+
.segmentsBytesFloor(666L)
106+
)
102107
.writebufferIdle(44L)
103108
.writebufferActive(55L)
104109
.writebufferSizeMax(66L);

0 commit comments

Comments
 (0)