Skip to content

Commit

Permalink
Empty dir error in datanode inplace migration (#20912)
Browse files Browse the repository at this point in the history
* Empty dir error in datanode inplace migration

* better place for empty data dir compatibility check

* added changelog

* compatibility warning for inplace migration in case of empty data dir

* display warning

* rephrased empty datadir warning

* only show green alert when there are no warnings

---------

Co-authored-by: Mohamed Ould Hocine <[email protected]>
Co-authored-by: Matthias Oesterheld <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent b88223a commit 60e1ca3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/pr-20912.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "fixed"
message = "Directory compatibility check for datanode inplace migration rejects empty dir"

issues = []
pulls = ["20912"]
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@

public record CompatibilityResult(String hostname, String opensearchVersion,
IndexerDirectoryInformation info,
java.util.List<String> compatibilityErrors) {
java.util.List<String> compatibilityErrors,
java.util.List<String> compatibilityWarnings) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.graylog.datanode.filesystem.index.dto.NodeInformation;
import org.graylog.shaded.opensearch2.org.opensearch.Version;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -59,13 +60,21 @@ public CompatibilityResult status() {
directoryReadableValidator.validate(dataTargetDir.toUri().toString(), dataTargetDir);
final IndexerDirectoryInformation info = indicesDirectoryParser.parse(dataTargetDir);
final Version currentVersion = Version.fromString(opensearchVersion);

final List<String> compatibilityWarnings = new ArrayList<>();

if (info.nodes().isEmpty() || info.nodes().stream().allMatch(n -> n.indices().isEmpty())) {
compatibilityWarnings.add("Your configured opensearch_data_location directory " + dataTargetDir.toAbsolutePath() + " doesn't contain any indices! Do you want to continue without migrating existing data?");
}

final List<String> compatibilityErrors = info.nodes().stream()
.filter(node -> !isNodeCompatible(node, currentVersion))
.map(node -> String.format(Locale.ROOT, "Current version %s of Opensearch is not compatible with index version %s", currentVersion, node.nodeVersion()))
.toList();
return new CompatibilityResult(hostname, opensearchVersion, info, compatibilityErrors);

return new CompatibilityResult(hostname, opensearchVersion, info, compatibilityErrors, compatibilityWarnings);
} catch (Exception e) {
return new CompatibilityResult(hostname, opensearchVersion, new IndexerDirectoryInformation(dataTargetDir, Collections.emptyList()), Collections.singletonList(e.getMessage()));
return new CompatibilityResult(hostname, opensearchVersion, new IndexerDirectoryInformation(dataTargetDir, Collections.emptyList()), Collections.singletonList(e.getMessage()), Collections.emptyList());
}
}

Expand Down
2 changes: 2 additions & 0 deletions graylog2-web-interface/src/components/datanode/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export type NodeInfo = {
node_version: string,
}
export type CompatibilityResponseType = {
hostname: string,
opensearch_version: string,
info: {
nodes: Array<NodeInfo>,
opensearch_data_location: string,
},
compatibility_errors: Array<string>,
compatibility_warnings: Array<string>,
};
export type DataNode = {
hostname: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ describe('CompatibilityCheckStep', () => {
asMock(useCompatibilityCheck).mockReturnValue({
data: {
datanode1: {
hostname: 'hostname1',
opensearch_version: '2.10.0',
info: null,
compatibility_errors: ['org.graylog.shaded.opensearch2.org.apache.lucene.index.IndexFormatTooOldException: Format version is not supported (resource BufferedChecksumIndexInput(ByteBufferIndexInput(path="/index/segments_3"))): This index was initially created with Lucene 7.x while the current version is 9.7.0 and Lucene only supports reading the current and previous major versions. This version of Lucene only supports indexes created with release 8.0 and later by default.'],
compatibility_warnings: ['warnings'],
},
},
refetch: () => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,39 @@ const CompatibilityCheckStep = ({ currentStep, onTriggerStep, hideActions }: Mig
}

const errors = Object.values(data || {}).flatMap((value) => (value?.compatibility_errors || []));
const warnings = Object.values(data || {}).flatMap((value) => (value?.compatibility_warnings || []));
const isCompatible = errors.length === 0;

return (
<>
<h3>Directory compatibility check</h3>
<CompatibilityAlert bsStyle={(!isError && isCompatible) ? 'success' : 'danger'}>
{isCompatible && <h4>Your existing OpenSearch data can be migrated to Data Node.</h4>}
{!isError && !isCompatible && (
<>
<h4>Your existing OpenSearch data cannot be migrated to Data Node.</h4>
<br />
Error: {errors} {errors.map((error) => <dd key={error}>{error}</dd>)}
</>
)}
{isError && (
<>
<h4>There was an error checking the compatibility</h4>
<p>{requestError.message}</p>
</>
)}
</CompatibilityAlert>
{isCompatible && !warnings.length && (
<CompatibilityAlert bsStyle="success">
<h4>Your existing OpenSearch data can be migrated to Data Node.</h4>
</CompatibilityAlert>
)}
{(!isCompatible || isError) && (
<CompatibilityAlert bsStyle="danger">
{!isError && !isCompatible && (
<>
<h4>Your existing OpenSearch data cannot be migrated to Data Node.</h4>
<br />
{errors.map((error) => <dd key={error}>{error}</dd>)}
</>
)}
{isError && (
<>
<h4>There was an error checking the compatibility</h4>
<p>{requestError.message}</p>
</>
)}
</CompatibilityAlert>
)}
{warnings.length > 0 && (
<CompatibilityAlert bsStyle="warning">
{warnings.map((warning) => <dd key={warning}>{warning}</dd>)}
</CompatibilityAlert>
)}
<br />
{!isCompatible && (<p>Your OpenSearch cluster cannot be migrated to this Data Node version because it&apos;s not compatible.</p>)}
{isCompatible && data && Object.keys(data).map((hostname) => (
Expand Down

0 comments on commit 60e1ca3

Please sign in to comment.