private void checkTopNAggregation(Model model, BanyanDBClient client) throws BanyanDBException {
        MetadataRegistry.Schema schema = MetadataRegistry.INSTANCE.findMetadata(model);
        String topNName = MetadataRegistry.Schema.formatTopNName(schema.getMetadata().name());
        TopNAggregation hisTopNAggregation = client.findTopNAggregation(schema.getMetadata().getGroup(), topNName);

        if (schema.getTopNSpec() != null) {
            TopNAggregation topNAggregation = schema.getTopNSpec();
            if (hisTopNAggregation == null) {
                try {
                    client.define(topNAggregation);
                    log.info("new TopNAggregation created: {}", topNAggregation);
                } catch (BanyanDBException ex) {
                    if (ex.getStatus().equals(Status.Code.ALREADY_EXISTS)) {
                        log.info("TopNAggregation {} already created by another OAP node", topNAggregation);
                    } else {
                        throw ex;
                    }
                }
            } else {
                boolean equals = hisTopNAggregation.toBuilder()
                                                   .clearUpdatedAt()
                                                   .clearMetadata()
                                                   .build()
                                                   .equals(topNAggregation.toBuilder().clearMetadata().build());
                if (!equals) {
                    client.update(topNAggregation);
                    log.info(
                        "update TopNAggregation: {} from: {} to: {}", hisTopNAggregation.getMetadata().getName(),
                        hisTopNAggregation, topNAggregation
                    );
                }
            }
        } else {
            if (hisTopNAggregation != null) {
                client.deleteTopNAggregation(schema.getMetadata().getGroup(), topNName);
                log.info(
                    "delete deprecated TopNAggregation: {} from group: {}", hisTopNAggregation.getMetadata().getName(),
                    schema.getMetadata().getGroup()
                );
            }
        }
    }
Check if the TopN aggregation exists and update it if necessary.
If the old TopN aggregation is not in the schema, delete it.
oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBIndexInstaller.java