/** Returns a {@link Status} instance detailing * the state of the index. * * <p>As this method checks every byte in the index, on a large * index it can take quite a long time to run. * * <p><b>WARNING</b>: make sure * you only call this when the index is not opened by any * writer. */ public Status checkIndex() throws IOException { return checkIndex(null); }
public void checkClean(){ try { dir = FSDirectory.open(indexDir.toPath()); CheckIndex checkIndex = new CheckIndex(dir); CheckIndex.Status status = checkIndex.checkIndex(); assert (status.clean) : "index is not clean"; dir.close(); } catch (IOException e) { throw new RuntimeException(e); } }
setInfoStream(opts.out, opts.verbose); Status result = checkIndex(opts.onlySegments); if (result.missingSegments) { return 1;
CheckIndex.Status status = checker.checkIndex(); if ( !status.clean )
/** * Checks and returns the status of the existing index in this store. * * @param out where infoStream messages should go. See {@link CheckIndex#setInfoStream(PrintStream)} */ public CheckIndex.Status checkIndex(PrintStream out) throws IOException { metadataLock.writeLock().lock(); try (CheckIndex checkIndex = new CheckIndex(directory)) { checkIndex.setInfoStream(out); return checkIndex.checkIndex(); } finally { metadataLock.writeLock().unlock(); } }
/** Returns a {@link Status} instance detailing * the state of the index. * * <p>As this method checks every byte in the index, on a large * index it can take quite a long time to run. * * <p><b>WARNING</b>: make sure * you only call this when the index is not opened by any * writer. */ public Status checkIndex() throws IOException { return checkIndex(null); }
/** Returns a {@link Status} instance detailing * the state of the index. * * <p>As this method checks every byte in the index, on a large * index it can take quite a long time to run. * * <p><b>WARNING</b>: make sure * you only call this when the index is not opened by any * writer. */ public Status checkIndex() throws IOException { return checkIndex(null); }
/** Returns a {@link Status} instance detailing * the state of the index. * * <p>As this method checks every byte in the index, on a large * index it can take quite a long time to run. * * <p><b>WARNING</b>: make sure * you only call this when the index is not opened by any * writer. */ public Status checkIndex() throws IOException { return checkIndex(null); }
/** Returns a {@link Status} instance detailing * the state of the index. * * <p>As this method checks every byte in the index, on a large * index it can take quite a long time to run. * * <p><b>WARNING</b>: make sure * you only call this when the index is not opened by any * writer. */ public Status checkIndex() throws IOException { return checkIndex(null); }
/** Returns a {@link Status} instance detailing * the state of the index. * * <p>As this method checks every byte in the index, on a large * index it can take quite a long time to run. * * <p><b>WARNING</b>: make sure * you only call this when the index is not opened by any * writer. */ public Status checkIndex() throws IOException { return checkIndex(null); }
public Tuple<RemoveCorruptedShardDataCommand.CleanStatus, String> getCleanStatus(ShardPath shardPath, Directory indexDirectory, Lock writeLock, PrintStream printStream, boolean verbose) throws IOException { if (RemoveCorruptedShardDataCommand.isCorruptMarkerFileIsPresent(indexDirectory) == false) { return Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CLEAN, null); } final CheckIndex.Status status; try (CheckIndex checker = new CheckIndex(indexDirectory, writeLock)) { checker.setChecksumsOnly(true); checker.setInfoStream(printStream, verbose); status = checker.checkIndex(null); if (status.missingSegments) { return Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.UNRECOVERABLE, "Index is unrecoverable - there are missing segments"); } return status.clean ? Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CLEAN_WITH_CORRUPTED_MARKER, null) : Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CORRUPTED, "Corrupted Lucene index segments found - " + status.totLoseDocCount + " documents will be lost."); } }
public void execute(Terminal terminal, ShardPath shardPath, Directory indexDirectory, Lock writeLock, PrintStream printStream, boolean verbose) throws IOException { checkCorruptMarkerFileIsPresent(indexDirectory); final CheckIndex.Status status; try (CheckIndex checker = new CheckIndex(indexDirectory, writeLock)) { checker.setChecksumsOnly(true); checker.setInfoStream(printStream, verbose); status = checker.checkIndex(null); if (status.missingSegments == false) { if (status.clean == false) { terminal.println("Writing..."); checker.exorciseIndex(status); terminal.println("OK"); terminal.println("Wrote new segments file \"" + status.segmentsFileName + "\""); } } else { throw new ElasticsearchException("Index is unrecoverable - there are missing segments"); } } }
/** * Checks and returns the status of the existing index in this store. * * @param out where infoStream messages should go. See {@link CheckIndex#setInfoStream(PrintStream)} */ public CheckIndex.Status checkIndex(PrintStream out) throws IOException { metadataLock.writeLock().lock(); try (CheckIndex checkIndex = new CheckIndex(directory)) { checkIndex.setInfoStream(out); return checkIndex.checkIndex(); } finally { metadataLock.writeLock().unlock(); } }
/** * Checks and returns the status of the existing index in this store. * * @param out where infoStream messages should go. See {@link CheckIndex#setInfoStream(PrintStream)} */ public CheckIndex.Status checkIndex(PrintStream out) throws IOException { metadataLock.writeLock().lock(); try (CheckIndex checkIndex = new CheckIndex(directory)) { checkIndex.setInfoStream(out); return checkIndex.checkIndex(); } finally { metadataLock.writeLock().unlock(); } }
/** Returns true if index is clean, else false. * @deprecated Please instantiate a CheckIndex and then use {@link #checkIndex(List)} instead */ public static boolean check(Directory dir, boolean doFix, List onlySegments) throws IOException { CheckIndex checker = new CheckIndex(dir); Status status = checker.checkIndex(onlySegments); if (doFix && !status.clean) checker.fixIndex(status); return status.clean; }
/** Returns true if index is clean, else false. * @deprecated Please instantiate a CheckIndex and then use {@link #checkIndex(List)} instead */ public static boolean check(Directory dir, boolean doFix, List onlySegments) throws IOException { CheckIndex checker = new CheckIndex(dir); Status status = checker.checkIndex(onlySegments); if (doFix && !status.clean) checker.fixIndex(status); return status.clean; }
/** * Runs check-index on the target shard and throws an exception if it failed */ public void checkIndex(ShardPath targetPath) throws IOException { BytesStreamOutput os = new BytesStreamOutput(); PrintStream out = new PrintStream(os, false, Charsets.UTF_8.name()); try (Directory directory = new SimpleFSDirectory(targetPath.resolveIndex()); final CheckIndex checkIndex = new CheckIndex(directory)) { checkIndex.setInfoStream(out); CheckIndex.Status status = checkIndex.checkIndex(); out.flush(); if (!status.clean) { logger.warn("check index [failure]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8)); throw new IllegalStateException("index check failure"); } } }
CheckIndex.Status check() throws Exception { return rwl.writeEx(() -> { closeIndex(); try (final Directory directory = IndexInstanceBuilder.getDirectory(settings, fileSet.dataDirectory)) { try (final CheckIndex checkIndex = new CheckIndex(directory)) { return checkIndex.checkIndex(); } } finally { ensureOpen(); } }); }
public Tuple<RemoveCorruptedShardDataCommand.CleanStatus, String> getCleanStatus(ShardPath shardPath, Directory indexDirectory, Lock writeLock, PrintStream printStream, boolean verbose) throws IOException { if (RemoveCorruptedShardDataCommand.isCorruptMarkerFileIsPresent(indexDirectory) == false) { return Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CLEAN, null); } final CheckIndex.Status status; try (CheckIndex checker = new CheckIndex(indexDirectory, writeLock)) { checker.setChecksumsOnly(true); checker.setInfoStream(printStream, verbose); status = checker.checkIndex(null); if (status.missingSegments) { return Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.UNRECOVERABLE, "Index is unrecoverable - there are missing segments"); } return status.clean ? Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CLEAN_WITH_CORRUPTED_MARKER, null) : Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CORRUPTED, "Corrupted Lucene index segments found - " + status.totLoseDocCount + " documents will be lost."); } }
public Tuple<RemoveCorruptedShardDataCommand.CleanStatus, String> getCleanStatus(ShardPath shardPath, Directory indexDirectory, Lock writeLock, PrintStream printStream, boolean verbose) throws IOException { if (RemoveCorruptedShardDataCommand.isCorruptMarkerFileIsPresent(indexDirectory) == false) { return Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CLEAN, null); } final CheckIndex.Status status; try (CheckIndex checker = new CheckIndex(indexDirectory, writeLock)) { checker.setChecksumsOnly(true); checker.setInfoStream(printStream, verbose); status = checker.checkIndex(null); if (status.missingSegments) { return Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.UNRECOVERABLE, "Index is unrecoverable - there are missing segments"); } return status.clean ? Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CLEAN_WITH_CORRUPTED_MARKER, null) : Tuple.tuple(RemoveCorruptedShardDataCommand.CleanStatus.CORRUPTED, "Corrupted Lucene index segments found - " + status.totLoseDocCount + " documents will be lost."); } }