Java Code Examples for org.apache.lucene.index.CheckIndex#Status
The following examples show how to use
org.apache.lucene.index.CheckIndex#Status .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckIndexDialogFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
private String createResultsMessage(CheckIndex.Status status) { String msg; if (status == null) { msg = "?"; } else if (status.clean) { msg = "OK"; } else if (status.toolOutOfDate) { msg = "ERROR: Can't check - tool out-of-date"; } else { StringBuilder sb = new StringBuilder("BAD:"); if (status.missingSegments) { sb.append(" Missing segments."); } if (status.numBadSegments > 0) { sb.append(" numBadSegments="); sb.append(status.numBadSegments); } if (status.totLoseDocCount > 0) { sb.append(" totLoseDocCount="); sb.append(status.totLoseDocCount); } msg = sb.toString(); } return msg; }
Example 2
Source File: TestUtil.java From lucene-solr with Apache License 2.0 | 6 votes |
/** If failFast is true, then throw the first exception when index corruption is hit, instead of moving on to other fields/segments to * look for any other corruption. */ public static CheckIndex.Status checkIndex(Directory dir, boolean doSlowChecks, boolean failFast, ByteArrayOutputStream output) throws IOException { if (output == null) { output = new ByteArrayOutputStream(1024); } // TODO: actually use the dir's locking, unless test uses a special method? // some tests e.g. exception tests become much more complicated if they have to close the writer try (CheckIndex checker = new CheckIndex(dir, NoLockFactory.INSTANCE.obtainLock(dir, "bogus"))) { checker.setDoSlowChecks(doSlowChecks); checker.setFailFast(failFast); checker.setInfoStream(new PrintStream(output, false, IOUtils.UTF_8), false); CheckIndex.Status indexStatus = checker.checkIndex(null); if (indexStatus == null || indexStatus.clean == false) { System.out.println("CheckIndex failed"); System.out.println(output.toString(IOUtils.UTF_8)); throw new RuntimeException("CheckIndex failed"); } else { if (LuceneTestCase.INFOSTREAM) { System.out.println(output.toString(IOUtils.UTF_8)); } return indexStatus; } } }
Example 3
Source File: MultiDataPathUpgrader.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * 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"); } } }
Example 4
Source File: IndexToolsImpl.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void repairIndex(CheckIndex.Status st, PrintStream ps) { try { if (dir != null) { IndexUtils.tryRepairIndex(dir, st, ps); } else { throw new IllegalStateException("Directory is not set."); } } catch (Exception e) { throw new LukeException("Failed to repair index.", e); } }
Example 5
Source File: Store.java From crate with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example 6
Source File: IndexShard.java From Elasticsearch with Apache License 2.0 | 4 votes |
private void doCheckIndex() throws IOException { long timeNS = System.nanoTime(); if (!Lucene.indexExists(store.directory())) { return; } BytesStreamOutput os = new BytesStreamOutput(); PrintStream out = new PrintStream(os, false, Charsets.UTF_8.name()); if ("checksum".equalsIgnoreCase(checkIndexOnStartup)) { // physical verification only: verify all checksums for the latest commit IOException corrupt = null; MetadataSnapshot metadata = store.getMetadata(); for (Map.Entry<String, StoreFileMetaData> entry : metadata.asMap().entrySet()) { try { Store.checkIntegrity(entry.getValue(), store.directory()); out.println("checksum passed: " + entry.getKey()); } catch (IOException exc) { out.println("checksum failed: " + entry.getKey()); exc.printStackTrace(out); corrupt = exc; } } out.flush(); if (corrupt != null) { logger.warn("check index [failure]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8)); throw corrupt; } } else { // full checkindex try (CheckIndex checkIndex = new CheckIndex(store.directory())) { checkIndex.setInfoStream(out); CheckIndex.Status status = checkIndex.checkIndex(); out.flush(); if (!status.clean) { if (state == IndexShardState.CLOSED) { // ignore if closed.... return; } logger.warn("check index [failure]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8)); if ("fix".equalsIgnoreCase(checkIndexOnStartup)) { if (logger.isDebugEnabled()) { logger.debug("fixing index, writing new segments file ..."); } checkIndex.exorciseIndex(status); if (logger.isDebugEnabled()) { logger.debug("index fixed, wrote new segments file \"{}\"", status.segmentsFileName); } } else { // only throw a failure if we are not going to fix the index throw new IllegalStateException("index check failure but can't fix it"); } } } } if (logger.isDebugEnabled()) { logger.debug("check index [success]\n{}", new String(os.bytes().toBytes(), Charsets.UTF_8)); } recoveryState.getVerifyIndex().checkIndexTime(Math.max(0, TimeValue.nsecToMSec(System.nanoTime() - timeNS))); }
Example 7
Source File: TestUtil.java From lucene-solr with Apache License 2.0 | 4 votes |
/** This runs the CheckIndex tool on the index in. If any * issues are hit, a RuntimeException is thrown; else, * true is returned. */ public static CheckIndex.Status checkIndex(Directory dir) throws IOException { return checkIndex(dir, true); }
Example 8
Source File: TestUtil.java From lucene-solr with Apache License 2.0 | 4 votes |
public static CheckIndex.Status checkIndex(Directory dir, boolean doSlowChecks) throws IOException { return checkIndex(dir, doSlowChecks, false, null); }
Example 9
Source File: IndexShard.java From crate with Apache License 2.0 | 4 votes |
private void doCheckIndex() throws IOException { final long timeNS = System.nanoTime(); if (!Lucene.indexExists(store.directory())) { return; } BytesStreamOutput os = new BytesStreamOutput(); PrintStream out = new PrintStream(os, false, StandardCharsets.UTF_8.name()); if ("checksum".equals(checkIndexOnStartup)) { // physical verification only: verify all checksums for the latest commit IOException corrupt = null; MetadataSnapshot metadata = snapshotStoreMetadata(); for (Map.Entry<String, StoreFileMetaData> entry : metadata.asMap().entrySet()) { try { Store.checkIntegrity(entry.getValue(), store.directory()); out.println("checksum passed: " + entry.getKey()); } catch (IOException exc) { out.println("checksum failed: " + entry.getKey()); exc.printStackTrace(out); corrupt = exc; } } out.flush(); if (corrupt != null) { logger.warn("check index [failure]\n{}", os.bytes().utf8ToString()); throw corrupt; } } else { // full checkindex final CheckIndex.Status status = store.checkIndex(out); out.flush(); if (!status.clean) { if (state == IndexShardState.CLOSED) { // ignore if closed.... return; } logger.warn("check index [failure]\n{}", os.bytes().utf8ToString()); throw new IOException("index check failure"); } } if (logger.isDebugEnabled()) { logger.debug("check index [success]\n{}", os.bytes().utf8ToString()); } recoveryState.getVerifyIndex().checkIndexTime(Math.max(0, TimeValue.nsecToMSec(System.nanoTime() - timeNS))); }
Example 10
Source File: IndexTools.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Check the current index status. * * @param ps information stream * @return index status * @throws LukeException - if an internal error occurs when accessing index */ CheckIndex.Status checkIndex(PrintStream ps);
Example 11
Source File: IndexTools.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Try to repair the corrupted index using previously returned index status. * * <p>This method must be called with the return value from {@link IndexTools#checkIndex(PrintStream)}.</p> * * @param st - index status * @param ps - information stream * @throws LukeException - if an internal error occurs when accessing index */ void repairIndex(CheckIndex.Status st, PrintStream ps);