Skip to content

Commit 31ddee7

Browse files
authored
Index cache refilling (DE-564) (#495)
1 parent dc2af2c commit 31ddee7

File tree

6 files changed

+160
-0
lines changed

6 files changed

+160
-0
lines changed

src/main/java/com/arangodb/internal/InternalArangoCollection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public abstract class InternalArangoCollection<A extends InternalArangoDB<E>, D
5252
private static final String PATH_API_USER = "/_api/user";
5353

5454
private static final String MERGE_OBJECTS = "mergeObjects";
55+
private static final String REFILL_INDEX_CACHES = "refillIndexCaches";
5556
private static final String IGNORE_REVS = "ignoreRevs";
5657
private static final String RETURN_NEW = "returnNew";
5758
private static final String NEW = "new";
@@ -90,6 +91,7 @@ protected <T> Request insertDocumentRequest(final T value, final DocumentCreateO
9091
request.putQueryParam(OVERWRITE, params.getOverwrite());
9192
request.putQueryParam(OVERWRITE_MODE, params.getOverwriteMode() != null ? params.getOverwriteMode().getValue() : null);
9293
request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects());
94+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
9395
request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId());
9496

9597
request.setBody(util(Serializer.CUSTOM).serialize(value));
@@ -130,6 +132,7 @@ protected <T> Request insertDocumentsRequest(final Collection<T> values, final D
130132
request.putQueryParam(OVERWRITE, params.getOverwrite());
131133
request.putQueryParam(OVERWRITE_MODE, params.getOverwriteMode() != null ? params.getOverwriteMode().getValue() : null);
132134
request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects());
135+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
133136
request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId());
134137

135138
request.setBody(util(Serializer.CUSTOM)
@@ -266,6 +269,7 @@ protected <T> Request replaceDocumentRequest(
266269
request.putQueryParam(RETURN_NEW, params.getReturnNew());
267270
request.putQueryParam(RETURN_OLD, params.getReturnOld());
268271
request.putQueryParam(SILENT, params.getSilent());
272+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
269273
request.setBody(util(Serializer.CUSTOM).serialize(value));
270274
return request;
271275
}
@@ -301,6 +305,7 @@ protected <T> Request replaceDocumentsRequest(final Collection<T> values, final
301305
request.putQueryParam(RETURN_NEW, params.getReturnNew());
302306
request.putQueryParam(RETURN_OLD, params.getReturnOld());
303307
request.putQueryParam(SILENT, params.getSilent());
308+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
304309
request.setBody(util(Serializer.CUSTOM)
305310
.serialize(values, new ArangoSerializer.Options().serializeNullValues(false).stringAsJson(true)));
306311
return request;
@@ -363,6 +368,7 @@ protected <T> Request updateDocumentRequest(final String key, final T value, fin
363368
request.putQueryParam(RETURN_NEW, params.getReturnNew());
364369
request.putQueryParam(RETURN_OLD, params.getReturnOld());
365370
request.putQueryParam(SILENT, params.getSilent());
371+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
366372
request.setBody(util(Serializer.CUSTOM).serialize(value, new ArangoSerializer.Options()
367373
.serializeNullValues(params.getSerializeNull() == null || params.getSerializeNull())));
368374
return request;
@@ -402,6 +408,7 @@ protected <T> Request updateDocumentsRequest(final Collection<T> values, final D
402408
request.putQueryParam(RETURN_NEW, params.getReturnNew());
403409
request.putQueryParam(RETURN_OLD, params.getReturnOld());
404410
request.putQueryParam(SILENT, params.getSilent());
411+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
405412
request.setBody(util(Serializer.CUSTOM).serialize(values, new ArangoSerializer.Options()
406413
.serializeNullValues(params.getSerializeNull() == null || params.getSerializeNull())
407414
.stringAsJson(true)));
@@ -455,6 +462,7 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp
455462
request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync());
456463
request.putQueryParam(RETURN_OLD, params.getReturnOld());
457464
request.putQueryParam(SILENT, params.getSilent());
465+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
458466
return request;
459467
}
460468

@@ -478,6 +486,7 @@ protected <T> Request deleteDocumentsRequest(final Collection<T> keys, final Doc
478486
request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync());
479487
request.putQueryParam(RETURN_OLD, params.getReturnOld());
480488
request.putQueryParam(SILENT, params.getSilent());
489+
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
481490
request.setBody(util().serialize(keys));
482491
return request;
483492
}

src/main/java/com/arangodb/model/DocumentCreateOptions.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class DocumentCreateOptions {
3636
private Boolean silent;
3737
private String streamTransactionId;
3838
private Boolean mergeObjects;
39+
private Boolean refillIndexCaches;
3940

4041

4142
public DocumentCreateOptions() {
@@ -168,4 +169,17 @@ public DocumentCreateOptions mergeObjects(Boolean mergeObjects) {
168169
return this;
169170
}
170171

172+
public Boolean getRefillIndexCaches() {
173+
return refillIndexCaches;
174+
}
175+
176+
/**
177+
* @param refillIndexCaches Whether to add a new entry to the in-memory edge cache if an edge document is inserted.
178+
* @return options
179+
* @since ArangoDB 3.11
180+
*/
181+
public DocumentCreateOptions refillIndexCaches(Boolean refillIndexCaches) {
182+
this.refillIndexCaches = refillIndexCaches;
183+
return this;
184+
}
171185
}

src/main/java/com/arangodb/model/DocumentDeleteOptions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class DocumentDeleteOptions {
3333
private Boolean returnOld;
3434
private Boolean silent;
3535
private String streamTransactionId;
36+
private Boolean refillIndexCaches;
3637

3738
public DocumentDeleteOptions() {
3839
super();
@@ -106,4 +107,19 @@ public DocumentDeleteOptions streamTransactionId(final String streamTransactionI
106107
return this;
107108
}
108109

110+
public Boolean getRefillIndexCaches() {
111+
return refillIndexCaches;
112+
}
113+
114+
/**
115+
* @param refillIndexCaches Whether to delete an existing entry from the in-memory edge cache and refill it with
116+
* another edge if an edge document is removed.
117+
* @return options
118+
* @since ArangoDB 3.11
119+
*/
120+
public DocumentDeleteOptions refillIndexCaches(Boolean refillIndexCaches) {
121+
this.refillIndexCaches = refillIndexCaches;
122+
return this;
123+
}
124+
109125
}

src/main/java/com/arangodb/model/DocumentReplaceOptions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class DocumentReplaceOptions {
3535
private Boolean returnOld;
3636
private Boolean silent;
3737
private String streamTransactionId;
38+
private Boolean refillIndexCaches;
3839

3940
public DocumentReplaceOptions() {
4041
super();
@@ -136,4 +137,18 @@ public DocumentReplaceOptions streamTransactionId(final String streamTransaction
136137
return this;
137138
}
138139

140+
public Boolean getRefillIndexCaches() {
141+
return refillIndexCaches;
142+
}
143+
144+
/**
145+
* @param refillIndexCaches Whether to update an existing entry in the in-memory edge cache if an edge document is
146+
* replaced.
147+
* @return options
148+
* @since ArangoDB 3.11
149+
*/
150+
public DocumentReplaceOptions refillIndexCaches(Boolean refillIndexCaches) {
151+
this.refillIndexCaches = refillIndexCaches;
152+
return this;
153+
}
139154
}

src/main/java/com/arangodb/model/DocumentUpdateOptions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class DocumentUpdateOptions {
3838
private Boolean serializeNull;
3939
private Boolean silent;
4040
private String streamTransactionId;
41+
private Boolean refillIndexCaches;
4142

4243
public DocumentUpdateOptions() {
4344
super();
@@ -185,4 +186,19 @@ public DocumentUpdateOptions streamTransactionId(final String streamTransactionI
185186
return this;
186187
}
187188

189+
public Boolean getRefillIndexCaches() {
190+
return refillIndexCaches;
191+
}
192+
193+
/**
194+
* @param refillIndexCaches Whether to update an existing entry in the in-memory edge cache if an edge document is
195+
* updated.
196+
* @return options
197+
* @since ArangoDB 3.11
198+
*/
199+
public DocumentUpdateOptions refillIndexCaches(Boolean refillIndexCaches) {
200+
this.refillIndexCaches = refillIndexCaches;
201+
return this;
202+
}
203+
188204
}

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ void insertDocumentWaitForSync(ArangoCollection collection) {
276276
assertThat(doc.getNew()).isNull();
277277
}
278278

279+
@ParameterizedTest(name = "{index}")
280+
@MethodSource("cols")
281+
void insertDocumentRefillIndexCaches(ArangoCollection collection) {
282+
final DocumentCreateOptions options = new DocumentCreateOptions().refillIndexCaches(true);
283+
final DocumentCreateEntity<BaseDocument> doc = collection.insertDocument(new BaseDocument(), options);
284+
assertThat(doc).isNotNull();
285+
assertThat(doc.getId()).isNotNull();
286+
assertThat(doc.getKey()).isNotNull();
287+
assertThat(doc.getRev()).isNotNull();
288+
assertThat(doc.getNew()).isNull();
289+
}
290+
279291
@ParameterizedTest(name = "{index}")
280292
@MethodSource("cols")
281293
void insertDocumentAsJson(ArangoCollection collection) {
@@ -327,6 +339,15 @@ void insertDocumentsSilent(ArangoCollection collection) {
327339
assertThat(info.getErrors()).isEmpty();
328340
}
329341

342+
@ParameterizedTest(name = "{index}")
343+
@MethodSource("cols")
344+
void insertDocumentsRefillIndexCaches(ArangoCollection collection) {
345+
final MultiDocumentEntity<DocumentCreateEntity<BaseDocument>> info =
346+
collection.insertDocuments(Arrays.asList(new BaseDocument(), new BaseDocument()),
347+
new DocumentCreateOptions().refillIndexCaches(true));
348+
assertThat(info.getErrors()).isEmpty();
349+
}
350+
330351
@ParameterizedTest(name = "{index}")
331352
@MethodSource("cols")
332353
void getDocument(ArangoCollection collection) {
@@ -922,6 +943,29 @@ void updateDocumentPreconditionFailed(ArangoCollection collection) {
922943
assertThat(readDocument.getAttribute("foo")).isEqualTo("b");
923944
}
924945

946+
@ParameterizedTest(name = "{index}")
947+
@MethodSource("cols")
948+
void updateDocumentRefillIndexCaches(ArangoCollection collection) {
949+
BaseDocument doc = new BaseDocument();
950+
DocumentCreateEntity<?> createResult = collection.insertDocument(doc);
951+
doc.addAttribute("foo", "bar");
952+
DocumentUpdateEntity<BaseDocument> updateResult = collection.updateDocument(createResult.getKey(),
953+
doc , new DocumentUpdateOptions().refillIndexCaches(true));
954+
assertThat(updateResult.getRev())
955+
.isNotNull()
956+
.isNotEqualTo(createResult.getRev());
957+
}
958+
959+
@ParameterizedTest(name = "{index}")
960+
@MethodSource("cols")
961+
void updateDocumentsRefillIndexCaches(ArangoCollection collection) {
962+
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
963+
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> info =
964+
collection.updateDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())),
965+
new DocumentUpdateOptions().refillIndexCaches(true), BaseDocument.class);
966+
assertThat(info.getErrors()).isEmpty();
967+
}
968+
925969
@ParameterizedTest(name = "{index}")
926970
@MethodSource("cols")
927971
void replaceDocument(ArangoCollection collection) {
@@ -1108,6 +1152,28 @@ void replaceDocumentsSilent(ArangoCollection collection) {
11081152
assertThat(info.getErrors()).isEmpty();
11091153
}
11101154

1155+
@ParameterizedTest(name = "{index}")
1156+
@MethodSource("cols")
1157+
void replaceDocumentRefillIndexCaches(ArangoCollection collection) {
1158+
final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString());
1159+
final DocumentCreateEntity<?> createResult = collection.insertDocument(doc);
1160+
final DocumentUpdateEntity<BaseDocument> replaceResult = collection.replaceDocument(createResult.getKey(), doc,
1161+
new DocumentReplaceOptions().refillIndexCaches(true));
1162+
assertThat(replaceResult.getRev())
1163+
.isNotNull()
1164+
.isNotEqualTo(createResult.getRev());
1165+
}
1166+
1167+
@ParameterizedTest(name = "{index}")
1168+
@MethodSource("cols")
1169+
void replaceDocumentsRefillIndexCaches(ArangoCollection collection) {
1170+
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
1171+
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> info =
1172+
collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())),
1173+
new DocumentReplaceOptions().refillIndexCaches(true));
1174+
assertThat(info.getErrors()).isEmpty();
1175+
}
1176+
11111177
@ParameterizedTest(name = "{index}")
11121178
@MethodSource("cols")
11131179
void deleteDocument(ArangoCollection collection) {
@@ -1189,6 +1255,30 @@ void deleteDocumentsSilent(ArangoCollection collection) {
11891255
assertThat(info.getErrors()).isEmpty();
11901256
}
11911257

1258+
@ParameterizedTest(name = "{index}")
1259+
@MethodSource("cols")
1260+
void deleteDocumentRefillIndexCaches(ArangoCollection collection) {
1261+
DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
1262+
DocumentDeleteEntity<?> deleteResult = collection.deleteDocument(createResult.getKey(),
1263+
BaseDocument.class,
1264+
new DocumentDeleteOptions().refillIndexCaches(true));
1265+
assertThat(deleteResult.getRev())
1266+
.isNotNull()
1267+
.isEqualTo(createResult.getRev());
1268+
}
1269+
1270+
@ParameterizedTest(name = "{index}")
1271+
@MethodSource("cols")
1272+
void deleteDocumentsRefillIndexCaches(ArangoCollection collection) {
1273+
assumeTrue(isSingleServer());
1274+
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
1275+
final MultiDocumentEntity<DocumentDeleteEntity<BaseDocument>> info = collection.deleteDocuments(
1276+
Collections.singletonList(createResult.getKey()),
1277+
BaseDocument.class,
1278+
new DocumentDeleteOptions().refillIndexCaches(true));
1279+
assertThat(info.getErrors()).isEmpty();
1280+
}
1281+
11921282
@ParameterizedTest(name = "{index}")
11931283
@MethodSource("cols")
11941284
void getIndex(ArangoCollection collection) {

0 commit comments

Comments
 (0)