Skip to content

Commit

Permalink
Fix NPE in IndexService#getNodeMappingStats (#91334) (#91756)
Browse files Browse the repository at this point in the history
The field mapperService in IndexService can be null, which needs to be
handled in getNodeMappingStats. It returns a null in that case, which is
already handled by the caller CommonStats.

Co-authored-by: Stéphane Campinas <stephane.campinas@gmail.com>
  • Loading branch information
kingherc and scampi committed Nov 21, 2022
1 parent e82fb44 commit df619bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/changelog/91334.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 91334
summary: "Fix NPE in IndexService getNodeMappingStats"
area: "Stats"
type: bug
issues:
- 91259
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ public IndexShard getShard(int shardId) {
}

public NodeMappingStats getNodeMappingStats() {
if (mapperService == null) {
return null;
}
long totalCount = mapperService().mappingLookup().getTotalFieldsCount();
Index index = index();
long totalEstimatedOverhead = totalCount * 1024L; // 1KiB estimated per mapping
NodeMappingStats indexNodeMappingStats = new NodeMappingStats(totalCount, totalEstimatedOverhead);
return indexNodeMappingStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ public static CompressedXContent filter(QueryBuilder filterBuilder) throws IOExc
return new CompressedXContent(Strings.toString(builder));
}

public void testClosedIndexHasNullNodeMappingStats() throws Exception {
final IndexService indexService = createIndex("test", Settings.EMPTY);
ensureGreen("test");

final Index index = indexService.index();
assertAcked(client().admin().indices().prepareClose(index.getName()));
assertBusy(() -> assertTrue("Index not found: " + index.getName(), getInstanceFromNode(IndicesService.class).hasIndex(index)));

final IndexService closedIndexService = getInstanceFromNode(IndicesService.class).indexServiceSafe(index);
assertNotSame(indexService, closedIndexService);
assertNull(closedIndexService.getNodeMappingStats());
}

public void testBaseAsyncTask() throws Exception {
IndexService indexService = createIndex("test", Settings.EMPTY);
AtomicReference<CountDownLatch> latch = new AtomicReference<>(new CountDownLatch(1));
Expand Down

0 comments on commit df619bc

Please sign in to comment.