AngelaFabregues commented on code in PR #568:
URL: https://github.com/apache/jackrabbit-oak/pull/568#discussion_r874811773
##########
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticIndexStatistics.java:
##########
@@ -164,77 +157,59 @@ static <K, V> LoadingCache<K, V> setupCache(long maxSize,
long expireMin, long r
static class CountCacheLoader extends CacheLoader<StatsRequestDescriptor,
Integer> {
@Override
- public Integer load(StatsRequestDescriptor countRequestDescriptor)
throws IOException {
+ public Integer load(@NotNull StatsRequestDescriptor
countRequestDescriptor) throws IOException {
return count(countRequestDescriptor);
}
@Override
- public ListenableFuture<Integer> reload(StatsRequestDescriptor crd,
Integer oldValue) {
+ public ListenableFuture<Integer> reload(@NotNull
StatsRequestDescriptor crd, @NotNull Integer oldValue) {
ListenableFutureTask<Integer> task =
ListenableFutureTask.create(() -> count(crd));
Executors.newSingleThreadExecutor().execute(task);
return task;
}
private int count(StatsRequestDescriptor crd) throws IOException {
- CountRequest countRequest = new CountRequest(crd.index);
+ CountRequest.Builder cBuilder = new CountRequest.Builder();
+ cBuilder.index(crd.index);
if (crd.field != null) {
- countRequest.query(QueryBuilders.existsQuery(crd.field));
+ cBuilder.query(q -> q.exists(e -> e.field(crd.field)));
} else {
- countRequest.query(QueryBuilders.matchAllQuery());
+ cBuilder.query(q -> q.matchAll( m-> m));
}
-
- CountResponse response =
crd.connection.getClient().count(countRequest, RequestOptions.DEFAULT);
- return (int) response.getCount();
+ return (int)
crd.connection.getClient().count(cBuilder.build()).count();
}
}
static class StatsCacheLoader extends CacheLoader<StatsRequestDescriptor,
StatsResponse> {
- private static final ObjectMapper MAPPER = new ObjectMapper();
-
@Override
- public StatsResponse load(StatsRequestDescriptor
countRequestDescriptor) throws IOException {
+ public StatsResponse load(@NotNull StatsRequestDescriptor
countRequestDescriptor) throws IOException {
return stats(countRequestDescriptor);
}
@Override
- public ListenableFuture<StatsResponse> reload(StatsRequestDescriptor
crd, StatsResponse oldValue) {
+ public ListenableFuture<StatsResponse> reload(@NotNull
StatsRequestDescriptor crd, @NotNull StatsResponse oldValue) {
ListenableFutureTask<StatsResponse> task =
ListenableFutureTask.create(() -> stats(crd));
Executors.newSingleThreadExecutor().execute(task);
return task;
}
private StatsResponse stats(StatsRequestDescriptor crd) throws
IOException {
- RestClient lowLevelClient =
crd.connection.getClient().getLowLevelClient();
- // TODO: the elastic rest high-level client does not currently
support the index stats API.
- // We should switch to this once available, since the _cat API is
not intended for use by applications
- Response response = lowLevelClient.performRequest(
- new Request("GET", "/_cat/indices/" + crd.index
- +
"?format=json&h=store.size,creation.date,docs.count,docs.deleted&bytes=b&time=ms")
- );
-
- if (response != null) {
- String rawBody = EntityUtils.toString(response.getEntity());
- TypeReference<List<Map<String, String>>> typeRef = new
TypeReference<List<Map<String, String>>>() {};
- List<Map<String, String>> indices = MAPPER.readValue(rawBody,
typeRef);
-
- if (!indices.isEmpty()) {
- // we ask for a specific index, so we can get the first
entry
- Map<String, String> indexProps = indices.get(0);
- String size = indexProps.get("store.size");
- String creationDate = indexProps.get("creation.date");
- String luceneDocsCount = indexProps.get("docs.count");
- String luceneDocsDeleted = indexProps.get("docs.deleted");
- return new StatsResponse(
+ IndicesRecord record = crd.connection.getClient().cat().indices(i
-> i
Review Comment:
You are right, this is a potential null pointer exception. Line 198 ends
with getting the first element of a list which can potentially be empty, the
index has been deleted.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]