Skip to content

Commit

Permalink
[DE-565] Index cache refilling (#494)
Browse files Browse the repository at this point in the history
* DocumentCreateOptions.refillIndexCaches

* DocumentReplaceOptions.refillIndexCaches

* DocumentUpdateOptions.refillIndexCaches

* DocumentDeleteOptions.refillIndexCaches

* test CRUD methods on multiple documents
  • Loading branch information
rashtao authored Apr 25, 2023
1 parent 7580fd6 commit 7b334c3
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class InternalArangoCollection<A extends InternalArangoDB<E>, D
private static final String PATH_API_USER = "/_api/user";
private static final String MERGE_OBJECTS = "mergeObjects";
private static final String KEEP_NULL = "keepNull";
private static final String REFILL_INDEX_CACHES = "refillIndexCaches";
private static final String IGNORE_REVS = "ignoreRevs";
private static final String RETURN_NEW = "returnNew";
private static final String RETURN_OLD = "returnOld";
Expand Down Expand Up @@ -106,6 +107,7 @@ private InternalRequest createInsertDocumentRequest(final DocumentCreateOptions
params.getOverwriteMode().getValue() : null);
request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects());
request.putQueryParam(KEEP_NULL, params.getKeepNull());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId());
return request;
}
Expand Down Expand Up @@ -243,6 +245,7 @@ private InternalRequest createReplaceDocumentRequest(final DocumentReplaceOption
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
return request;
}

Expand Down Expand Up @@ -304,6 +307,7 @@ private InternalRequest createUpdateDocumentRequest(final DocumentUpdateOptions
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
return request;
}

Expand Down Expand Up @@ -359,6 +363,7 @@ private InternalRequest createDeleteDocumentRequest(final DocumentDeleteOptions
request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
return request;
}

Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/com/arangodb/model/DocumentCreateOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class DocumentCreateOptions {
private String streamTransactionId;
private Boolean mergeObjects;
private Boolean keepNull;
private Boolean refillIndexCaches;

public DocumentCreateOptions() {
super();
Expand Down Expand Up @@ -163,4 +164,17 @@ public DocumentCreateOptions keepNull(Boolean keepNull) {
return this;
}

public Boolean getRefillIndexCaches() {
return refillIndexCaches;
}

/**
* @param refillIndexCaches Whether to add a new entry to the in-memory edge cache if an edge document is inserted.
* @return options
* @since ArangoDB 3.11
*/
public DocumentCreateOptions refillIndexCaches(Boolean refillIndexCaches) {
this.refillIndexCaches = refillIndexCaches;
return this;
}
}
15 changes: 15 additions & 0 deletions core/src/main/java/com/arangodb/model/DocumentDeleteOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class DocumentDeleteOptions {
private Boolean returnOld;
private Boolean silent;
private String streamTransactionId;
private Boolean refillIndexCaches;

public DocumentDeleteOptions() {
super();
Expand Down Expand Up @@ -107,4 +108,18 @@ public DocumentDeleteOptions streamTransactionId(final String streamTransactionI
return this;
}

public Boolean getRefillIndexCaches() {
return refillIndexCaches;
}

/**
* @param refillIndexCaches Whether to delete an existing entry from the in-memory edge cache and refill it with
* another edge if an edge document is removed.
* @return options
* @since ArangoDB 3.11
*/
public DocumentDeleteOptions refillIndexCaches(Boolean refillIndexCaches) {
this.refillIndexCaches = refillIndexCaches;
return this;
}
}
15 changes: 15 additions & 0 deletions core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public final class DocumentReplaceOptions {
private Boolean returnOld;
private Boolean silent;
private String streamTransactionId;
private Boolean refillIndexCaches;

public DocumentReplaceOptions() {
super();
Expand Down Expand Up @@ -139,4 +140,18 @@ public DocumentReplaceOptions streamTransactionId(final String streamTransaction
return this;
}

public Boolean getRefillIndexCaches() {
return refillIndexCaches;
}

/**
* @param refillIndexCaches Whether to update an existing entry in the in-memory edge cache if an edge document is
* replaced.
* @return options
* @since ArangoDB 3.11
*/
public DocumentReplaceOptions refillIndexCaches(Boolean refillIndexCaches) {
this.refillIndexCaches = refillIndexCaches;
return this;
}
}
16 changes: 16 additions & 0 deletions core/src/main/java/com/arangodb/model/DocumentUpdateOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class DocumentUpdateOptions {
private Boolean returnOld;
private Boolean silent;
private String streamTransactionId;
private Boolean refillIndexCaches;

public DocumentUpdateOptions() {
super();
Expand Down Expand Up @@ -174,4 +175,19 @@ public DocumentUpdateOptions streamTransactionId(final String streamTransactionI
return this;
}

public Boolean getRefillIndexCaches() {
return refillIndexCaches;
}

/**
* @param refillIndexCaches Whether to update an existing entry in the in-memory edge cache if an edge document is
* updated.
* @return options
* @since ArangoDB 3.11
*/
public DocumentUpdateOptions refillIndexCaches(Boolean refillIndexCaches) {
this.refillIndexCaches = refillIndexCaches;
return this;
}

}
95 changes: 92 additions & 3 deletions driver/src/test/java/com/arangodb/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ void insertDocumentWaitForSync(ArangoCollection collection) {
assertThat(doc.getNew()).isNull();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void insertDocumentRefillIndexCaches(ArangoCollection collection) {
final DocumentCreateOptions options = new DocumentCreateOptions().refillIndexCaches(true);
final DocumentCreateEntity<BaseDocument> doc = collection.insertDocument(new BaseDocument(), options);
assertThat(doc).isNotNull();
assertThat(doc.getId()).isNotNull();
assertThat(doc.getKey()).isNotNull();
assertThat(doc.getRev()).isNotNull();
assertThat(doc.getNew()).isNull();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void insertDocumentAsJson(ArangoCollection collection) {
Expand Down Expand Up @@ -396,6 +408,15 @@ void insertDocumentsSilent(ArangoCollection collection) {
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void insertDocumentsRefillIndexCaches(ArangoCollection collection) {
final MultiDocumentEntity<DocumentCreateEntity<BaseDocument>> info =
collection.insertDocuments(Arrays.asList(new BaseDocument(), new BaseDocument()),
new DocumentCreateOptions().refillIndexCaches(true), BaseDocument.class);
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void getDocument(ArangoCollection collection) {
Expand Down Expand Up @@ -941,6 +962,29 @@ void updateDocumentPreconditionFailed(ArangoCollection collection) {
assertThat(readDocument.getAttribute("foo")).isEqualTo("b");
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void updateDocumentRefillIndexCaches(ArangoCollection collection) {
BaseDocument doc = new BaseDocument();
DocumentCreateEntity<?> createResult = collection.insertDocument(doc);
doc.addAttribute("foo", "bar");
DocumentUpdateEntity<BaseDocument> updateResult = collection.updateDocument(createResult.getKey(),
doc , new DocumentUpdateOptions().refillIndexCaches(true));
assertThat(updateResult.getRev())
.isNotNull()
.isNotEqualTo(createResult.getRev());
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void updateDocumentsRefillIndexCaches(ArangoCollection collection) {
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> info =
collection.updateDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())),
new DocumentUpdateOptions().refillIndexCaches(true), BaseDocument.class);
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void replaceDocument(ArangoCollection collection) {
Expand Down Expand Up @@ -1098,7 +1142,7 @@ void replaceDocumentSilentDontTouchInstance(ArangoCollection collection) {
final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString());
final DocumentCreateEntity<?> createResult = collection.insertDocument(doc);
final DocumentUpdateEntity<BaseDocument> meta = collection.replaceDocument(createResult.getKey(), doc,
new DocumentReplaceOptions().silent(true));
new DocumentReplaceOptions().silent(true));
assertThat(meta.getRev()).isNull();
assertThat(doc.getRevision()).isNull();
assertThat(createResult.getRev()).isNotNull();
Expand All @@ -1110,14 +1154,36 @@ void replaceDocumentsSilent(ArangoCollection collection) {
assumeTrue(isSingleServer());
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> info =
collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())),
new DocumentReplaceOptions().silent(true), BaseDocument.class);
collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())),
new DocumentReplaceOptions().silent(true), BaseDocument.class);
assertThat(info).isNotNull();
assertThat(info.getDocuments()).isEmpty();
assertThat(info.getDocumentsAndErrors()).isEmpty();
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void replaceDocumentRefillIndexCaches(ArangoCollection collection) {
final BaseDocument doc = new BaseDocument(UUID.randomUUID().toString());
final DocumentCreateEntity<?> createResult = collection.insertDocument(doc);
final DocumentUpdateEntity<BaseDocument> replaceResult = collection.replaceDocument(createResult.getKey(), doc,
new DocumentReplaceOptions().refillIndexCaches(true));
assertThat(replaceResult.getRev())
.isNotNull()
.isNotEqualTo(createResult.getRev());
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void replaceDocumentsRefillIndexCaches(ArangoCollection collection) {
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> info =
collection.replaceDocuments(Collections.singletonList(new BaseDocument(createResult.getKey())),
new DocumentReplaceOptions().refillIndexCaches(true), BaseDocument.class);
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void deleteDocument(ArangoCollection collection) {
Expand Down Expand Up @@ -1192,6 +1258,29 @@ void deleteDocumentsSilent(ArangoCollection collection) {
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void deleteDocumentRefillIndexCaches(ArangoCollection collection) {
DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
DocumentDeleteEntity<?> deleteResult = collection.deleteDocument(createResult.getKey(),
new DocumentDeleteOptions().refillIndexCaches(true));
assertThat(deleteResult.getRev())
.isNotNull()
.isEqualTo(createResult.getRev());
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void deleteDocumentsRefillIndexCaches(ArangoCollection collection) {
assumeTrue(isSingleServer());
final DocumentCreateEntity<?> createResult = collection.insertDocument(new BaseDocument());
final MultiDocumentEntity<DocumentDeleteEntity<BaseDocument>> info = collection.deleteDocuments(
Collections.singletonList(createResult.getKey()),
new DocumentDeleteOptions().refillIndexCaches(true),
BaseDocument.class);
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void getIndex(ArangoCollection collection) {
Expand Down

0 comments on commit 7b334c3

Please sign in to comment.