Skip to content

Commit 55eefa0

Browse files
denglimingclaude
andcommitted
Graph: GRAPH.CONSTRAINT CREATE replies PENDING; slow log test uses a heavy query
FalkorDB logs only queries of 10 ms or more. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 36221f7 commit 55eefa0

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎redisgraph/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ results use the compact protocol; property names and relationship types are reso
2222
| GRAPH.LIST | `RedisGraph.list()` | |
2323
| GRAPH.SLOWLOG | `RedisGraph.slowLog()` | |
2424
| GRAPH.CONFIG GET / SET | `RedisGraph.getConfig()`, `setConfig()` | |
25-
| GRAPH.CONSTRAINT CREATE | `RedisGraph.createConstraint()` | FalkorDB; enforced asynchronously, UNIQUE needs an index |
25+
| GRAPH.CONSTRAINT CREATE | `RedisGraph.createConstraint()` | FalkorDB; replies `PENDING`, enforced asynchronously, UNIQUE needs an index |
2626
| GRAPH.CONSTRAINT DROP | `RedisGraph.dropConstraint()` | FalkorDB |
2727
| GRAPH.COPY | `RedisGraph.copy()` | FalkorDB |
2828
| GRAPH.MEMORY USAGE | `RedisGraph.memoryUsage()` | FalkorDB |

‎redisgraph/src/main/java/io/github/dengliming/redismodule/redisgraph/RedisGraph.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,20 @@ public RFuture<ResultSet> readOnlyQueryAsync(String graphName, String query, lon
223223

224224

225225
/**
226-
* Creates a constraint (FalkorDB). Constraints are enforced asynchronously once the server has validated the
227-
* existing data; a UNIQUE constraint needs an exact-match index on the same properties first.
226+
* Creates a constraint (FalkorDB). The server replies {@code PENDING}: the constraint is validated against
227+
* existing data asynchronously and its status moves to {@code OPERATIONAL} (or {@code FAILED}), visible through
228+
* {@code CALL db.constraints()}. A UNIQUE constraint needs an exact-match index on the same properties first.
228229
* <p>
229230
* GRAPH.CONSTRAINT CREATE key MANDATORY|UNIQUE NODE label|RELATIONSHIP type PROPERTIES count prop...
231+
*
232+
* @return the server status, {@code PENDING} on success
230233
*/
231-
public boolean createConstraint(String graphName, ConstraintType type, EntityType entity, String labelOrType, String... properties) {
234+
public String createConstraint(String graphName, ConstraintType type, EntityType entity, String labelOrType, String... properties) {
232235
return get(createConstraintAsync(graphName, type, entity, labelOrType, properties));
233236
}
234237

235-
public RFuture<Boolean> createConstraintAsync(String graphName, ConstraintType type, EntityType entity, String labelOrType,
236-
String... properties) {
238+
public RFuture<String> createConstraintAsync(String graphName, ConstraintType type, EntityType entity, String labelOrType,
239+
String... properties) {
237240
return write(graphName, StringCodec.INSTANCE, GRAPH_CONSTRAINT_CREATE, constraintArgs(graphName, type, entity, labelOrType, properties));
238241
}
239242

‎redisgraph/src/main/java/io/github/dengliming/redismodule/redisgraph/protocol/RedisCommands.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public interface RedisCommands {
4343
RedisCommand<List<String>> GRAPH_PROFILE = new RedisCommand<>("GRAPH.PROFILE", new ObjectListReplayDecoder<>());
4444
RedisCommand<List<String>> GRAPH_EXPLAIN = new RedisCommand<>("GRAPH.EXPLAIN", new ObjectListReplayDecoder<>());
4545
// FalkorDB additions
46-
RedisCommand<Boolean> GRAPH_CONSTRAINT_CREATE = new RedisCommand<>("GRAPH.CONSTRAINT", "CREATE", new BooleanReplayConvertor());
46+
// replies PENDING: constraints are built asynchronously
47+
RedisCommand<String> GRAPH_CONSTRAINT_CREATE = new RedisCommand<>("GRAPH.CONSTRAINT", "CREATE");
4748
RedisCommand<Boolean> GRAPH_CONSTRAINT_DROP = new RedisCommand<>("GRAPH.CONSTRAINT", "DROP", new BooleanReplayConvertor());
4849
RedisCommand<Boolean> GRAPH_COPY = new RedisCommand<>("GRAPH.COPY", new BooleanReplayConvertor());
4950
RedisCommand<Map<String, Object>> GRAPH_MEMORY_USAGE = new RedisCommand<>("GRAPH.MEMORY", "USAGE", new ObjectMapReplayDecoder<String, Object>());

‎redisgraph/src/test/java/io/github/dengliming/redismodule/redisgraph/RedisGraphTest.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public void testList() {
6868
@Test
6969
public void testSlowLog() {
7070
RedisGraph redisGraph = getRedisGraph();
71-
assertThat(redisGraph.profile("social", "CREATE (:person{name:'roi',age:32})", 0L)).isNotEmpty();
72-
assertThat(redisGraph.profile("social", "CREATE (:person{name:'amit',age:30})", 0L)).isNotEmpty();
71+
// only queries taking 10 ms or more are logged, so run something deliberately heavy
72+
assertThat(redisGraph.query("social", "UNWIND range(1, 2000000) AS x RETURN count(x)", 0L)).isNotNull();
7373

7474
List<SlowLogItem> slowLogItems = redisGraph.slowLog("social");
75-
assertThat(slowLogItems).isNotNull();
76-
assertThat(slowLogItems.size()).isEqualTo(2);
77-
assertThat(slowLogItems.get(0).getCommand()).isEqualToIgnoringCase("GRAPH.PROFILE");
75+
assertThat(slowLogItems).isNotEmpty();
76+
assertThat(slowLogItems.get(0).getCommand()).isEqualToIgnoringCase("GRAPH.QUERY");
77+
assertThat(slowLogItems.get(0).getQuery()).contains("UNWIND");
7878
}
7979

8080
@Test
@@ -178,7 +178,7 @@ public void testFalkorDbCommands() throws InterruptedException {
178178
assertThat(redisGraph.query("social", "CREATE (:person{name:'roi',age:32})", 0L)).isNotNull();
179179

180180
// constraints are validated asynchronously against existing data before they are enforced
181-
assertThat(redisGraph.createConstraint("social", ConstraintType.MANDATORY, EntityType.NODE, "person", "name")).isTrue();
181+
assertThat(redisGraph.createConstraint("social", ConstraintType.MANDATORY, EntityType.NODE, "person", "name")).isEqualTo("PENDING");
182182
awaitConstraintStatus(redisGraph, "OPERATIONAL");
183183
assertThatThrownBy(() -> redisGraph.query("social", "CREATE (:person{age:1})", 0L)).isInstanceOf(RedisException.class);
184184
assertThat(redisGraph.dropConstraint("social", ConstraintType.MANDATORY, EntityType.NODE, "person", "name")).isTrue();

0 commit comments

Comments
 (0)