From 9f95607643c39ca0dfd5d096be22fc37bb410d5e Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 7 Jun 2022 11:10:45 +0200 Subject: [PATCH] [DE-60] Deprecate usage of deprecated server API (#440) * request next cursor batch using POST method instead of PUT * deprecated collection id * deprecated load/unload collection * deprecated DocumentCreateOptions.overwrite() * deprecated minReplicationFactor in favor of writeConcern * deprecated traversal API --- .../java/com/arangodb/ArangoCollection.java | 4 ++ .../arangodb/async/ArangoCollectionAsync.java | 4 ++ .../com/arangodb/entity/CollectionEntity.java | 5 +++ .../entity/CollectionPropertiesEntity.java | 18 ++++++++- .../java/com/arangodb/entity/GraphEntity.java | 9 +++++ .../arangodb/entity/MinReplicationFactor.java | 4 ++ .../java/com/arangodb/entity/PathEntity.java | 1 + .../com/arangodb/entity/TraversalEntity.java | 1 + .../internal/InternalArangoDatabase.java | 2 +- .../model/CollectionCreateOptions.java | 24 +++++++++++ .../arangodb/model/DocumentCreateOptions.java | 2 + .../arangodb/model/GraphCreateOptions.java | 40 +++++++++++++++++++ .../java/com/arangodb/ArangoDatabaseTest.java | 6 +-- .../java/com/arangodb/ArangoGraphTest.java | 6 +-- .../arangodb/async/ArangoDatabaseTest.java | 6 +-- .../com/arangodb/async/ArangoGraphTest.java | 6 +-- 16 files changed, 124 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoCollection.java b/src/main/java/com/arangodb/ArangoCollection.java index 8c0b3935c..40a5cdfd7 100644 --- a/src/main/java/com/arangodb/ArangoCollection.java +++ b/src/main/java/com/arangodb/ArangoCollection.java @@ -661,7 +661,9 @@ MultiDocumentEntity> deleteDocuments( * @throws ArangoDBException * @see API * Documentation + * @deprecated MMFiles only */ + @Deprecated CollectionEntity load() throws ArangoDBException; /** @@ -672,7 +674,9 @@ MultiDocumentEntity> deleteDocuments( * @throws ArangoDBException * @see API * Documentation + * @deprecated MMFiles only */ + @Deprecated CollectionEntity unload() throws ArangoDBException; /** diff --git a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java index 1b63c1e3d..c54a7c8e1 100644 --- a/src/main/java/com/arangodb/async/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/async/ArangoCollectionAsync.java @@ -615,7 +615,9 @@ CompletableFuture ensureFulltextIndex( * @return information about the collection * @see API * Documentation + * @deprecated MMFiles only */ + @Deprecated CompletableFuture load(); /** @@ -625,7 +627,9 @@ CompletableFuture ensureFulltextIndex( * @return information about the collection * @see API * Documentation + * @deprecated MMFiles only */ + @Deprecated CompletableFuture unload(); /** diff --git a/src/main/java/com/arangodb/entity/CollectionEntity.java b/src/main/java/com/arangodb/entity/CollectionEntity.java index 4f6c9cd5c..c9b1a0e47 100644 --- a/src/main/java/com/arangodb/entity/CollectionEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionEntity.java @@ -41,6 +41,11 @@ public CollectionEntity() { super(); } + /** + * @deprecated Accessing collections by their internal ID instead of accessing them by name is deprecated and highly + * discouraged. This functionality may be removed in future versions of ArangoDB. + */ + @Deprecated public String getId() { return id; } diff --git a/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java b/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java index 14fc1fe92..506e3d49e 100644 --- a/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionPropertiesEntity.java @@ -38,7 +38,7 @@ public class CollectionPropertiesEntity extends CollectionEntity { private Collection shardKeys; private final ReplicationFactor replicationFactor; private final MinReplicationFactor minReplicationFactor; - + private Integer writeConcern; private String shardingStrategy; // cluster option private String smartJoinAttribute; // enterprise option @@ -119,14 +119,30 @@ public void setReplicationFactor(final Integer replicationFactor) { this.replicationFactor.setReplicationFactor(replicationFactor); } + /** + * @deprecated use {@link #getWriteConcern()} instead + */ + @Deprecated public Integer getMinReplicationFactor() { return minReplicationFactor.getMinReplicationFactor(); } + /** + * @deprecated use {@link #setWriteConcern(Integer)} instead + */ + @Deprecated public void setMinReplicationFactor(final Integer minReplicationFactor) { this.minReplicationFactor.setMinReplicationFactor(minReplicationFactor); } + public Integer getWriteConcern() { + return writeConcern; + } + + public void setWriteConcern(final Integer writeConcern) { + this.writeConcern = writeConcern; + } + /** * @return whether the collection is a satellite collection. Only in an enterprise cluster setup (else returning null). */ diff --git a/src/main/java/com/arangodb/entity/GraphEntity.java b/src/main/java/com/arangodb/entity/GraphEntity.java index 9fd615701..96dcc3299 100644 --- a/src/main/java/com/arangodb/entity/GraphEntity.java +++ b/src/main/java/com/arangodb/entity/GraphEntity.java @@ -41,6 +41,7 @@ public class GraphEntity implements Entity { private String smartGraphAttribute; private ReplicationFactor replicationFactor; private Integer minReplicationFactor; + private Integer writeConcern; public String getName() { return name != null ? name : _key; @@ -74,10 +75,18 @@ public Boolean getSatellite() { return this.replicationFactor.getSatellite(); } + /** + * @deprecated use {@link #getWriteConcern()} instead + */ + @Deprecated public Integer getMinReplicationFactor() { return minReplicationFactor; } + public Integer getWriteConcern() { + return writeConcern; + } + public String getSmartGraphAttribute() { return smartGraphAttribute; } diff --git a/src/main/java/com/arangodb/entity/MinReplicationFactor.java b/src/main/java/com/arangodb/entity/MinReplicationFactor.java index 60b39976e..5a1bfa915 100644 --- a/src/main/java/com/arangodb/entity/MinReplicationFactor.java +++ b/src/main/java/com/arangodb/entity/MinReplicationFactor.java @@ -20,9 +20,13 @@ package com.arangodb.entity; +import com.arangodb.model.CollectionCreateOptions; + /** * @author Heiko Kernbach + * @deprecated use {@link CollectionCreateOptions#writeConcern(Integer)} instead */ +@Deprecated public class MinReplicationFactor { private Integer minReplicationFactor; diff --git a/src/main/java/com/arangodb/entity/PathEntity.java b/src/main/java/com/arangodb/entity/PathEntity.java index 91bcc29c1..52f25840e 100644 --- a/src/main/java/com/arangodb/entity/PathEntity.java +++ b/src/main/java/com/arangodb/entity/PathEntity.java @@ -27,6 +27,7 @@ * @see API * Documentation */ +@Deprecated public class PathEntity implements Entity { private Collection edges; diff --git a/src/main/java/com/arangodb/entity/TraversalEntity.java b/src/main/java/com/arangodb/entity/TraversalEntity.java index 4dd679281..2d7f9a52a 100644 --- a/src/main/java/com/arangodb/entity/TraversalEntity.java +++ b/src/main/java/com/arangodb/entity/TraversalEntity.java @@ -27,6 +27,7 @@ * @see API * Documentation */ +@Deprecated public class TraversalEntity implements Entity { private Collection vertices; diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 179d9073e..933b5c175 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -186,7 +186,7 @@ protected Request queryRequest( protected Request queryNextRequest(final String id, final AqlQueryOptions options, Map meta) { - final Request request = request(dbName, RequestType.PUT, PATH_API_CURSOR, id); + final Request request = request(dbName, RequestType.POST, PATH_API_CURSOR, id); if (meta != null) { request.getHeaderParam().putAll(meta); diff --git a/src/main/java/com/arangodb/model/CollectionCreateOptions.java b/src/main/java/com/arangodb/model/CollectionCreateOptions.java index 0d3200ec4..63d7c5627 100644 --- a/src/main/java/com/arangodb/model/CollectionCreateOptions.java +++ b/src/main/java/com/arangodb/model/CollectionCreateOptions.java @@ -37,6 +37,7 @@ public class CollectionCreateOptions { private Long journalSize; private final ReplicationFactor replicationFactor; private final MinReplicationFactor minReplicationFactor; + private Integer writeConcern; private KeyOptions keyOptions; private Boolean waitForSync; private Boolean doCompact; @@ -89,6 +90,10 @@ public Integer getReplicationFactor() { return replicationFactor.getReplicationFactor(); } + /** + * @deprecated use {@link #getWriteConcern()} instead + */ + @Deprecated public Integer getMinReplicationFactor() { return minReplicationFactor.getMinReplicationFactor(); } @@ -118,12 +123,31 @@ public CollectionCreateOptions replicationFactor(final Integer replicationFactor * are allowed. Having `minReplicationFactor > 1` requires additional insync copies on follower servers * to allow writes. * @return options + * @deprecated use {@link #writeConcern(Integer)} instead */ + @Deprecated public CollectionCreateOptions minReplicationFactor(final Integer minReplicationFactor) { this.minReplicationFactor.setMinReplicationFactor(minReplicationFactor); return this; } + public Integer getWriteConcern() { + return writeConcern; + } + + /** + * @param writeConcern write concern for this collection (default: 1). + * It determines how many copies of each shard are required to be in sync on the different + * DB-Servers. If there are less then these many copies in the cluster a shard will refuse to + * write. Writes to shards with enough up-to-date copies will succeed at the same time however. + * The value of writeConcern can not be larger than replicationFactor. (cluster only) + * @return options + */ + public CollectionCreateOptions writeConcern(final Integer writeConcern) { + this.writeConcern = writeConcern; + return this; + } + public Boolean getSatellite() { return replicationFactor.getSatellite(); } diff --git a/src/main/java/com/arangodb/model/DocumentCreateOptions.java b/src/main/java/com/arangodb/model/DocumentCreateOptions.java index a1cda768d..3c8a52337 100644 --- a/src/main/java/com/arangodb/model/DocumentCreateOptions.java +++ b/src/main/java/com/arangodb/model/DocumentCreateOptions.java @@ -93,7 +93,9 @@ public Boolean getOverwrite() { * the old document. * @return options * @since ArangoDB 3.4 + * @deprecated use {@link #overwriteMode(OverwriteMode)} instead */ + @Deprecated public DocumentCreateOptions overwrite(final Boolean overwrite) { this.overwrite = overwrite; return this; diff --git a/src/main/java/com/arangodb/model/GraphCreateOptions.java b/src/main/java/com/arangodb/model/GraphCreateOptions.java index 25e681fec..cf06b3e4b 100644 --- a/src/main/java/com/arangodb/model/GraphCreateOptions.java +++ b/src/main/java/com/arangodb/model/GraphCreateOptions.java @@ -143,6 +143,10 @@ public GraphCreateOptions satellite(final Boolean satellite) { return this; } + /** + * @deprecated use {@link #getWriteConcern()} instead + */ + @Deprecated public Integer getMinReplicationFactor() { return getOptions().getMinReplicationFactor(); } @@ -157,12 +161,31 @@ public Integer getMinReplicationFactor() { * are allowed. Having `minReplicationFactor > 1` requires additional insync copies on follower servers * to allow writes. * @return options + * @deprecated use {@link #writeConcern(Integer)} instead */ + @Deprecated public GraphCreateOptions minReplicationFactor(final Integer minReplicationFactor) { getOptions().setMinReplicationFactor(minReplicationFactor); return this; } + public Integer getWriteConcern() { + return getOptions().getWriteConcern(); + } + + /** + * @param writeConcern Write concern for new collections in the graph. + * It determines how many copies of each shard are required to be in sync on the different + * DB-Servers. If there are less then these many copies in the cluster a shard will refuse to + * write. Writes to shards with enough up-to-date copies will succeed at the same time however. + * The value of writeConcern can not be larger than replicationFactor. (cluster only) + * @return options + */ + public GraphCreateOptions writeConcern(final Integer writeConcern) { + getOptions().setWriteConcern(writeConcern); + return this; + } + public Integer getNumberOfShards() { return getOptions().getNumberOfShards(); } @@ -216,6 +239,7 @@ private SmartOptions getOptions() { public static class SmartOptions { private ReplicationFactor replicationFactor; private Integer minReplicationFactor; + private Integer writeConcern; private Integer numberOfShards; private String smartGraphAttribute; private Boolean isDisjoint; @@ -242,14 +266,30 @@ public void setSatellite(final Boolean satellite) { replicationFactor.setSatellite(satellite); } + /** + * @deprecated use {{@link #getWriteConcern()}} instead + */ + @Deprecated public Integer getMinReplicationFactor() { return minReplicationFactor; } + /** + * @deprecated use {{@link #setWriteConcern(Integer)}} instead + */ + @Deprecated public void setMinReplicationFactor(final Integer minReplicationFactor) { this.minReplicationFactor = minReplicationFactor; } + public Integer getWriteConcern() { + return writeConcern; + } + + public void setWriteConcern(final Integer writeConcern) { + this.writeConcern = writeConcern; + } + public Integer getNumberOfShards() { return numberOfShards; } diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index 915cd7a36..4d6c5b10d 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -122,18 +122,18 @@ void createCollectionWithReplicationFactor(ArangoDatabase db) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void createCollectionWithMinReplicationFactor(ArangoDatabase db) { + void createCollectionWithWriteConcern(ArangoDatabase db) { assumeTrue(isAtLeastVersion(3, 5)); assumeTrue(isCluster()); String name = "collection-" + rnd(); final CollectionEntity result = db.createCollection(name, - new CollectionCreateOptions().replicationFactor(2).minReplicationFactor(2)); + new CollectionCreateOptions().replicationFactor(2).writeConcern(2)); assertThat(result).isNotNull(); assertThat(result.getId()).isNotNull(); CollectionPropertiesEntity props = db.collection(name).getProperties(); assertThat(props.getReplicationFactor()).isEqualTo(2); - assertThat(props.getMinReplicationFactor()).isEqualTo(2); + assertThat(props.getWriteConcern()).isEqualTo(2); assertThat(props.getSatellite()).isNull(); } diff --git a/src/test/java/com/arangodb/ArangoGraphTest.java b/src/test/java/com/arangodb/ArangoGraphTest.java index 731be3a54..93aa505ce 100644 --- a/src/test/java/com/arangodb/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/ArangoGraphTest.java @@ -87,15 +87,15 @@ void exists(ArangoGraph graph) { @ParameterizedTest(name = "{index}") @MethodSource("dbs") - void createWithReplicationAndMinReplicationFactor(ArangoDatabase db) { + void createWithReplicationAndWriteConcern(ArangoDatabase db) { assumeTrue(isAtLeastVersion(3, 5)); assumeTrue(isCluster()); final Collection edgeDefinitions = new ArrayList<>(); - final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2)); + final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).writeConcern(2)); assertThat(graph).isNotNull(); assertThat(graph.getName()).isEqualTo(GRAPH_NAME + "_1"); - assertThat(graph.getMinReplicationFactor()).isEqualTo(2); + assertThat(graph.getWriteConcern()).isEqualTo(2); assertThat(graph.getReplicationFactor()).isEqualTo(2); db.graph(GRAPH_NAME + "_1").drop(); } diff --git a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java index 93c0da44b..de76da620 100644 --- a/src/test/java/com/arangodb/async/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/async/ArangoDatabaseTest.java @@ -123,16 +123,16 @@ void createCollectionWithReplicationFactor() throws InterruptedException, Execut } @Test - void createCollectionWithMinReplicationFactor() throws ExecutionException, InterruptedException { + void createCollectionWithWriteConcern() throws ExecutionException, InterruptedException { assumeTrue(isAtLeastVersion(3, 5)); assumeTrue(isCluster()); final CollectionEntity result = db.createCollection(COLLECTION_NAME, - new CollectionCreateOptions().replicationFactor(2).minReplicationFactor(2)).get(); + new CollectionCreateOptions().replicationFactor(2).writeConcern(2)).get(); assertThat(result).isNotNull(); assertThat(result.getId()).isNotNull(); assertThat(db.collection(COLLECTION_NAME).getProperties().get().getReplicationFactor()).isEqualTo(2); - assertThat(db.collection(COLLECTION_NAME).getProperties().get().getMinReplicationFactor()).isEqualTo(2); + assertThat(db.collection(COLLECTION_NAME).getProperties().get().getWriteConcern()).isEqualTo(2); assertThat(db.collection(COLLECTION_NAME).getProperties().get().getSatellite()).isNull(); db.collection(COLLECTION_NAME).drop(); } diff --git a/src/test/java/com/arangodb/async/ArangoGraphTest.java b/src/test/java/com/arangodb/async/ArangoGraphTest.java index 19b91a03a..9513d4fec 100644 --- a/src/test/java/com/arangodb/async/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/async/ArangoGraphTest.java @@ -94,14 +94,14 @@ void create() throws InterruptedException, ExecutionException { } @Test - void createWithReplicationAndMinReplicationFactor() throws ExecutionException, InterruptedException { + void createWithReplicationAndWriteConcern() throws ExecutionException, InterruptedException { assumeTrue(isAtLeastVersion(3, 5)); assumeTrue(isCluster()); final Collection edgeDefinitions = new ArrayList<>(); - final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).minReplicationFactor(2)).get(); + final GraphEntity graph = db.createGraph(GRAPH_NAME + "_1", edgeDefinitions, new GraphCreateOptions().isSmart(true).replicationFactor(2).writeConcern(2)).get(); assertThat(graph).isNotNull(); assertThat(graph.getName()).isEqualTo(GRAPH_NAME + "_1"); - assertThat(graph.getMinReplicationFactor()).isEqualTo(2); + assertThat(graph.getWriteConcern()).isEqualTo(2); assertThat(graph.getReplicationFactor()).isEqualTo(2); db.graph(GRAPH_NAME + "_1").drop(); }