Skip to content

Commit 0c98f8d

Browse files
authoredDec 10, 2024··
added missing collection options (DE-961) (#590)
1 parent 38bb1ac commit 0c98f8d

File tree

3 files changed

+192
-69
lines changed

3 files changed

+192
-69
lines changed
 

‎core/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java

+68-31
Original file line numberDiff line numberDiff line change
@@ -27,72 +27,86 @@
2727
*/
2828
public final class CollectionPropertiesEntity extends CollectionEntity {
2929

30+
private Boolean cacheEnabled;
31+
private String distributeShardsLike;
32+
private Boolean isDisjoint;
33+
private Boolean isSmart;
3034
private KeyOptions keyOptions;
31-
private Long count;
3235
private Integer numberOfShards;
33-
private Collection<String> shardKeys;
3436
private ReplicationFactor replicationFactor;
35-
private Integer writeConcern;
37+
private Collection<String> shardKeys;
3638
private String shardingStrategy; // cluster option
39+
private String smartGraphAttribute;
3740
private String smartJoinAttribute; // enterprise option
41+
private Integer writeConcern;
42+
private Long count;
3843

3944
public CollectionPropertiesEntity() {
4045
super();
4146
}
4247

43-
public KeyOptions getKeyOptions() {
44-
return keyOptions;
48+
public Boolean getCacheEnabled() {
49+
return cacheEnabled;
4550
}
4651

47-
public void setKeyOptions(final KeyOptions keyOptions) {
48-
this.keyOptions = keyOptions;
52+
public void setCacheEnabled(Boolean cacheEnabled) {
53+
this.cacheEnabled = cacheEnabled;
4954
}
5055

51-
public Long getCount() {
52-
return count;
56+
public String getDistributeShardsLike() {
57+
return distributeShardsLike;
5358
}
5459

55-
public void setCount(final Long count) {
56-
this.count = count;
60+
public void setDistributeShardsLike(String distributeShardsLike) {
61+
this.distributeShardsLike = distributeShardsLike;
5762
}
5863

59-
/**
60-
* @return the number of shards of the collection. Only in a cluster setup (else returning null).
61-
*/
62-
public Integer getNumberOfShards() {
63-
return numberOfShards;
64+
public Boolean getDisjoint() {
65+
return isDisjoint;
6466
}
6567

66-
public void setNumberOfShards(final Integer numberOfShards) {
67-
this.numberOfShards = numberOfShards;
68+
public void setDisjoint(Boolean disjoint) {
69+
isDisjoint = disjoint;
6870
}
6971

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

78-
public void setShardKeys(final Collection<String> shardKeys) {
79-
this.shardKeys = shardKeys;
76+
public void setSmart(Boolean smart) {
77+
isSmart = smart;
78+
}
79+
80+
public KeyOptions getKeyOptions() {
81+
return keyOptions;
82+
}
83+
84+
public void setKeyOptions(KeyOptions keyOptions) {
85+
this.keyOptions = keyOptions;
86+
}
87+
88+
public Integer getNumberOfShards() {
89+
return numberOfShards;
90+
}
91+
92+
public void setNumberOfShards(Integer numberOfShards) {
93+
this.numberOfShards = numberOfShards;
8094
}
8195

8296
public ReplicationFactor getReplicationFactor() {
8397
return replicationFactor;
8498
}
8599

86-
public void setReplicationFactor(final ReplicationFactor replicationFactor) {
100+
public void setReplicationFactor(ReplicationFactor replicationFactor) {
87101
this.replicationFactor = replicationFactor;
88102
}
89103

90-
public Integer getWriteConcern() {
91-
return writeConcern;
104+
public Collection<String> getShardKeys() {
105+
return shardKeys;
92106
}
93107

94-
public void setWriteConcern(final Integer writeConcern) {
95-
this.writeConcern = writeConcern;
108+
public void setShardKeys(Collection<String> shardKeys) {
109+
this.shardKeys = shardKeys;
96110
}
97111

98112
public String getShardingStrategy() {
@@ -103,6 +117,14 @@ public void setShardingStrategy(String shardingStrategy) {
103117
this.shardingStrategy = shardingStrategy;
104118
}
105119

120+
public String getSmartGraphAttribute() {
121+
return smartGraphAttribute;
122+
}
123+
124+
public void setSmartGraphAttribute(String smartGraphAttribute) {
125+
this.smartGraphAttribute = smartGraphAttribute;
126+
}
127+
106128
public String getSmartJoinAttribute() {
107129
return smartJoinAttribute;
108130
}
@@ -111,4 +133,19 @@ public void setSmartJoinAttribute(String smartJoinAttribute) {
111133
this.smartJoinAttribute = smartJoinAttribute;
112134
}
113135

136+
public Integer getWriteConcern() {
137+
return writeConcern;
138+
}
139+
140+
public void setWriteConcern(Integer writeConcern) {
141+
this.writeConcern = writeConcern;
142+
}
143+
144+
public Long getCount() {
145+
return count;
146+
}
147+
148+
public void setCount(Long count) {
149+
this.count = count;
150+
}
114151
}

‎core/src/main/java/com/arangodb/model/CollectionPropertiesOptions.java

+91-20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
package com.arangodb.model;
2222

23+
import com.arangodb.entity.ReplicationFactor;
24+
import com.fasterxml.jackson.annotation.JsonInclude;
25+
2326
import java.util.ArrayList;
2427
import java.util.Collections;
2528
import java.util.List;
@@ -29,56 +32,124 @@
2932
*/
3033
public final class CollectionPropertiesOptions {
3134

32-
private Boolean waitForSync;
33-
private CollectionSchema schema;
35+
private Boolean cacheEnabled;
3436
private List<ComputedValue> computedValues;
37+
private ReplicationFactor replicationFactor;
38+
private CollectionSchema schema;
39+
private Boolean waitForSync;
40+
private Integer writeConcern;
3541

3642
public CollectionPropertiesOptions() {
3743
super();
3844
}
3945

40-
public Boolean getWaitForSync() {
41-
return waitForSync;
46+
public Boolean getCacheEnabled() {
47+
return cacheEnabled;
4248
}
4349

4450
/**
45-
* @param waitForSync If true then creating or changing a document will wait until the data has been synchronized
46-
* to disk.
47-
* @return options
51+
* @param cacheEnabled Whether the in-memory hash cache for documents should be enabled for this collection. Can be
52+
* controlled globally with the --cache.size startup option. The cache can speed up repeated
53+
* reads of the same documents via their document keys. If the same documents are not fetched
54+
* often or are modified frequently, then you may disable the cache to avoid the maintenance
55+
* costs.
56+
* @return this
4857
*/
49-
public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) {
50-
this.waitForSync = waitForSync;
58+
public CollectionPropertiesOptions cacheEnabled(final Boolean cacheEnabled) {
59+
this.cacheEnabled = cacheEnabled;
60+
return this;
61+
}
62+
63+
public List<ComputedValue> getComputedValues() {
64+
return computedValues;
65+
}
66+
67+
/**
68+
* @param computedValues An optional list of computed values.
69+
* @return this
70+
* @since ArangoDB 3.10
71+
*/
72+
public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) {
73+
if (this.computedValues == null) {
74+
this.computedValues = new ArrayList<>();
75+
}
76+
Collections.addAll(this.computedValues, computedValues);
5177
return this;
5278
}
5379

80+
public ReplicationFactor getReplicationFactor() {
81+
return replicationFactor;
82+
}
83+
84+
/**
85+
* @param replicationFactor In a cluster, this attribute determines how many copies of each shard are kept on
86+
* different DB-Servers. The value 1 means that only one copy (no synchronous replication)
87+
* is kept. A value of k means that k-1 replicas are kept. For SatelliteCollections, it
88+
* needs to be the string "satellite", which matches the replication factor to the number
89+
* of DB-Servers (Enterprise Edition only).
90+
* <p>
91+
* Any two copies reside on different DB-Servers. Replication between them is synchronous,
92+
* that is, every write operation to the “leader” copy will be replicated to all “follower”
93+
* replicas, before the write operation is reported successful.
94+
* <p>
95+
* If a server fails, this is detected automatically and one of the servers holding copies
96+
* take over, usually without an error being reported.
97+
* @return this
98+
*/
99+
public CollectionPropertiesOptions replicationFactor(final ReplicationFactor replicationFactor) {
100+
this.replicationFactor = replicationFactor;
101+
return this;
102+
}
103+
104+
@JsonInclude(JsonInclude.Include.ALWAYS)
54105
public CollectionSchema getSchema() {
55106
return schema;
56107
}
57108

58109
/**
59110
* @param schema object that specifies the collection level schema for documents
60-
* @return options
111+
* @return this
61112
* @since ArangoDB 3.7
62113
*/
63114
public CollectionPropertiesOptions schema(final CollectionSchema schema) {
64115
this.schema = schema;
65116
return this;
66117
}
67118

119+
public Boolean getWaitForSync() {
120+
return waitForSync;
121+
}
122+
68123
/**
69-
* @param computedValues An optional list of computed values.
70-
* @return options
71-
* @since ArangoDB 3.10
124+
* @param waitForSync If true then creating or changing a document will wait until the data has been synchronized
125+
* to disk.
126+
* @return this
72127
*/
73-
public CollectionPropertiesOptions computedValues(final ComputedValue... computedValues) {
74-
if(this.computedValues == null) {
75-
this.computedValues = new ArrayList<>();
76-
}
77-
Collections.addAll(this.computedValues, computedValues);
128+
public CollectionPropertiesOptions waitForSync(final Boolean waitForSync) {
129+
this.waitForSync = waitForSync;
78130
return this;
79131
}
80132

81-
public List<ComputedValue> getComputedValues() {
82-
return computedValues;
133+
public Integer getWriteConcern() {
134+
return writeConcern;
83135
}
136+
137+
/**
138+
* @param writeConcern Determines how many copies of each shard are required to be in sync on the different
139+
* DB-Servers. If there are less than these many copies in the cluster, a shard refuses to
140+
* write. Writes to shards with enough up-to-date copies succeed at the same time, however.
141+
* The value of writeConcern cannot be greater than replicationFactor.
142+
* <p>
143+
* If distributeShardsLike is set, the default writeConcern is that of the prototype collection.
144+
* For SatelliteCollections, the writeConcern is automatically controlled to equal the number of
145+
* DB-Servers and has a value of 0. Otherwise, the default value is controlled by the current
146+
* database’s default writeConcern, which uses the --cluster.write-concern startup option as
147+
* default, which defaults to 1. (cluster only)
148+
* @return this
149+
*/
150+
public CollectionPropertiesOptions writeConcern(final Integer writeConcern) {
151+
this.writeConcern = writeConcern;
152+
return this;
153+
}
154+
84155
}

‎test-functional/src/test/java/com/arangodb/ArangoCollectionTest.java

+33-18
Original file line numberDiff line numberDiff line change
@@ -3453,36 +3453,51 @@ void getPropeties(ArangoCollection collection) {
34533453
@ParameterizedTest
34543454
@MethodSource("cols")
34553455
void changeProperties(ArangoCollection collection) {
3456+
assumeTrue(isCluster());
34563457
final CollectionPropertiesEntity properties = collection.getProperties();
34573458
assertThat(properties.getWaitForSync()).isNotNull();
3458-
if (isAtLeastVersion(3, 7)) {
3459-
assertThat(properties.getSchema()).isNull();
3460-
}
3459+
assertThat(properties.getSchema()).isNull();
34613460

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

34663465
CollectionPropertiesOptions updatedOptions =
3467-
new CollectionPropertiesOptions().waitForSync(!properties.getWaitForSync()).schema(new CollectionSchema().setLevel(CollectionSchema.Level.NEW).setMessage(schemaMessage).setRule(schemaRule));
3466+
new CollectionPropertiesOptions()
3467+
.cacheEnabled(!properties.getCacheEnabled())
3468+
.computedValues(new ComputedValue()
3469+
.name("foo")
3470+
.expression("RETURN 11")
3471+
.overwrite(false)
3472+
.computeOn(ComputedValue.ComputeOn.insert)
3473+
.keepNull(false)
3474+
.failOnWarning(true))
3475+
.replicationFactor(ReplicationFactor.of(3))
3476+
.schema(new CollectionSchema().setLevel(CollectionSchema.Level.NEW).setMessage(schemaMessage).setRule(schemaRule))
3477+
.waitForSync(!properties.getWaitForSync())
3478+
.writeConcern(2);
34683479

34693480
final CollectionPropertiesEntity changedProperties = collection.changeProperties(updatedOptions);
3470-
assertThat(changedProperties.getWaitForSync()).isNotNull();
3471-
assertThat(changedProperties.getWaitForSync()).isEqualTo(!properties.getWaitForSync());
3472-
if (isAtLeastVersion(3, 7)) {
3473-
assertThat(changedProperties.getSchema()).isNotNull();
3474-
assertThat(changedProperties.getSchema().getLevel()).isEqualTo(CollectionSchema.Level.NEW);
3475-
assertThat(changedProperties.getSchema().getMessage()).isEqualTo(schemaMessage);
3476-
assertThat(changedProperties.getSchema().getRule()).isEqualTo(schemaRule);
3477-
}
3481+
assertThat(changedProperties.getCacheEnabled()).isEqualTo(updatedOptions.getCacheEnabled());
3482+
assertThat(changedProperties.getComputedValues())
3483+
.hasSize(1)
3484+
.contains(updatedOptions.getComputedValues().get(0));
3485+
assertThat(changedProperties.getReplicationFactor().get()).isEqualTo(updatedOptions.getReplicationFactor().get());
3486+
assertThat(changedProperties.getSchema().getLevel()).isEqualTo(CollectionSchema.Level.NEW);
3487+
assertThat(changedProperties.getSchema().getMessage()).isEqualTo(schemaMessage);
3488+
assertThat(changedProperties.getSchema().getRule()).isEqualTo(schemaRule);
3489+
assertThat(changedProperties.getWaitForSync()).isEqualTo(updatedOptions.getWaitForSync());
3490+
assertThat(changedProperties.getWriteConcern()).isEqualTo(updatedOptions.getWriteConcern());
34783491

34793492
// revert changes
3480-
CollectionPropertiesEntity revertedProperties = collection.changeProperties(new CollectionPropertiesOptions()
3481-
.waitForSync(properties.getWaitForSync()).schema(new CollectionSchema()));
3482-
if (isAtLeastVersion(3, 7)) {
3483-
assertThat(revertedProperties.getSchema()).isNull();
3484-
}
3485-
3493+
CollectionPropertiesOptions revertOptions = new CollectionPropertiesOptions()
3494+
.cacheEnabled(properties.getCacheEnabled())
3495+
.computedValues()
3496+
.replicationFactor(properties.getReplicationFactor())
3497+
.schema(properties.getSchema())
3498+
.waitForSync(properties.getWaitForSync())
3499+
.writeConcern(properties.getWriteConcern());
3500+
collection.changeProperties(revertOptions);
34863501
}
34873502

34883503
@ParameterizedTest

0 commit comments

Comments
 (0)
Please sign in to comment.