Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE-564] Index cache refilling (v6) #495

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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 REFILL_INDEX_CACHES = "refillIndexCaches";
private static final String IGNORE_REVS = "ignoreRevs";
private static final String RETURN_NEW = "returnNew";
private static final String NEW = "new";
Expand Down Expand Up @@ -90,6 +91,7 @@ protected <T> Request insertDocumentRequest(final T value, final DocumentCreateO
request.putQueryParam(OVERWRITE, params.getOverwrite());
request.putQueryParam(OVERWRITE_MODE, params.getOverwriteMode() != null ? params.getOverwriteMode().getValue() : null);
request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId());

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

request.setBody(util(Serializer.CUSTOM)
Expand Down Expand Up @@ -266,6 +269,7 @@ protected <T> Request replaceDocumentRequest(
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
request.setBody(util(Serializer.CUSTOM).serialize(value));
return request;
}
Expand Down Expand Up @@ -301,6 +305,7 @@ protected <T> Request replaceDocumentsRequest(final Collection<T> values, final
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
request.setBody(util(Serializer.CUSTOM)
.serialize(values, new ArangoSerializer.Options().serializeNullValues(false).stringAsJson(true)));
return request;
Expand Down Expand Up @@ -363,6 +368,7 @@ protected <T> Request updateDocumentRequest(final String key, final T value, fin
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
request.setBody(util(Serializer.CUSTOM).serialize(value, new ArangoSerializer.Options()
.serializeNullValues(params.getSerializeNull() == null || params.getSerializeNull())));
return request;
Expand Down Expand Up @@ -402,6 +408,7 @@ protected <T> Request updateDocumentsRequest(final Collection<T> values, final D
request.putQueryParam(RETURN_NEW, params.getReturnNew());
request.putQueryParam(RETURN_OLD, params.getReturnOld());
request.putQueryParam(SILENT, params.getSilent());
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
request.setBody(util(Serializer.CUSTOM).serialize(values, new ArangoSerializer.Options()
.serializeNullValues(params.getSerializeNull() == null || params.getSerializeNull())
.stringAsJson(true)));
Expand Down Expand Up @@ -455,6 +462,7 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp
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 All @@ -478,6 +486,7 @@ protected <T> Request deleteDocumentsRequest(final Collection<T> keys, final Doc
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());
request.setBody(util().serialize(keys));
return request;
}
Expand Down
14 changes: 14 additions & 0 deletions 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 class DocumentCreateOptions {
private Boolean silent;
private String streamTransactionId;
private Boolean mergeObjects;
private Boolean refillIndexCaches;


public DocumentCreateOptions() {
Expand Down Expand Up @@ -168,4 +169,17 @@ public DocumentCreateOptions mergeObjects(Boolean mergeObjects) {
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;
}
}
16 changes: 16 additions & 0 deletions 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 class DocumentDeleteOptions {
private Boolean returnOld;
private Boolean silent;
private String streamTransactionId;
private Boolean refillIndexCaches;

public DocumentDeleteOptions() {
super();
Expand Down Expand Up @@ -106,4 +107,19 @@ 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 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 class DocumentReplaceOptions {
private Boolean returnOld;
private Boolean silent;
private String streamTransactionId;
private Boolean refillIndexCaches;

public DocumentReplaceOptions() {
super();
Expand Down Expand Up @@ -136,4 +137,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 src/main/java/com/arangodb/model/DocumentUpdateOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class DocumentUpdateOptions {
private Boolean serializeNull;
private Boolean silent;
private String streamTransactionId;
private Boolean refillIndexCaches;

public DocumentUpdateOptions() {
super();
Expand Down Expand Up @@ -185,4 +186,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;
}

}
90 changes: 90 additions & 0 deletions src/test/java/com/arangodb/ArangoCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,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 @@ -327,6 +339,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));
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void getDocument(ArangoCollection collection) {
Expand Down Expand Up @@ -922,6 +943,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 @@ -1108,6 +1152,28 @@ void replaceDocumentsSilent(ArangoCollection collection) {
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));
assertThat(info.getErrors()).isEmpty();
}

@ParameterizedTest(name = "{index}")
@MethodSource("cols")
void deleteDocument(ArangoCollection collection) {
Expand Down Expand Up @@ -1189,6 +1255,30 @@ 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(),
BaseDocument.class,
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()),
BaseDocument.class,
new DocumentDeleteOptions().refillIndexCaches(true));
assertThat(info.getErrors()).isEmpty();
}

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