Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add archive restore retry on mapper parsing exception (6.1) #21258

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/pr-21197.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "fixed"
message = "Add archive restore retry on mapper parsing exception."

issues = ["graylog-plugin-enterprise#9208"]
pulls = ["21197", "Graylog2/graylog-plugin-enterprise#9413"]
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.graylog2.indexer.BatchSizeTooLargeException;
import org.graylog2.indexer.IndexNotFoundException;
import org.graylog2.indexer.InvalidWriteTargetException;
import org.graylog2.indexer.MapperParsingException;
import org.graylog2.indexer.MasterNotDiscoveredException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -202,6 +203,9 @@ private ElasticsearchException exceptionFrom(Exception e, String errorMessage) {
if (isBatchSizeTooLargeException(elasticsearchException)) {
throw new BatchSizeTooLargeException(elasticsearchException.getMessage());
}
if (isMapperParsingExceptionException(elasticsearchException)) {
throw new MapperParsingException(elasticsearchException.getMessage());
}
} else if (e instanceof IOException && e.getCause() instanceof ContentTooLongException) {
throw new BatchSizeTooLargeException(e.getMessage());
}
Expand Down Expand Up @@ -231,6 +235,10 @@ private boolean isIndexNotFoundException(ElasticsearchException elasticsearchExc
return elasticsearchException.getMessage().contains("index_not_found_exception");
}

private boolean isMapperParsingExceptionException(ElasticsearchException openSearchException) {
return openSearchException.getMessage().contains("mapper_parsing_exception");
}

private boolean isBatchSizeTooLargeException(ElasticsearchException elasticsearchException) {
if (elasticsearchException instanceof ElasticsearchStatusException statusException) {
if (statusException.getCause() instanceof ResponseException responseException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.graylog2.indexer.BatchSizeTooLargeException;
import org.graylog2.indexer.IndexNotFoundException;
import org.graylog2.indexer.InvalidWriteTargetException;
import org.graylog2.indexer.MapperParsingException;
import org.graylog2.indexer.MasterNotDiscoveredException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -202,6 +203,9 @@ private OpenSearchException exceptionFrom(Exception e, String errorMessage) {
if (isBatchSizeTooLargeException(openSearchException)) {
throw new BatchSizeTooLargeException(openSearchException.getMessage());
}
if (isMapperParsingExceptionException(openSearchException)) {
throw new MapperParsingException(openSearchException.getMessage());
}
} else if (e instanceof IOException && e.getCause() instanceof ContentTooLongException) {
throw new BatchSizeTooLargeException(e.getMessage());
}
Expand Down Expand Up @@ -231,6 +235,10 @@ private boolean isIndexNotFoundException(OpenSearchException openSearchException
return openSearchException.getMessage().contains("index_not_found_exception");
}

private boolean isMapperParsingExceptionException(OpenSearchException openSearchException) {
return openSearchException.getMessage().contains("mapper_parsing_exception");
}

private boolean isBatchSizeTooLargeException(OpenSearchException openSearchException) {
if (openSearchException instanceof OpenSearchStatusException statusException) {
if (statusException.getCause() instanceof ResponseException responseException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.graylog2.indexer;

public class MapperParsingException extends ElasticsearchException {
public MapperParsingException(String errorMessage) {
super(errorMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.graylog2.indexer.IndexNotFoundException;
import org.graylog2.indexer.IndexSet;
import org.graylog2.indexer.IndexTemplateNotFoundException;
import org.graylog2.indexer.MapperParsingException;
import org.graylog2.indexer.indexset.CustomFieldMappings;
import org.graylog2.indexer.indexset.IndexSetConfig;
import org.graylog2.indexer.indexset.IndexSetMappingTemplate;
Expand Down Expand Up @@ -227,7 +228,7 @@ public void deleteIndexTemplate(IndexSet indexSet) {
}

public boolean create(String indexName, IndexSet indexSet) {
return create(indexName, indexSet, null, null );
return create(indexName, indexSet, null, null);
}

public boolean create(String indexName,
Expand All @@ -248,6 +249,10 @@ public boolean create(String indexName,

indicesAdapter.create(indexName, settings, mappings);
} catch (Exception e) {
if ((indexSettings != null || indexMapping != null) && e instanceof MapperParsingException) {
LOG.info("Couldn't create index {}. Error: {}. Fall back to default settings/mappings and retry.", indexName, e.getMessage(), e);
return create(indexName, indexSet, null, null);
}
LOG.warn("Couldn't create index {}. Error: {}", indexName, e.getMessage(), e);
auditEventSender.failure(AuditActor.system(nodeId), ES_INDEX_CREATE, ImmutableMap.of("indexName", indexName));
return false;
Expand All @@ -259,7 +264,7 @@ public boolean create(String indexName,
private Optional<IndexMappingTemplate> indexMapping(IndexSet indexSet) {
try {
return Optional.of(indexMappingFactory.createIndexMapping(indexSet.getConfig()));
}catch (IgnoreIndexTemplate e){
} catch (IgnoreIndexTemplate e) {
return Optional.empty();
}
}
Expand Down
Loading