Skip to content

Commit 53e4ba8

Browse files
hkernbachrashtao
authored andcommitted
Feature/arangosearch properties (#287)
* added properties commitIntervalMsec and primarySort * prepared PrimarySort entity * add primarySort collection * added PrimarySort to Deserializer * more work on primarySort * finalized primarySort, added test * add commitIntervalMsec to serializer * add commitIntervalMsec to deserializer * getter for commitInterval and primarySort, also test for commitInterval * fixed test, fixed wrong deserializer statement
1 parent 71e8d55 commit 53e4ba8

File tree

8 files changed

+524
-312
lines changed

8 files changed

+524
-312
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,30 @@
2626

2727
/**
2828
* @author Mark Vollmary
29+
* @author Heiko Kernbach
2930
*
3031
*/
3132
public class ArangoSearchProperties {
3233

3334
private Long consolidationIntervalMsec;
35+
private Long commitIntervalMsec;
3436
private Long cleanupIntervalStep;
3537
private ConsolidationPolicy consolidationPolicy;
38+
private final Collection<PrimarySort> primarySorts;
3639
private final Collection<CollectionLink> links;
3740

3841
public ArangoSearchProperties() {
3942
super();
4043
links = new ArrayList<CollectionLink>();
44+
primarySorts = new ArrayList<PrimarySort>();
45+
}
46+
47+
public Long getCommitIntervalMsec() {
48+
return commitIntervalMsec;
49+
}
50+
51+
public void setCommitIntervalMsec(final Long commitIntervalMsec) {
52+
this.commitIntervalMsec = commitIntervalMsec;
4153
}
4254

4355
public Long getConsolidationIntervalMsec() {
@@ -72,4 +84,11 @@ public void addLink(final CollectionLink... links) {
7284
this.links.addAll(Arrays.asList(links));
7385
}
7486

87+
public Collection<PrimarySort> getPrimarySort() {
88+
return primarySorts;
89+
}
90+
91+
public void addPrimarySort(final PrimarySort... primarySorts) {
92+
this.primarySorts.addAll(Arrays.asList(primarySorts));
93+
}
7594
}

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

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,71 @@
2727

2828
/**
2929
* @author Mark Vollmary
30-
*
3130
*/
3231
public class ArangoSearchPropertiesEntity extends ViewEntity {
3332

34-
private final ArangoSearchProperties properties;
33+
private final ArangoSearchProperties properties;
34+
35+
public ArangoSearchPropertiesEntity(final String id, final String name, final ViewType type,
36+
final ArangoSearchProperties properties) {
37+
super(id, name, type);
38+
this.properties = properties;
39+
}
3540

36-
public ArangoSearchPropertiesEntity(final String id, final String name, final ViewType type,
37-
final ArangoSearchProperties properties) {
38-
super(id, name, type);
39-
this.properties = properties;
40-
}
41+
/**
42+
* @return Wait at least this many milliseconds between committing index data changes and making them visible to
43+
* queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a
44+
* lower value, until commit, will cause the index not to account for them and memory usage would continue
45+
* to grow. For the case where there are a few inserts/updates, a higher value will impact performance and
46+
* waste disk space for each commit call without any added benefits.
47+
*/
48+
public Long getConsolidationIntervalMsec() {
49+
return properties.getConsolidationIntervalMsec();
50+
}
4151

42-
/**
43-
* @return Wait at least this many milliseconds between committing index data changes and making them visible to
44-
* queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a
45-
* lower value, until commit, will cause the index not to account for them and memory usage would continue
46-
* to grow. For the case where there are a few inserts/updates, a higher value will impact performance and
47-
* waste disk space for each commit call without any added benefits.
48-
*/
49-
public Long getConsolidationIntervalMsec() {
50-
return properties.getConsolidationIntervalMsec();
51-
}
52+
/**
53+
* @return Wait at least this many milliseconds between committing view data store changes and making documents
54+
* visible to queries (default: 1000, to disable use: 0). For the case where there are a lot of inserts/updates, a
55+
* lower value, until commit, will cause the index not to account for them and memory usage would continue to grow.
56+
* For the case where there are a few inserts/updates, a higher value will impact performance and waste disk space
57+
* for each commit call without any added benefits. Background: For data retrieval ArangoSearch views follow the
58+
* concept of “eventually-consistent”, i.e. eventually all the data in ArangoDB will be matched by corresponding
59+
* query expressions. The concept of ArangoSearch view “commit” operation is introduced to control the upper-bound
60+
* on the time until document addition/removals are actually reflected by corresponding query expressions. Once a
61+
* “commit” operation is complete all documents added/removed prior to the start of the “commit” operation will be
62+
* reflected by queries invoked in subsequent ArangoDB transactions, in-progress ArangoDB transactions will still
63+
* continue to return a repeatable-read state.
64+
*/
65+
public Long getCommitIntervalMsec() {
66+
return properties.getCommitIntervalMsec();
67+
}
5268

53-
/**
54-
* @return Wait at least this many commits between removing unused files in data directory (default: 10, to disable
55-
* use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of
56-
* commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the
57-
* consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact
58-
* performance without any added benefits.
59-
*/
60-
public Long getCleanupIntervalStep() {
61-
return properties.getCleanupIntervalStep();
62-
}
69+
/**
70+
* @return Wait at least this many commits between removing unused files in data directory (default: 10, to disable
71+
* use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of
72+
* commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the
73+
* consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact
74+
* performance without any added benefits.
75+
*/
76+
public Long getCleanupIntervalStep() {
77+
return properties.getCleanupIntervalStep();
78+
}
6379

64-
public ConsolidationPolicy getConsolidationPolicy() {
65-
return properties.getConsolidationPolicy();
66-
}
80+
public ConsolidationPolicy getConsolidationPolicy() {
81+
return properties.getConsolidationPolicy();
82+
}
6783

68-
/**
69-
* @return A list of linked collections
70-
*/
71-
public Collection<CollectionLink> getLinks() {
72-
return properties.getLinks();
73-
}
84+
/**
85+
* @return A list of linked collections
86+
*/
87+
public Collection<CollectionLink> getLinks() {
88+
return properties.getLinks();
89+
}
7490

91+
/**
92+
* @return A list of primary sort objects
93+
*/
94+
public Collection<PrimarySort> getPrimarySort() {
95+
return properties.getPrimarySort();
96+
}
7597
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2019 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity.arangosearch;
22+
23+
/**
24+
* @author Heiko Kernbach
25+
*
26+
*/
27+
public class PrimarySort {
28+
29+
private final String fieldName;
30+
private Boolean ascending;
31+
32+
private PrimarySort(final String fieldName) {
33+
super();
34+
this.fieldName = fieldName;
35+
}
36+
37+
public static PrimarySort on(final String fieldName) {
38+
return new PrimarySort(fieldName);
39+
}
40+
41+
/**
42+
* @param ascending
43+
* @return primarySort
44+
*/
45+
public PrimarySort ascending(final Boolean ascending) {
46+
if (ascending) {
47+
this.ascending = true;
48+
} else {
49+
this.ascending = false;
50+
}
51+
return this;
52+
}
53+
54+
public Boolean getAscending() {
55+
return ascending;
56+
}
57+
58+
public String getFieldName() {
59+
return fieldName;
60+
}
61+
}

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,10 @@
2828
import java.util.Map.Entry;
2929

3030
import com.arangodb.entity.*;
31+
import com.arangodb.entity.arangosearch.*;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

34-
import com.arangodb.entity.arangosearch.ArangoSearchProperties;
35-
import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity;
36-
import com.arangodb.entity.arangosearch.CollectionLink;
37-
import com.arangodb.entity.arangosearch.ConsolidationPolicy;
38-
import com.arangodb.entity.arangosearch.ConsolidationType;
39-
import com.arangodb.entity.arangosearch.FieldLink;
40-
import com.arangodb.entity.arangosearch.StoreValuesType;
4135
import com.arangodb.velocypack.VPackDeserializationContext;
4236
import com.arangodb.velocypack.VPackDeserializer;
4337
import com.arangodb.velocypack.VPackSlice;
@@ -223,10 +217,17 @@ public ArangoSearchProperties deserialize(
223217
if (consolidationIntervalMsec.isInteger()) {
224218
properties.setConsolidationIntervalMsec(consolidationIntervalMsec.getAsLong());
225219
}
220+
221+
final VPackSlice commitIntervalMsec = vpack.get("commitIntervalMsec");
222+
if (commitIntervalMsec.isInteger()) {
223+
properties.setCommitIntervalMsec(commitIntervalMsec.getAsLong());
224+
}
225+
226226
final VPackSlice cleanupIntervalStep = vpack.get("cleanupIntervalStep");
227227
if (cleanupIntervalStep.isInteger()) {
228228
properties.setCleanupIntervalStep(cleanupIntervalStep.getAsLong());
229229
}
230+
230231
final VPackSlice consolidationPolicy = vpack.get("consolidationPolicy");
231232
if (consolidationPolicy.isObject()) {
232233
properties.setConsolidationPolicy(
@@ -269,6 +270,22 @@ public ArangoSearchProperties deserialize(
269270
properties.addLink(link);
270271
}
271272
}
273+
274+
final VPackSlice primarySorts = vpack.get("primarySort");
275+
if (primarySorts.isArray()) {
276+
final Iterator<VPackSlice> primarySortsIterator = primarySorts.arrayIterator();
277+
for (; primarySortsIterator.hasNext();) {
278+
final VPackSlice entry = primarySortsIterator.next();
279+
if (entry.isObject()) {
280+
if (entry.get("field").isString() && entry.get("asc").isBoolean()) {
281+
final PrimarySort primarySort = PrimarySort.on(entry.get("field").getAsString());
282+
primarySort.ascending(entry.get("asc").getAsBoolean());
283+
properties.addPrimarySort(primarySort);
284+
}
285+
}
286+
}
287+
}
288+
272289
return properties;
273290
}
274291
};

0 commit comments

Comments
 (0)