congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
CorruptIndexException
Code IndexAdd Tabnine to your IDE (free)

How to use
CorruptIndexException
in
org.apache.lucene.index

Best Java code snippets using org.apache.lucene.index.CorruptIndexException (Showing top 20 results out of 324)

Refine searchRefine arrow

  • IndexInput
  • Directory
  • BytesRefBuilder
origin: org.apache.lucene/lucene-core

/** Retrieves the full index header from the provided {@link IndexInput}.
 *  This throws {@link CorruptIndexException} if this file does
 * not appear to be an index file. */
public static byte[] readIndexHeader(IndexInput in) throws IOException {
 in.seek(0);
 final int actualHeader = in.readInt();
 if (actualHeader != CODEC_MAGIC) {
  throw new CorruptIndexException("codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CODEC_MAGIC, in);
 }
 String codec = in.readString();
 in.readInt();
 in.seek(in.getFilePointer() + StringHelper.ID_LENGTH);
 int suffixLength = in.readByte() & 0xFF;
 byte[] bytes = new byte[headerLength(codec) + StringHelper.ID_LENGTH + 1 + suffixLength];
 in.seek(0);
 in.readBytes(bytes, 0, bytes.length);
 return bytes;
}
origin: org.elasticsearch/elasticsearch

private static void checksumFromLuceneFile(Directory directory, String file, Map<String, StoreFileMetaData> builder,
    Logger logger, Version version, boolean readFileAsHash) throws IOException {
  final String checksum;
  final BytesRefBuilder fileHash = new BytesRefBuilder();
  try (IndexInput in = directory.openInput(file, IOContext.READONCE)) {
    final long length;
    try {
      length = in.length();
      if (length < CodecUtil.footerLength()) {
        // truncated files trigger IAE if we seek negative... these files are really corrupted though
        throw new CorruptIndexException("Can't retrieve checksum from file: " + file + " file length must be >= " +
          CodecUtil.footerLength() + " but was: " + in.length(), in);
      }
      if (readFileAsHash) {
        // additional safety we checksum the entire file we read the hash for...
        final VerifyingIndexInput verifyingIndexInput = new VerifyingIndexInput(in);
        hashFile(fileHash, new InputStreamIndexInput(verifyingIndexInput, length), length);
        checksum = digestToString(verifyingIndexInput.verify());
      } else {
        checksum = digestToString(CodecUtil.retrieveChecksum(in));
      }
    } catch (Exception ex) {
      logger.debug(() -> new ParameterizedMessage("Can retrieve checksum from file [{}]", file), ex);
      throw ex;
    }
    builder.put(file, new StoreFileMetaData(file, length, checksum, version, fileHash.get()));
  }
}
origin: org.apache.lucene/lucene-codecs

@Override
public BytesRef lookupOrd(long ord) throws IOException {
 if (ord < 0 || ord >= field.numValues) {
  throw new IndexOutOfBoundsException("ord must be 0 .. " + (field.numValues-1) + "; got " + ord);
 }
 in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.length() + field.maxLength));
 SimpleTextUtil.readLine(in, scratch);
 assert StringHelper.startsWith(scratch.get(), LENGTH): "got " + scratch.get().utf8ToString() + " in=" + in;
 int len;
 try {
  len = decoder.parse(new String(scratch.bytes(), LENGTH.length, scratch.length() - LENGTH.length, StandardCharsets.UTF_8)).intValue();
 } catch (ParseException pe) {
  throw new CorruptIndexException("failed to parse int length", in, pe);
 }
 term.grow(len);
 term.setLength(len);
 in.readBytes(term.bytes(), 0, len);
 return term.get();
}

origin: org.apache.lucene/lucene-core

try (ChecksumIndexInput input = d.openChecksumInput(indexName, context)) {
 Throwable priorE = null;
 try {
 vectorsStream = d.openInput(vectorsStreamFN, context);
 final String codecNameDat = formatName + CODEC_SFX_DAT;
 int version2 = CodecUtil.checkIndexHeader(vectorsStream, codecNameDat, VERSION_START, VERSION_CURRENT, si.getId(), segmentSuffix);
 if (version != version2) {
  throw new CorruptIndexException("Version mismatch between stored fields index and data: " + version + " != " + version2, vectorsStream);
 assert CodecUtil.indexHeaderLength(codecNameDat, segmentSuffix) == vectorsStream.getFilePointer();
 long pos = vectorsStream.getFilePointer();
 vectorsStream.seek(maxPointer);
 numChunks = vectorsStream.readVLong();
 numDirtyChunks = vectorsStream.readVLong();
 if (numDirtyChunks > numChunks) {
  throw new CorruptIndexException("invalid chunk counts: dirty=" + numDirtyChunks + ", total=" + numChunks, vectorsStream);
origin: com.github.monnetproject/clesa

private void setIndexReader(Directory indexDir) {
  try {
    this.reader = IndexReader.open(indexDir);
    indexDir.close();			
  } catch (CorruptIndexException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }        
}
origin: org.apache.lucene/lucene-codecs

 @Override
 boolean advanceExact(int target) throws IOException {
  this.doc = target;
  in.seek(field.dataStartFilePointer + (9+field.pattern.length() + field.maxLength+2)*target);
  SimpleTextUtil.readLine(in, scratch);
  assert StringHelper.startsWith(scratch.get(), LENGTH);
  int len;
  try {
   len = decoder.parse(new String(scratch.bytes(), LENGTH.length, scratch.length() - LENGTH.length, StandardCharsets.UTF_8)).intValue();
  } catch (ParseException pe) {
   throw new CorruptIndexException("failed to parse int length", in, pe);
  }
  // skip past bytes
  byte bytes[] = new byte[len];
  in.readBytes(bytes, 0, len);
  SimpleTextUtil.readLine(in, scratch); // newline
  SimpleTextUtil.readLine(in, scratch); // 'T' or 'F'
  return scratch.byteAt(0) == (byte) 'T';
 }
};
origin: org.apache.lucene/lucene-codecs

@Override
public void checkIntegrity() throws IOException {
 BytesRefBuilder scratch = new BytesRefBuilder();
 IndexInput clone = dataIn.clone();
 clone.seek(0);
 // checksum is fixed-width encoded with 20 bytes, plus 1 byte for newline (the space is included in SimpleTextUtil.CHECKSUM):
 long footerStartPos = dataIn.length() - (SimpleTextUtil.CHECKSUM.length + 21);
 ChecksumIndexInput input = new BufferedChecksumIndexInput(clone);
 while (true) {
  SimpleTextUtil.readLine(input, scratch);
  if (input.getFilePointer() >= footerStartPos) {
   // Make sure we landed at precisely the right location:
   if (input.getFilePointer() != footerStartPos) {
    throw new CorruptIndexException("SimpleText failure: footer does not start at expected position current=" + input.getFilePointer() + " vs expected=" + footerStartPos, input);
   }
   SimpleTextUtil.checkFooter(input);
   break;
  }
 }
}
origin: org.apache.lucene/lucene-core

handle = directory.openInput(dataFileName, context);
try {
 CodecUtil.checkIndexHeader(handle, Lucene50CompoundFormat.DATA_CODEC, version, version, si.getId(), "");
 if (handle.length() != expectedLength) {
  throw new CorruptIndexException("length should be " + expectedLength + " bytes, but is " + handle.length() + " instead", handle);
origin: org.apache.lucene/lucene-core

 byte b = termsIn.readByte();
 if (b != 0) {
  throw new CorruptIndexException("Index header pretends the index has auto-prefix terms: " + b, termsIn);
final int numFields = termsIn.readVInt();
if (numFields < 0) {
 throw new CorruptIndexException("invalid numFields: " + numFields, termsIn);
 final int field = termsIn.readVInt();
 final long numTerms = termsIn.readVLong();
 if (numTerms <= 0) {
  throw new CorruptIndexException("Illegal numTerms for field number: " + field, termsIn);
  throw new CorruptIndexException("invalid field number: " + field, termsIn);
 final int longsSize = termsIn.readVInt();
 if (longsSize < 0) {
  throw new CorruptIndexException("invalid longsSize for field: " + fieldInfo.name + ", longsSize=" + longsSize, termsIn);
  throw new CorruptIndexException("invalid docCount: " + docCount + " maxDoc: " + state.segmentInfo.maxDoc(), termsIn);
  throw new CorruptIndexException("invalid sumDocFreq: " + sumDocFreq + " docCount: " + docCount, termsIn);
  throw new CorruptIndexException("invalid sumTotalTermFreq: " + sumTotalTermFreq + " sumDocFreq: " + sumDocFreq, termsIn);
                          indexStartFP, longsSize, indexIn, minTerm, maxTerm));
 if (previous != null) {
  throw new CorruptIndexException("duplicate field: " + fieldInfo.name, termsIn);
origin: google/sagetv

  tmpWriter.addIndexes(new Directory[] {index});
  tmp.createOutput(INDEX_WRITE_COMPLETED);
  tmpWriter.close();
  long start = Sage.time();
  tmp.close();
  start = Sage.time() - start;
  if(Sage.DBG) System.out.println("Snapshot-index-close-time: " + start);
 e.printStackTrace();
} catch (IOException e) {
origin: org.apache.lucene/lucene-core

if (in.length() < footerLength() + headerLength("")) {
 throw new CorruptIndexException("compound sub-files must have a valid codec header and footer: file is too small (" + in.length() + " bytes)", in);
int actualHeader = in.readInt();
if (actualHeader != CODEC_MAGIC) {
 throw new CorruptIndexException("compound sub-files must have a valid codec header and footer: codec header mismatch: actual header=" + actualHeader + " vs expected header=" + CodecUtil.CODEC_MAGIC, in);
origin: org.apache.lucene/lucene-core

/** Retrieves the full footer from the provided {@link IndexInput}.  This throws
 *  {@link CorruptIndexException} if this file does not have a valid footer. */
public static byte[] readFooter(IndexInput in) throws IOException {
 if (in.length() < footerLength()) {
  throw new CorruptIndexException("misplaced codec footer (file truncated?): length=" + in.length() + " but footerLength==" + footerLength(), in);
 }
 in.seek(in.length() - footerLength());
 validateFooter(in);
 in.seek(in.length() - footerLength());
 byte[] bytes = new byte[footerLength()];
 in.readBytes(bytes, 0, bytes.length);
 return bytes;
}

origin: org.apache.lucene/lucene-codecs

@Override
public boolean advanceExact(int target) throws IOException {
 this.doc = target;
 in.seek(field.dataStartFilePointer + field.numValues * (9 + field.pattern.length() + field.maxLength) + target * (1 + field.ordPattern.length()));
 SimpleTextUtil.readLine(in, scratch);
 try {
  ord = (int) ordDecoder.parse(scratch.get().utf8ToString()).longValue()-1;
 } catch (ParseException pe) {
  throw new CorruptIndexException("failed to parse ord", in, pe);
 }
 return ord >= 0;
}
origin: org.apache.lucene/lucene-core

rawDocs.seek(index.getStartPointer(0));
int docID = 0;
while (docID < maxDoc) {
 int base = rawDocs.readVInt();
 if (base != docID) {
  throw new CorruptIndexException("invalid state: base=" + base + ", docID=" + docID, rawDocs);
 int bufferedDocs = rawDocs.readVInt();
  throw new CorruptIndexException("invalid state: base=" + base + ", count=" + bufferedDocs + ", maxDoc=" + maxDoc, rawDocs);
if (rawDocs.getFilePointer() != matchingVectorsReader.getMaxPointer()) {
 throw new CorruptIndexException("invalid state: pos=" + rawDocs.getFilePointer() + ", max=" + matchingVectorsReader.getMaxPointer(), rawDocs);
origin: org.apache.lucene/lucene-core

private static void validateFooter(IndexInput in) throws IOException {
 long remaining = in.length() - in.getFilePointer();
 long expected = footerLength();
 if (remaining < expected) {
  throw new CorruptIndexException("misplaced codec footer (file truncated?): remaining=" + remaining + ", expected=" + expected + ", fp=" + in.getFilePointer(), in);
 } else if (remaining > expected) {
  throw new CorruptIndexException("misplaced codec footer (file extended?): remaining=" + remaining + ", expected=" + expected + ", fp=" + in.getFilePointer(), in);
 }
 
 final int magic = in.readInt();
 if (magic != FOOTER_MAGIC) {
  throw new CorruptIndexException("codec footer mismatch (file truncated?): actual footer=" + magic + " vs expected footer=" + FOOTER_MAGIC, in);
 }
 
 final int algorithmID = in.readInt();
 if (algorithmID != 0) {
  throw new CorruptIndexException("codec footer mismatch: unknown algorithmID: " + algorithmID, in);
 }
}

origin: org.apache.lucene/lucene-core

 vectorsStream.seek(startPointer);
final int docBase = vectorsStream.readVInt();
final int chunkDocs = vectorsStream.readVInt();
if (doc < docBase || doc >= docBase + chunkDocs || docBase + chunkDocs > numDocs) {
 throw new CorruptIndexException("docBase=" + docBase + ",chunkDocs=" + chunkDocs + ",doc=" + doc, vectorsStream);
origin: org.apache.lucene/lucene-codecs

final IndexInput in = data.clone();
final BytesRefBuilder scratch = new BytesRefBuilder();
final DecimalFormat decoder = new DecimalFormat(field.pattern, new DecimalFormatSymbols(Locale.ROOT));
    bd = (BigDecimal) decoder.parse(scratch.get().utf8ToString());
   } catch (ParseException pe) {
    throw new CorruptIndexException("failed to parse BigDecimal value", in, pe);
origin: org.apache.lucene/lucene-codecs

public static void checkFooter(ChecksumIndexInput input) throws IOException {
 BytesRefBuilder scratch = new BytesRefBuilder();
 String expectedChecksum = String.format(Locale.ROOT, "%020d", input.getChecksum());
 readLine(input, scratch);
 if (StringHelper.startsWith(scratch.get(), CHECKSUM) == false) {
  throw new CorruptIndexException("SimpleText failure: expected checksum line but got " + scratch.get().utf8ToString(), input);
 }
 String actualChecksum = new BytesRef(scratch.bytes(), CHECKSUM.length, scratch.length() - CHECKSUM.length).utf8ToString();
 if (!expectedChecksum.equals(actualChecksum)) {
  throw new CorruptIndexException("SimpleText checksum failure: " + actualChecksum + " != " + expectedChecksum, input);
 }
 if (input.length() != input.getFilePointer()) {
  throw new CorruptIndexException("Unexpected stuff at the end of file, please be careful with your text editor!", input);
 }
}
origin: org.apache.lucene/lucene-core

try (ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context)) {
 Throwable priorE = null;
 try {
this.data = state.directory.openInput(dataName, state.context);
boolean success = false;
try {
                       state.segmentSuffix);
 if (version != version2) {
  throw new CorruptIndexException("Format versions mismatch: meta=" + version + ", data=" + version2, data);
origin: org.apache.lucene/lucene-core

private void readFields(IndexInput meta, FieldInfos infos) throws IOException {
 for (int fieldNumber = meta.readInt(); fieldNumber != -1; fieldNumber = meta.readInt()) {
  FieldInfo info = infos.fieldInfo(fieldNumber);
  if (info == null) {
   throw new CorruptIndexException("Invalid field number: " + fieldNumber, meta);
  } else if (!info.hasNorms()) {
   throw new CorruptIndexException("Invalid field: " + info.name, meta);
  }
  NormsEntry entry = new NormsEntry();
  entry.docsWithFieldOffset = meta.readLong();
  entry.docsWithFieldLength = meta.readLong();
  entry.numDocsWithField = meta.readInt();
  entry.bytesPerNorm = meta.readByte();
  switch (entry.bytesPerNorm) {
   case 0: case 1: case 2: case 4: case 8:
    break;
   default:
    throw new CorruptIndexException("Invalid bytesPerValue: " + entry.bytesPerNorm + ", field: " + info.name, meta);
  }
  entry.normsOffset = meta.readLong();
  norms.put(info.number, entry);
 }
}
org.apache.lucene.indexCorruptIndexException

Javadoc

This exception is thrown when Lucene detects an inconsistency in the index.

Most used methods

  • <init>
    Create exception with message and root cause.
  • printStackTrace
  • getMessage
  • getOriginalMessage
    Returns the original exception message without the corrupted file description.
  • getResourceDescription
    Returns a description of the file that was corrupted
  • getLocalizedMessage
  • initCause

Popular in Java

  • Making http requests using okhttp
  • getSystemService (Context)
  • runOnUiThread (Activity)
  • onCreateOptionsMenu (Activity)
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now