wu-sheng commented on a change in pull request #6499:
URL: https://github.com/apache/skywalking/pull/6499#discussion_r588866099
##########
File path:
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
##########
@@ -68,26 +94,39 @@ protected boolean isExists(Model model) throws
StorageException {
@Override
protected void createTable(Model model) throws StorageException {
ElasticSearchClient esClient = (ElasticSearchClient) client;
-
Map<String, Object> settings = createSetting(model);
Map<String, Object> mapping = createMapping(model);
- log.info("index {}'s columnTypeEsMapping builder str: {}",
esClient.formatIndexName(model.getName()), mapping
- .toString());
+ String tableName = StoragePartitioner.INSTANCE.getTableName(model);
+ StoragePartitioner.INSTANCE.registerTableRelation(model.getName(),
tableName);
+ log.info("index {}'s columnTypeEsMapping builder str: {}",
+ esClient.formatIndexName(tableName), mapping.toString()
+ );
+ String indexName;
try {
- String indexName;
- if (!model.isTimeSeries()) {
- indexName = model.getName();
- } else {
- if (!esClient.isExistsTemplate(model.getName())) {
- boolean isAcknowledged =
esClient.createTemplate(model.getName(), settings, mapping);
- log.info(
- "create {} index template finished, isAcknowledged:
{}", model.getName(), isAcknowledged);
+ if (model.isTimeSeries()) {
+ Map<String, Object> template = esClient.getTemplate(tableName);
+ if (!template.isEmpty()) {
+ appendTemplateMapping(tableName, (Map<String, Object>)
template.get("mappings"));
+ }
+ if (!containsTemplateMapping(tableName, mapping)) {
+ Map<String, Object> templateMapping =
appendTemplateMapping(tableName, mapping);
+ boolean isAcknowledged =
esClient.createTemplate(tableName, settings, templateMapping);
Review comment:
Then let's polish the logic like this
1. Check template existing.
2. If no template, creating.
3. If yes, check mapping compatible, then merging and update(put).
4. Create latest index.
----------------------------------------------------------------
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:
[email protected]