Skip to content

Commit ccac3a3

Browse files
committed
AQL CursorStats (DE-484)
1 parent 1317d3d commit ccac3a3

File tree

3 files changed

+125
-6
lines changed

3 files changed

+125
-6
lines changed

core/src/main/java/com/arangodb/entity/CursorStats.java

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,140 @@
66
import java.util.Map;
77

88
public final class CursorStats {
9-
10-
private Long fullCount;
119
private final Map<String, Object> properties = new HashMap<>();
10+
private Long writesExecuted;
11+
private Long writesIgnored;
12+
private Long scannedFull;
13+
private Long scannedIndex;
14+
private Long cursorsCreated;
15+
private Long cursorsRearmed;
16+
private Long cacheHits;
17+
private Long cacheMisses;
18+
private Long filtered;
19+
private Long httpRequests;
20+
private Long fullCount;
21+
private Double executionTime;
22+
private Long peakMemoryUsage;
1223

1324
@JsonAnySetter
1425
public void add(String key, Object value) {
1526
properties.put(key, value);
1627
}
1728

29+
public Object get(String key) {
30+
return properties.get(key);
31+
}
32+
33+
/**
34+
* @return The total number of data-modification operations successfully executed.
35+
*/
36+
public Long getWritesExecuted() {
37+
return writesExecuted;
38+
}
39+
40+
/**
41+
* @return The total number of data-modification operations that were unsuccessful, but have been ignored because of
42+
* the ignoreErrors query option.
43+
*/
44+
public Long getWritesIgnored() {
45+
return writesIgnored;
46+
}
47+
48+
/**
49+
* @return The total number of documents iterated over when scanning a collection without an index. Documents
50+
* scanned by subqueries are included in the result, but operations triggered by built-in or user-defined AQL
51+
* functions are not.
52+
*/
53+
public Long getScannedFull() {
54+
return scannedFull;
55+
}
56+
57+
/**
58+
* @return The total number of documents iterated over when scanning a collection using an index. Documents scanned
59+
* by subqueries are included in the result, but operations triggered by built-in or user-defined AQL functions are
60+
* not.
61+
*/
62+
public Long getScannedIndex() {
63+
return scannedIndex;
64+
}
65+
66+
/**
67+
* @return The total number of cursor objects created during query execution. Cursor objects are created for index
68+
* lookups.
69+
*/
70+
public Long getCursorsCreated() {
71+
return cursorsCreated;
72+
}
73+
74+
/**
75+
* @return The total number of times an existing cursor object was repurposed. Repurposing an existing cursor object
76+
* is normally more efficient compared to destroying an existing cursor object and creating a new one from scratch.
77+
*/
78+
public Long getCursorsRearmed() {
79+
return cursorsRearmed;
80+
}
81+
82+
/**
83+
* @return The total number of index entries read from in-memory caches for indexes of type edge or persistent. This
84+
* value is only non-zero when reading from indexes that have an in-memory cache enabled, and when the query allows
85+
* using the in-memory cache (i.e. using equality lookups on all index attributes).
86+
*/
87+
public Long getCacheHits() {
88+
return cacheHits;
89+
}
90+
91+
/**
92+
* @return The total number of cache read attempts for index entries that could not be served from in-memory caches
93+
* for indexes of type edge or persistent. This value is only non-zero when reading from indexes that have an
94+
* in-memory cache enabled, the query allows using the in-memory cache (i.e. using equality lookups on all index
95+
* attributes) and the looked up values are not present in the cache.
96+
*/
97+
public Long getCacheMisses() {
98+
return cacheMisses;
99+
}
100+
101+
/**
102+
* @return The total number of documents removed after executing a filter condition in a FilterNode or another node
103+
* that post-filters data. Note that nodes of the IndexNode type can also filter documents by selecting only the
104+
* required index range from a collection, and the filtered value only indicates how much filtering was done by a
105+
* post filter in the IndexNode itself or following FilterNode nodes. Nodes of the EnumerateCollectionNode and
106+
* TraversalNode types can also apply filter conditions and can report the number of filtered documents.
107+
*/
108+
public Long getFiltered() {
109+
return filtered;
110+
}
111+
112+
/**
113+
* @return The total number of cluster-internal HTTP requests performed.
114+
*/
115+
public Long getHttpRequests() {
116+
return httpRequests;
117+
}
118+
119+
/**
120+
* @return The total number of documents that matched the search condition if the query’s final top-level LIMIT
121+
* operation were not present. This attribute may only be returned if the fullCount option was set when starting the
122+
* query and only contains a sensible value if the query contains a LIMIT operation on the top level.
123+
*/
18124
public Long getFullCount() {
19125
return fullCount;
20126
}
21127

22-
public Object get(String key) {
23-
return properties.get(key);
128+
/**
129+
* @return The query execution time (wall-clock time) in seconds.
130+
*/
131+
public Double getExecutionTime() {
132+
return executionTime;
24133
}
25134

135+
/**
136+
* @return The maximum memory usage of the query while it was running. In a cluster, the memory accounting is done
137+
* per shard, and the memory usage reported is the peak memory usage value from the individual shards. Note that to
138+
* keep things lightweight, the per-query memory usage is tracked on a relatively high level, not including any
139+
* memory allocator overhead nor any memory used for temporary results calculations (e.g. memory
140+
* allocated/deallocated inside AQL expressions and function calls).
141+
*/
142+
public Long getPeakMemoryUsage() {
143+
return peakMemoryUsage;
144+
}
26145
}

driver/src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ void queryWithLimitAndFullCount(ArangoDatabase db) {
627627
assertThat((Iterator<?>) cursor).hasNext();
628628
}
629629
assertThat(cursor.getStats()).isNotNull();
630-
assertThat(((Number) cursor.getStats().get("executionTime")).doubleValue()).isPositive();
630+
assertThat(cursor.getStats().getExecutionTime()).isPositive();
631631
assertThat((cursor.getStats().getFullCount())).isGreaterThanOrEqualTo(10);
632632
}
633633

driver/src/test/java/com/arangodb/async/ArangoDatabaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void queryWithLimitAndFullCount() throws InterruptedException, ExecutionExceptio
493493
assertThat(cursor.hasNext()).isEqualTo(true);
494494
}
495495
assertThat(cursor.getStats()).isNotNull();
496-
assertThat(((Number) cursor.getStats().get("executionTime")).doubleValue()).isPositive();
496+
assertThat(cursor.getStats().getExecutionTime()).isPositive();
497497
assertThat((cursor.getStats().getFullCount())).isGreaterThanOrEqualTo(10);
498498
})
499499
.get();

0 commit comments

Comments
 (0)