wu-sheng commented on a change in pull request #6499:
URL: https://github.com/apache/skywalking/pull/6499#discussion_r588948199
##########
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,40 +78,87 @@ 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 = PhysicalIndexManager.INSTANCE.getTableName(model);
+ PhysicalIndices.registerRelation(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()) {
+ if (!esClient.isExistsTemplate(tableName) ||
!isTemplateMappingCompatible(tableName, mapping)) {
+ Map<String, Object> templateMapping =
appendTemplateMapping(tableName, mapping);
+ boolean isAcknowledged = esClient.putTemplate(tableName,
settings, templateMapping);
+ log.info("create {} index template finished,
isAcknowledged: {}", tableName, isAcknowledged);
if (!isAcknowledged) {
- throw new StorageException("create " + model.getName()
+ " index template failure, ");
+ throw new StorageException("create " + tableName + "
index template failure, ");
}
}
indexName = TimeSeriesUtils.latestWriteIndexName(model);
+ } else {
+ indexName = tableName;
}
- if (!esClient.isExistsIndex(indexName)) {
- boolean isAcknowledged = esClient.createIndex(indexName);
+
+ if (esClient.isExistsIndex(indexName)) {
Review comment:
We need use ESInstaller to check whether this index was created through
the current booting process, if yes, it is safe to delete and recreate.
Otherwise, please terminate the booting with an error.
The compatibility check should be on index and template. If existing
template and index have the required columns and mapping, then booting could
continue. Extra columns are not the isssue.
We could set a checker, in the storage completed stage, to check whether all
physical indices matching the column. Only check, don't manipulate.
----------------------------------------------------------------
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]