Skip to content

[DE-434] ArangoSearch cache #472

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

Merged
merged 4 commits into from
Nov 29, 2022
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
20 changes: 10 additions & 10 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
fail-fast: false
matrix:
docker-img:
- docker.io/arangodb/arangodb:3.8.7
- docker.io/arangodb/arangodb:3.9.3
- docker.io/arangodb/arangodb-preview:3.10-nightly
- docker.io/arangodb/enterprise:3.8.7
- docker.io/arangodb/enterprise:3.9.3
- docker.io/arangodb/enterprise-preview:3.10-nightly
- docker.io/arangodb/arangodb:3.8.8
- docker.io/arangodb/arangodb:3.9.5
- docker.io/arangodb/arangodb:3.10.1
- docker.io/arangodb/enterprise:3.8.8
- docker.io/arangodb/enterprise:3.9.5
- docker.io/arangodb/enterprise:3.10.1
topology:
- single
- cluster
Expand All @@ -39,12 +39,12 @@ jobs:
user-language:
- en
include:
- docker-img: docker.io/arangodb/arangodb:3.9.3
- docker-img: docker.io/arangodb/arangodb:3.10.1
topology: single
db-ext-names: true
java-version: 11
user-language: tr
- docker-img: docker.io/arangodb/enterprise:3.9.3
- docker-img: docker.io/arangodb/enterprise:3.10.1
topology: cluster
db-ext-names: true
java-version: 17
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
fail-fast: false
matrix:
docker-img:
- docker.io/arangodb/enterprise:3.9.3
- docker.io/arangodb/enterprise:3.10.1
topology:
- single
- cluster
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
fail-fast: false
matrix:
docker-img:
- docker.io/arangodb/enterprise:3.9.1
- docker.io/arangodb/enterprise:3.10.1
topology:
- cluster
db-ext-names:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
docker-img:
- docker.io/arangodb/enterprise:3.9.3
- docker.io/arangodb/enterprise:3.10.1
topology:
- cluster
db-ext-names:
Expand Down
2 changes: 1 addition & 1 deletion docker/start_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ docker run -d \
--auth.jwt-secret=/jwtSecret \
--starter.address="${GW}" \
--docker.image="${DOCKER_IMAGE}" \
--starter.local --starter.mode=${STARTER_MODE} --all.log.level=debug --all.log.output=+ --log.verbose
--starter.local --starter.mode=${STARTER_MODE} --all.log.level=debug --all.log.output=+ --log.verbose --all.server.descriptors-minimum=1024


wait_server() {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CollectionLink {
private final Collection<FieldLink> fields;
private final Collection<FieldLink> nested;
private Boolean inBackground;
private Boolean cache;

private CollectionLink(final String name) {
super();
Expand Down Expand Up @@ -125,6 +126,19 @@ public CollectionLink inBackground(final Boolean inBackground) {
return this;
}

/**
* @param cache If you enable this option, then field normalization values are always cached in memory. This can
* improve the performance of scoring and ranking queries. Otherwise, these values are memory-mapped
* and it is up to the operating system to load them from disk into memory and to evict them from
* memory.
* @return link
* @since ArangoDB 3.9.5, Enterprise Edition only
*/
public CollectionLink cache(final Boolean cache) {
this.cache = cache;
return this;
}

public String getName() {
return name;
}
Expand Down Expand Up @@ -156,4 +170,7 @@ public Collection<FieldLink> getNested() {
public Boolean getInBackground() {
return inBackground;
}
public Boolean getCache() {
return cache;
}
}
17 changes: 14 additions & 3 deletions src/main/java/com/arangodb/entity/arangosearch/StoredValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ public class StoredValue {

private final List<String> fields;
private final ArangoSearchCompression compression;
private final Boolean cache;

/**
* @param fields A list of attribute paths. The . character denotes sub-attributes.
* @param compression Defines how to compress the attribute values.
* @param cache Whether to cache stored values in memory. (Since ArangoDB 3.9.5, Enterprise Edition only)
*/
public StoredValue(List<String> fields, ArangoSearchCompression compression) {
public StoredValue(List<String> fields, ArangoSearchCompression compression, Boolean cache) {
this.fields = fields;
this.compression = compression;
this.cache = cache;
}

public StoredValue(List<String> fields, ArangoSearchCompression compression) {
this(fields, compression, null);
}

public StoredValue(List<String> fields) {
Expand All @@ -55,16 +62,20 @@ public ArangoSearchCompression getCompression() {
return compression;
}

public Boolean getCache() {
return cache;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StoredValue that = (StoredValue) o;
return Objects.equals(fields, that.fields) && compression == that.compression;
return Objects.equals(fields, that.fields) && compression == that.compression && Objects.equals(cache, that.cache);
}

@Override
public int hashCode() {
return Objects.hash(fields, compression);
return Objects.hash(fields, compression, cache);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ public class VPackDeserializers {
public static final VPackDeserializer<StoredValue> STORED_VALUE = (parent, vpack, context) -> {
VPackSlice fields = vpack.get("fields");
VPackSlice compression = vpack.get("compression");
VPackSlice cache = vpack.get("cache");
Boolean cacheValue = cache.isBoolean() ? cache.getAsBoolean() : null;
final Iterator<VPackSlice> fieldsIterator = fields.arrayIterator();
List<String> fieldsList = new ArrayList<>();
while (fieldsIterator.hasNext()) {
fieldsList.add(fieldsIterator.next().getAsString());
}
return new StoredValue(fieldsList, ArangoSearchCompression.valueOf(compression.getAsString()));
return new StoredValue(fieldsList, ArangoSearchCompression.valueOf(compression.getAsString()), cacheValue);
};

public static final VPackDeserializer<ArangoSearchProperties> ARANGO_SEARCH_PROPERTIES = (parent, vpack, context) -> {
Expand Down Expand Up @@ -205,6 +207,10 @@ public class VPackDeserializers {
if (includeAllFields.isBoolean()) {
link.includeAllFields(includeAllFields.getAsBoolean());
}
final VPackSlice cache = value.get("cache");
if (cache.isBoolean()) {
link.cache(cache.getAsBoolean());
}
final VPackSlice trackListPositions = value.get("trackListPositions");
if (trackListPositions.isBoolean()) {
link.trackListPositions(trackListPositions.getAsBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.arangodb.model.TraversalOptions.Order;
import com.arangodb.model.ZKDIndexOptions;
import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions;
import com.arangodb.model.arangosearch.SearchAliasCreateOptions;
import com.arangodb.velocypack.*;
import com.arangodb.velocystream.Request;

Expand Down Expand Up @@ -193,6 +192,10 @@ public class VPackSerializers {
if (inBackground != null) {
builder.add("inBackground", inBackground);
}
Boolean cache = collectionLink.getCache();
if (cache != null) {
builder.add("cache", cache);
}
serializeFieldLinks(builder, collectionLink.getFields());
serializeNested(builder, collectionLink.getNested());
builder.close();
Expand Down Expand Up @@ -255,6 +258,9 @@ public class VPackSerializers {
if (value.getCompression() != null) {
builder.add("compression", value.getCompression().getValue());
}
if (value.getCache() != null) {
builder.add("cache", value.getCache());
}
builder.close(); // close object
};

Expand Down
13 changes: 12 additions & 1 deletion src/test/java/com/arangodb/ArangoSearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -918,11 +918,14 @@ void arangoSearchOptions(ArangoDatabase db) {
.includeAllFields(true)
.storeValues(StoreValuesType.ID)
.trackListPositions(false)
.inBackground(true);
.inBackground(true)
.cache(true);
if (isEnterprise()) {
link.nested(FieldLink.on("f3"));
}
ArangoSearchCreateOptions options = new ArangoSearchCreateOptions().link(link);
StoredValue storedValue = new StoredValue(Arrays.asList("a", "b"), ArangoSearchCompression.none, true);
options.storedValues(storedValue);

final ArangoSearch view = db.arangoSearch(viewName);
view.create(options);
Expand All @@ -940,6 +943,14 @@ void arangoSearchOptions(ArangoDatabase db) {
assertThat(createdLink.getIncludeAllFields()).isTrue();
assertThat(createdLink.getStoreValues()).isEqualTo(StoreValuesType.ID);
assertThat(createdLink.getTrackListPositions()).isFalse();

if (isEnterprise() && isAtLeastVersion(3, 9, 5) && isLessThanVersion(3, 10)) {
assertThat(createdLink.getCache()).isTrue();
assertThat(properties.getStoredValues())
.isNotEmpty()
.allSatisfy(it -> assertThat(it.getCache()).isTrue());
}

if (isEnterprise() && isAtLeastVersion(3, 10)) {
assertThat(createdLink.getNested()).isNotEmpty();
FieldLink nested = createdLink.getNested().iterator().next();
Expand Down