Skip to content

[DE-961] added missing collection options #590

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 1 commit into from
Dec 10, 2024
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 @@ -27,72 +27,86 @@
*/
public final class CollectionPropertiesEntity extends CollectionEntity {

private Boolean cacheEnabled;
private String distributeShardsLike;
private Boolean isDisjoint;
private Boolean isSmart;
private KeyOptions keyOptions;
private Long count;
private Integer numberOfShards;
private Collection<String> shardKeys;
private ReplicationFactor replicationFactor;
private Integer writeConcern;
private Collection<String> shardKeys;
private String shardingStrategy; // cluster option
private String smartGraphAttribute;
private String smartJoinAttribute; // enterprise option
private Integer writeConcern;
private Long count;

public CollectionPropertiesEntity() {
super();
}

public KeyOptions getKeyOptions() {
return keyOptions;
public Boolean getCacheEnabled() {
return cacheEnabled;
}

public void setKeyOptions(final KeyOptions keyOptions) {
this.keyOptions = keyOptions;
public void setCacheEnabled(Boolean cacheEnabled) {
this.cacheEnabled = cacheEnabled;
}

public Long getCount() {
return count;
public String getDistributeShardsLike() {
return distributeShardsLike;
}

public void setCount(final Long count) {
this.count = count;
public void setDistributeShardsLike(String distributeShardsLike) {
this.distributeShardsLike = distributeShardsLike;
}

/**
* @return the number of shards of the collection. Only in a cluster setup (else returning null).
*/
public Integer getNumberOfShards() {
return numberOfShards;
public Boolean getDisjoint() {
return isDisjoint;
}

public void setNumberOfShards(final Integer numberOfShards) {
this.numberOfShards = numberOfShards;
public void setDisjoint(Boolean disjoint) {
isDisjoint = disjoint;
}

/**
* @return the names of document attributes that are used to determine the target shard for documents.
* Only in a cluster setup (else returning null).
*/
public Collection<String> getShardKeys() {
return shardKeys;
public Boolean getSmart() {
return isSmart;
}

public void setShardKeys(final Collection<String> shardKeys) {
this.shardKeys = shardKeys;
public void setSmart(Boolean smart) {
isSmart = smart;
}

public KeyOptions getKeyOptions() {
return keyOptions;
}

public void setKeyOptions(KeyOptions keyOptions) {
this.keyOptions = keyOptions;
}

public Integer getNumberOfShards() {
return numberOfShards;
}

public void setNumberOfShards(Integer numberOfShards) {
this.numberOfShards = numberOfShards;
}

public ReplicationFactor getReplicationFactor() {
return replicationFactor;
}

public void setReplicationFactor(final ReplicationFactor replicationFactor) {
public void setReplicationFactor(ReplicationFactor replicationFactor) {
this.replicationFactor = replicationFactor;
}

public Integer getWriteConcern() {
return writeConcern;
public Collection<String> getShardKeys() {
return shardKeys;
}

public void setWriteConcern(final Integer writeConcern) {
this.writeConcern = writeConcern;
public void setShardKeys(Collection<String> shardKeys) {
this.shardKeys = shardKeys;
}

public String getShardingStrategy() {
Expand All @@ -103,6 +117,14 @@ public void setShardingStrategy(String shardingStrategy) {
this.shardingStrategy = shardingStrategy;
}

public String getSmartGraphAttribute() {
return smartGraphAttribute;
}

public void setSmartGraphAttribute(String smartGraphAttribute) {
this.smartGraphAttribute = smartGraphAttribute;
}

public String getSmartJoinAttribute() {
return smartJoinAttribute;
}
Expand All @@ -111,4 +133,19 @@ public void setSmartJoinAttribute(String smartJoinAttribute) {
this.smartJoinAttribute = smartJoinAttribute;
}

public Integer getWriteConcern() {
return writeConcern;
}

public void setWriteConcern(Integer writeConcern) {
this.writeConcern = writeConcern;
}

public Long getCount() {
return count;
}

public void setCount(Long count) {
this.count = count;
}
}
111 changes: 91 additions & 20 deletions core/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

package com.arangodb.model;

import com.arangodb.entity.ReplicationFactor;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -29,56 +32,124 @@
*/
public final class CollectionPropertiesOptions {

private Boolean waitForSync;
private CollectionSchema schema;
private Boolean cacheEnabled;
private List<ComputedValue> computedValues;
private ReplicationFactor replicationFactor;
private CollectionSchema schema;
private Boolean waitForSync;
private Integer writeConcern;

public CollectionPropertiesOptions() {
super();
}

public Boolean getWaitForSync() {
return waitForSync;
public Boolean getCacheEnabled() {
return cacheEnabled;
}

/**
* @param waitForSync If true then creating or changing a document will wait until the data has been synchronized
* to disk.
* @return options
* @param cacheEnabled Whether the in-memory hash cache for documents should be enabled for this collection. Can be
* controlled globally with the --cache.size startup option. The cache can speed up repeated
* reads of the same documents via their document keys. If the same documents are not fetched
* often or are modified frequently, then you may disable the cache to avoid the maintenance
* costs.
* @return this
*/
public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) {
this.waitForSync = waitForSync;
public CollectionPropertiesOptions cacheEnabled(final Boolean cacheEnabled) {
this.cacheEnabled = cacheEnabled;
return this;
}

public List<ComputedValue> getComputedValues() {
return computedValues;
}

/**
* @param computedValues An optional list of computed values.
* @return this
* @since ArangoDB 3.10
*/
public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) {
if (this.computedValues == null) {
this.computedValues = new ArrayList<>();
}
Collections.addAll(this.computedValues, computedValues);
return this;
}

public ReplicationFactor getReplicationFactor() {
return replicationFactor;
}

/**
* @param replicationFactor In a cluster, this attribute determines how many copies of each shard are kept on
* different DB-Servers. The value 1 means that only one copy (no synchronous replication)
* is kept. A value of k means that k-1 replicas are kept. For SatelliteCollections, it
* needs to be the string "satellite", which matches the replication factor to the number
* of DB-Servers (Enterprise Edition only).
* <p>
* Any two copies reside on different DB-Servers. Replication between them is synchronous,
* that is, every write operation to the “leader” copy will be replicated to all “follower”
* replicas, before the write operation is reported successful.
* <p>
* If a server fails, this is detected automatically and one of the servers holding copies
* take over, usually without an error being reported.
* @return this
*/
public CollectionPropertiesOptions replicationFactor(final ReplicationFactor replicationFactor) {
this.replicationFactor = replicationFactor;
return this;
}

@JsonInclude(JsonInclude.Include.ALWAYS)
public CollectionSchema getSchema() {
return schema;
}

/**
* @param schema object that specifies the collection level schema for documents
* @return options
* @return this
* @since ArangoDB 3.7
*/
public CollectionPropertiesOptions schema(final CollectionSchema schema) {
this.schema = schema;
return this;
}

public Boolean getWaitForSync() {
return waitForSync;
}

/**
* @param computedValues An optional list of computed values.
* @return options
* @since ArangoDB 3.10
* @param waitForSync If true then creating or changing a document will wait until the data has been synchronized
* to disk.
* @return this
*/
public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) {
if(this.computedValues == null) {
this.computedValues = new ArrayList<>();
}
Collections.addAll(this.computedValues, computedValues);
public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) {
this.waitForSync = waitForSync;
return this;
}

public List<ComputedValue> getComputedValues() {
return computedValues;
public Integer getWriteConcern() {
return writeConcern;
}

/**
* @param writeConcern Determines how many copies of each shard are required to be in sync on the different
* DB-Servers. If there are less than these many copies in the cluster, a shard refuses to
* write. Writes to shards with enough up-to-date copies succeed at the same time, however.
* The value of writeConcern cannot be greater than replicationFactor.
* <p>
* If distributeShardsLike is set, the default writeConcern is that of the prototype collection.
* For SatelliteCollections, the writeConcern is automatically controlled to equal the number of
* DB-Servers and has a value of 0. Otherwise, the default value is controlled by the current
* database’s default writeConcern, which uses the --cluster.write-concern startup option as
* default, which defaults to 1. (cluster only)
* @return this
*/
public CollectionPropertiesOptions writeConcern(final Integer writeConcern) {
this.writeConcern = writeConcern;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3453,36 +3453,51 @@ void getPropeties(ArangoCollection collection) {
@ParameterizedTest
@MethodSource("cols")
void changeProperties(ArangoCollection collection) {
assumeTrue(isCluster());
final CollectionPropertiesEntity properties = collection.getProperties();
assertThat(properties.getWaitForSync()).isNotNull();
if (isAtLeastVersion(3, 7)) {
assertThat(properties.getSchema()).isNull();
}
assertThat(properties.getSchema()).isNull();

String schemaRule = ("{ " + " \"properties\": {" + " \"number\": {" + " " +
" \"type\": \"number\"" + " }" + " }" + " }").replaceAll("\\s", "");
String schemaMessage = "The document has problems!";

CollectionPropertiesOptions updatedOptions =
new CollectionPropertiesOptions().waitForSync(!properties.getWaitForSync()).schema(new CollectionSchema().setLevel(CollectionSchema.Level.NEW).setMessage(schemaMessage).setRule(schemaRule));
new CollectionPropertiesOptions()
.cacheEnabled(!properties.getCacheEnabled())
.computedValues(new ComputedValue()
.name("foo")
.expression("RETURN 11")
.overwrite(false)
.computeOn(ComputedValue.ComputeOn.insert)
.keepNull(false)
.failOnWarning(true))
.replicationFactor(ReplicationFactor.of(3))
.schema(new CollectionSchema().setLevel(CollectionSchema.Level.NEW).setMessage(schemaMessage).setRule(schemaRule))
.waitForSync(!properties.getWaitForSync())
.writeConcern(2);

final CollectionPropertiesEntity changedProperties = collection.changeProperties(updatedOptions);
assertThat(changedProperties.getWaitForSync()).isNotNull();
assertThat(changedProperties.getWaitForSync()).isEqualTo(!properties.getWaitForSync());
if (isAtLeastVersion(3, 7)) {
assertThat(changedProperties.getSchema()).isNotNull();
assertThat(changedProperties.getSchema().getLevel()).isEqualTo(CollectionSchema.Level.NEW);
assertThat(changedProperties.getSchema().getMessage()).isEqualTo(schemaMessage);
assertThat(changedProperties.getSchema().getRule()).isEqualTo(schemaRule);
}
assertThat(changedProperties.getCacheEnabled()).isEqualTo(updatedOptions.getCacheEnabled());
assertThat(changedProperties.getComputedValues())
.hasSize(1)
.contains(updatedOptions.getComputedValues().get(0));
assertThat(changedProperties.getReplicationFactor().get()).isEqualTo(updatedOptions.getReplicationFactor().get());
assertThat(changedProperties.getSchema().getLevel()).isEqualTo(CollectionSchema.Level.NEW);
assertThat(changedProperties.getSchema().getMessage()).isEqualTo(schemaMessage);
assertThat(changedProperties.getSchema().getRule()).isEqualTo(schemaRule);
assertThat(changedProperties.getWaitForSync()).isEqualTo(updatedOptions.getWaitForSync());
assertThat(changedProperties.getWriteConcern()).isEqualTo(updatedOptions.getWriteConcern());

// revert changes
CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions()
.waitForSync(properties.getWaitForSync()).schema(new CollectionSchema()));
if (isAtLeastVersion(3, 7)) {
assertThat(revertedProperties.getSchema()).isNull();
}

CollectionPropertiesOptions revertOptions = new CollectionPropertiesOptions()
.cacheEnabled(properties.getCacheEnabled())
.computedValues()
.replicationFactor(properties.getReplicationFactor())
.schema(properties.getSchema())
.waitForSync(properties.getWaitForSync())
.writeConcern(properties.getWriteConcern());
collection.changeProperties(revertOptions);
}

@ParameterizedTest
Expand Down