wu-sheng commented on a change in pull request #4353: Optimizing performance reduces es index queries scope by timebucket URL: https://github.com/apache/skywalking/pull/4353#discussion_r378225818
########## File path: oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/model/ModelName.java ########## @@ -30,10 +43,73 @@ public static String build(Downsampling downsampling, String modelName) { return modelName + Const.ID_SPLIT + Downsampling.Day.getName(); case Hour: return modelName + Const.ID_SPLIT + Downsampling.Hour.getName(); - // case Second: - // return modelName + Const.ID_SPLIT + Downsampling.Second.getName(); default: return modelName; } } + + public static String[] build(Downsampling downsampling, String modelName, long startTB, long endTB) { + List<String> indexNameList = new ArrayList<>(); + + List<String> whiteIndexList = new ArrayList<String>() { + { + add(EndpointInventory.INDEX_NAME); + add(NetworkAddressInventory.INDEX_NAME); + add(ServiceInventory.INDEX_NAME); + add(ServiceInstanceInventory.INDEX_NAME); + } + }; + + if (whiteIndexList.contains(modelName)) { + return new String[] { modelName }; + } + + DateTime startDT = DurationUtils.INSTANCE.startTimeBucket2DateTime(downsampling, startTB); + DateTime endDT = DurationUtils.INSTANCE.endTimeBucket2DateTime(downsampling, endTB); + if (endDT.isAfter(startDT)) { + switch (downsampling) { + case Month: + while (endDT.isAfter(startDT)) { + String indexName = build(downsampling, modelName) + "-" + YYYYMM.print(startDT); + indexNameList.add(indexName); + startDT = startDT.plusMonths(1); + } + break; + case Day: + while (endDT.isAfter(startDT)) { + String indexName = build(downsampling, modelName) + "-" + YYYYMMDD.print(startDT); + indexNameList.add(indexName); + startDT = startDT.plusDays(1); + } + break; + case Hour: + //current hour index is also suffix with YYYYMMDD + while (endDT.isAfter(startDT)) { + String indexName = build(downsampling, modelName) + "-" + YYYYMMDD.print(startDT); + indexNameList.add(indexName); + startDT = startDT.plusDays(1); + } + break; + case Minute: + //current minute index is also suffix with YYYYMMDD + while (endDT.isAfter(startDT)) { + String indexName = build(downsampling, modelName) + "-" + YYYYMMDD.print(startDT); + indexNameList.add(indexName); + startDT = startDT.plusDays(1); + } + break; + case Second: + //current second index is also suffix with YYYYMMDD + while (endDT.isAfter(startDT)) { + String indexName = build(downsampling, modelName) + "-" + YYYYMMDD.print(startDT); + indexNameList.add(indexName); + startDT = startDT.plusDays(1); + } + break; + default: + indexNameList.add(modelName); + } + } + return indexNameList.toArray(new String[0]); Review comment: Did you answer the question in the wrong context? I am not saying `filterNotExistIndex` is useless. But based on the things you talked, I think you should establish a cache to `filterNotExistIndex` and cache the result for at least a day, considering the index could only be deleted day by day, right? Set up a guava cache with `#expireAfterWrite`? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services