• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IndexFormatTooNewException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.lucene.index.IndexFormatTooNewException的典型用法代码示例。如果您正苦于以下问题:Java IndexFormatTooNewException类的具体用法?Java IndexFormatTooNewException怎么用?Java IndexFormatTooNewException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IndexFormatTooNewException类属于org.apache.lucene.index包,在下文中一共展示了IndexFormatTooNewException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readBlob

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/**
 * Reads blob with specified name without resolving the blobName using using {@link #blobName} method.
 *
 * @param blobContainer blob container
 * @param blobName blob name
 */
public T readBlob(BlobContainer blobContainer, String blobName) throws IOException {
    try (InputStream inputStream = blobContainer.readBlob(blobName)) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Streams.copy(inputStream, out);
        final byte[] bytes = out.toByteArray();
        final String resourceDesc = "ChecksumBlobStoreFormat.readBlob(blob=\"" + blobName + "\")";
        try (ByteArrayIndexInput indexInput = new ByteArrayIndexInput(resourceDesc, bytes)) {
            CodecUtil.checksumEntireFile(indexInput);
            CodecUtil.checkHeader(indexInput, codec, VERSION, VERSION);
            long filePointer = indexInput.getFilePointer();
            long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
            BytesReference bytesReference = new BytesArray(bytes, (int) filePointer, (int) contentSize);
            return read(bytesReference);
        } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            // we trick this into a dedicated exception with the original stacktrace
            throw new CorruptStateException(ex);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:ChecksumBlobStoreFormat.java


示例2: checkHeaderNoMagic

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/** Like {@link
 *  #checkHeader(DataInput,String,int,int)} except this
 *  version assumes the first int has already been read
 *  and validated from the input. */
public static int checkHeaderNoMagic(DataInput in, String codec, int minVersion, int maxVersion) throws IOException {
  final String actualCodec = in.readString();
  if (!actualCodec.equals(codec)) {
    throw new CorruptIndexException("codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec + " (resource: " + in + ")");
  }

  final int actualVersion = in.readInt();
  if (actualVersion < minVersion) {
    throw new IndexFormatTooOldException(in, actualVersion, minVersion, maxVersion);
  }
  if (actualVersion > maxVersion) {
    throw new IndexFormatTooNewException(in, actualVersion, minVersion, maxVersion);
  }

  return actualVersion;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:CodecUtil.java


示例3: readBlob

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/**
 * Reads blob with specified name without resolving the blobName using using {@link #blobName} method.
 *
 * @param blobContainer blob container
 * @param blobName blob name
 */
public T readBlob(BlobContainer blobContainer, String blobName) throws IOException {
    try (InputStream inputStream = blobContainer.readBlob(blobName)) {
        byte[] bytes = ByteStreams.toByteArray(inputStream);
        final String resourceDesc = "ChecksumBlobStoreFormat.readBlob(blob=\"" + blobName + "\")";
        try (ByteArrayIndexInput indexInput = new ByteArrayIndexInput(resourceDesc, bytes)) {
            CodecUtil.checksumEntireFile(indexInput);
            CodecUtil.checkHeader(indexInput, codec, VERSION, VERSION);
            long filePointer = indexInput.getFilePointer();
            long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
            BytesReference bytesReference = new BytesArray(bytes, (int) filePointer, (int) contentSize);
            return read(bytesReference);
        } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            // we trick this into a dedicated exception with the original stacktrace
            throw new CorruptStateException(ex);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:ChecksumBlobStoreFormat.java


示例4: read

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/**
 * Reads the state from a given file and compares the expected version against the actual version of
 * the state.
 */
public final T read(Path file) throws IOException {
    try (Directory dir = newDirectory(file.getParent())) {
        try (final IndexInput indexInput = dir.openInput(file.getFileName().toString(), IOContext.DEFAULT)) {
             // We checksum the entire file before we even go and parse it. If it's corrupted we barf right here.
            CodecUtil.checksumEntireFile(indexInput);
            CodecUtil.checkHeader(indexInput, STATE_FILE_CODEC, STATE_FILE_VERSION, STATE_FILE_VERSION);
            final XContentType xContentType = XContentType.values()[indexInput.readInt()];
            indexInput.readLong(); // version currently unused
            long filePointer = indexInput.getFilePointer();
            long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
            try (IndexInput slice = indexInput.slice("state_xcontent", filePointer, contentSize)) {
                try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(new InputStreamIndexInput(slice, contentSize))) {
                    return fromXContent(parser);
                }
            }
        } catch(CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            // we trick this into a dedicated exception with the original stacktrace
            throw new CorruptStateException(ex);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:MetaDataStateFormat.java


示例5: failStoreIfCorrupted

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
private void failStoreIfCorrupted(Exception e) {
    if (e instanceof CorruptIndexException || e instanceof IndexFormatTooOldException || e instanceof IndexFormatTooNewException) {
        try {
            store.markStoreCorrupted((IOException) e);
        } catch (IOException inner) {
            inner.addSuppressed(e);
            logger.warn("store cannot be marked as corrupted", inner);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:BlobStoreRepository.java


示例6: restoreFile

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/**
 * Restores a file
 * This is asynchronous method. Upon completion of the operation latch is getting counted down and any failures are
 * added to the {@code failures} list
 *
 * @param fileInfo file to be restored
 */
private void restoreFile(final BlobStoreIndexShardSnapshot.FileInfo fileInfo, final Store store) throws IOException {
    boolean success = false;

    try (InputStream partSliceStream = new PartSliceStream(blobContainer, fileInfo)) {
        final InputStream stream;
        if (restoreRateLimiter == null) {
            stream = partSliceStream;
        } else {
            stream = new RateLimitingInputStream(partSliceStream, restoreRateLimiter, restoreRateLimitingTimeInNanos::inc);
        }

        try (IndexOutput indexOutput = store.createVerifyingOutput(fileInfo.physicalName(), fileInfo.metadata(), IOContext.DEFAULT)) {
            final byte[] buffer = new byte[BUFFER_SIZE];
            int length;
            while ((length = stream.read(buffer)) > 0) {
                indexOutput.writeBytes(buffer, 0, length);
                recoveryState.getIndex().addRecoveredBytesToFile(fileInfo.name(), length);
            }
            Store.verify(indexOutput);
            indexOutput.close();
            store.directory().sync(Collections.singleton(fileInfo.physicalName()));
            success = true;
        } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            try {
                store.markStoreCorrupted(ex);
            } catch (IOException e) {
                logger.warn("store cannot be marked as corrupted", e);
            }
            throw ex;
        } finally {
            if (success == false) {
                store.deleteQuiet(fileInfo.physicalName());
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:44,代码来源:BlobStoreRepository.java


示例7: read

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/**
 * Reads the state from a given file and compares the expected version against the actual version of
 * the state.
 */
public final T read(NamedXContentRegistry namedXContentRegistry, Path file) throws IOException {
    try (Directory dir = newDirectory(file.getParent())) {
        try (IndexInput indexInput = dir.openInput(file.getFileName().toString(), IOContext.DEFAULT)) {
             // We checksum the entire file before we even go and parse it. If it's corrupted we barf right here.
            CodecUtil.checksumEntireFile(indexInput);
            final int fileVersion = CodecUtil.checkHeader(indexInput, STATE_FILE_CODEC, MIN_COMPATIBLE_STATE_FILE_VERSION,
                STATE_FILE_VERSION);
            final XContentType xContentType = XContentType.values()[indexInput.readInt()];
            if (fileVersion == STATE_FILE_VERSION_ES_2X_AND_BELOW) {
                // format version 0, wrote a version that always came from the content state file and was never used
                indexInput.readLong(); // version currently unused
            }
            long filePointer = indexInput.getFilePointer();
            long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
            try (IndexInput slice = indexInput.slice("state_xcontent", filePointer, contentSize)) {
                try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(namedXContentRegistry,
                        new InputStreamIndexInput(slice, contentSize))) {
                    return fromXContent(parser);
                }
            }
        } catch(CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            // we trick this into a dedicated exception with the original stacktrace
            throw new CorruptStateException(ex);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:MetaDataStateFormat.java


示例8: testVerifyingIndexOutputOnEmptyFile

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
public void testVerifyingIndexOutputOnEmptyFile() throws IOException {
    Directory dir = newDirectory();
    IndexOutput verifyingOutput = new Store.LuceneVerifyingIndexOutput(new StoreFileMetaData("foo.bar", 0, Store.digestToString(0)),
        dir.createOutput("foo1.bar", IOContext.DEFAULT));
    try {
        Store.verify(verifyingOutput);
        fail("should be a corrupted index");
    } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
        // ok
    }
    IOUtils.close(verifyingOutput, dir);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:StoreTests.java


示例9: testVerifyingIndexOutputWithBogusInput

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
public void testVerifyingIndexOutputWithBogusInput() throws IOException {
    Directory dir = newDirectory();
    int length = scaledRandomIntBetween(10, 1024);
    IndexOutput verifyingOutput = new Store.LuceneVerifyingIndexOutput(new StoreFileMetaData("foo1.bar", length, ""), dir.createOutput("foo1.bar", IOContext.DEFAULT));
    try {
        while (length > 0) {
            verifyingOutput.writeByte((byte) random().nextInt());
            length--;
        }
        fail("should be a corrupted index");
    } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
        // ok
    }
    IOUtils.close(verifyingOutput, dir);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:StoreTests.java


示例10: testVerifyingIndexInput

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
public void testVerifyingIndexInput() throws IOException {
    Directory dir = newDirectory();
    IndexOutput output = dir.createOutput("foo.bar", IOContext.DEFAULT);
    int iters = scaledRandomIntBetween(10, 100);
    for (int i = 0; i < iters; i++) {
        BytesRef bytesRef = new BytesRef(TestUtil.randomRealisticUnicodeString(random(), 10, 1024));
        output.writeBytes(bytesRef.bytes, bytesRef.offset, bytesRef.length);
    }
    CodecUtil.writeFooter(output);
    output.close();

    // Check file
    IndexInput indexInput = dir.openInput("foo.bar", IOContext.DEFAULT);
    long checksum = CodecUtil.retrieveChecksum(indexInput);
    indexInput.seek(0);
    IndexInput verifyingIndexInput = new Store.VerifyingIndexInput(dir.openInput("foo.bar", IOContext.DEFAULT));
    readIndexInputFullyWithRandomSeeks(verifyingIndexInput);
    Store.verify(verifyingIndexInput);
    assertThat(checksum, equalTo(((ChecksumIndexInput) verifyingIndexInput).getChecksum()));
    IOUtils.close(indexInput, verifyingIndexInput);

    // Corrupt file and check again
    corruptFile(dir, "foo.bar", "foo1.bar");
    verifyingIndexInput = new Store.VerifyingIndexInput(dir.openInput("foo1.bar", IOContext.DEFAULT));
    readIndexInputFullyWithRandomSeeks(verifyingIndexInput);
    try {
        Store.verify(verifyingIndexInput);
        fail("should be a corrupted index");
    } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
        // ok
    }
    IOUtils.close(verifyingIndexInput);
    IOUtils.close(dir);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:StoreTests.java


示例11: checkValidFormat

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
private int checkValidFormat(IndexInput in) throws CorruptIndexException, IOException
{
  int format = in.readInt();
  if (format < FORMAT_MINIMUM)
    throw new IndexFormatTooOldException(in, format, FORMAT_MINIMUM, FORMAT_CURRENT);
  if (format > FORMAT_CURRENT)
    throw new IndexFormatTooNewException(in, format, FORMAT_MINIMUM, FORMAT_CURRENT);
  return format;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:Lucene3xTermVectorsReader.java


示例12: checkCodeVersion

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/** Verifies that the code version which wrote the segment is supported. */
public static void checkCodeVersion(Directory dir, String segment) throws IOException {
  final String indexStreamFN = IndexFileNames.segmentFileName(segment, "", FIELDS_INDEX_EXTENSION);
  IndexInput idxStream = dir.openInput(indexStreamFN, IOContext.DEFAULT);
  
  try {
    int format = idxStream.readInt();
    if (format < FORMAT_MINIMUM)
      throw new IndexFormatTooOldException(idxStream, format, FORMAT_MINIMUM, FORMAT_CURRENT);
    if (format > FORMAT_CURRENT)
      throw new IndexFormatTooNewException(idxStream, format, FORMAT_MINIMUM, FORMAT_CURRENT);
  } finally {
    idxStream.close();
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:Lucene3xStoredFieldsReader.java


示例13: failStoreIfCorrupted

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
private void failStoreIfCorrupted(Throwable t) {
    if (t instanceof CorruptIndexException || t instanceof IndexFormatTooOldException || t instanceof IndexFormatTooNewException) {
        try {
            store.markStoreCorrupted((IOException) t);
        } catch (IOException e) {
            logger.warn("store cannot be marked as corrupted", e);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:BlobStoreIndexShardRepository.java


示例14: unwrapCorruption

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
public static IOException unwrapCorruption(Throwable t) {
    return (IOException) unwrap(t, CorruptIndexException.class,
                                   IndexFormatTooOldException.class,
                                   IndexFormatTooNewException.class);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:ExceptionsHelper.java


示例15: testWriteThrowable

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
public void testWriteThrowable() throws IOException {
    final QueryShardException queryShardException = new QueryShardException(new Index("foo", "_na_"), "foobar", null);
    final UnknownException unknownException = new UnknownException("this exception is unknown", queryShardException);

    final Exception[] causes = new Exception[]{
            new IllegalStateException("foobar"),
            new IllegalArgumentException("alalaal"),
            new NullPointerException("boom"),
            new EOFException("dadada"),
            new ElasticsearchSecurityException("nono!"),
            new NumberFormatException("not a number"),
            new CorruptIndexException("baaaam booom", "this is my resource"),
            new IndexFormatTooNewException("tooo new", 1, 2, 3),
            new IndexFormatTooOldException("tooo new", 1, 2, 3),
            new IndexFormatTooOldException("tooo new", "very old version"),
            new ArrayIndexOutOfBoundsException("booom"),
            new StringIndexOutOfBoundsException("booom"),
            new FileNotFoundException("booom"),
            new NoSuchFileException("booom"),
            new AlreadyClosedException("closed!!", new NullPointerException()),
            new LockObtainFailedException("can't lock directory", new NullPointerException()),
            unknownException};
    for (final Exception cause : causes) {
        ElasticsearchException ex = new ElasticsearchException("topLevel", cause);
        ElasticsearchException deserialized = serialize(ex);
        assertEquals(deserialized.getMessage(), ex.getMessage());
        assertTrue("Expected: " + deserialized.getCause().getMessage() + " to contain: " +
                        ex.getCause().getClass().getName() + " but it didn't",
                deserialized.getCause().getMessage().contains(ex.getCause().getMessage()));
        if (ex.getCause().getClass() != UnknownException.class) { // unknown exception is not directly mapped
            assertEquals(deserialized.getCause().getClass(), ex.getCause().getClass());
        } else {
            assertEquals(deserialized.getCause().getClass(), NotSerializableExceptionWrapper.class);
        }
        assertArrayEquals(deserialized.getStackTrace(), ex.getStackTrace());
        assertTrue(deserialized.getStackTrace().length > 1);
        assertVersionSerializable(VersionUtils.randomVersion(random()), cause);
        assertVersionSerializable(VersionUtils.randomVersion(random()), ex);
        assertVersionSerializable(VersionUtils.randomVersion(random()), deserialized);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:42,代码来源:ExceptionSerializationTests.java


示例16: read

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
@Override
public FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext iocontext) throws IOException {
  final String fileName = IndexFileNames.segmentFileName(segmentName, "", FIELD_INFOS_EXTENSION);
  IndexInput input = directory.openInput(fileName, iocontext);
  
  boolean success = false;
  try {
    final int format = input.readVInt();

    if (format > FORMAT_MINIMUM) {
      throw new IndexFormatTooOldException(input, format, FORMAT_MINIMUM, FORMAT_CURRENT);
    }
    if (format < FORMAT_CURRENT) {
      throw new IndexFormatTooNewException(input, format, FORMAT_MINIMUM, FORMAT_CURRENT);
    }

    final int size = input.readVInt(); //read in the size
    FieldInfo infos[] = new FieldInfo[size];

    for (int i = 0; i < size; i++) {
      String name = input.readString();
      final int fieldNumber = i;
      byte bits = input.readByte();
      boolean isIndexed = (bits & IS_INDEXED) != 0;
      boolean storeTermVector = (bits & STORE_TERMVECTOR) != 0;
      boolean omitNorms = (bits & OMIT_NORMS) != 0;
      boolean storePayloads = (bits & STORE_PAYLOADS) != 0;
      final IndexOptions indexOptions;
      if (!isIndexed) {
        indexOptions = null;
      } else if ((bits & OMIT_TERM_FREQ_AND_POSITIONS) != 0) {
        indexOptions = IndexOptions.DOCS_ONLY;
      } else if ((bits & OMIT_POSITIONS) != 0) {
        if (format <= FORMAT_OMIT_POSITIONS) {
          indexOptions = IndexOptions.DOCS_AND_FREQS;
        } else {
          throw new CorruptIndexException("Corrupt fieldinfos, OMIT_POSITIONS set but format=" + format + " (resource: " + input + ")");
        }
      } else {
        indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
      }

      // LUCENE-3027: past indices were able to write
      // storePayloads=true when omitTFAP is also true,
      // which is invalid.  We correct that, here:
      if (indexOptions != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) {
        storePayloads = false;
      }
      infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, 
        omitNorms, storePayloads, indexOptions, null, isIndexed && !omitNorms? DocValuesType.NUMERIC : null, -1, Collections.<String,String>emptyMap());
    }

    if (input.getFilePointer() != input.length()) {
      throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
    }
    FieldInfos fieldInfos = new FieldInfos(infos);
    success = true;
    return fieldInfos;
  } finally {
    if (success) {
      input.close();
    } else {
      IOUtils.closeWhileHandlingException(input);
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:67,代码来源:Lucene3xFieldInfosReader.java


示例17: unwrapCorruption

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
public static IOException unwrapCorruption(Throwable t) {
    return (IOException) unwrap(t, CorruptIndexException.class, 
                                   IndexFormatTooOldException.class, 
                                   IndexFormatTooNewException.class);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:6,代码来源:ExceptionsHelper.java


示例18: restoreFile

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
/**
 * Restores a file
 * This is asynchronous method. Upon completion of the operation latch is getting counted down and any failures are
 * added to the {@code failures} list
 *
 * @param fileInfo file to be restored
 */
private void restoreFile(final FileInfo fileInfo) throws IOException {
    boolean success = false;

    try (InputStream partSliceStream = new PartSliceStream(blobContainer, fileInfo)) {
        final InputStream stream;
        if (restoreRateLimiter == null) {
            stream = partSliceStream;
        } else {
            stream = new RateLimitingInputStream(partSliceStream, restoreRateLimiter, restoreThrottleListener);
        }
        try (final IndexOutput indexOutput = store.createVerifyingOutput(fileInfo.physicalName(), fileInfo.metadata(), IOContext.DEFAULT)) {
            final byte[] buffer = new byte[BUFFER_SIZE];
            int length;
            while ((length = stream.read(buffer)) > 0) {
                indexOutput.writeBytes(buffer, 0, length);
                recoveryState.getIndex().addRecoveredBytesToFile(fileInfo.name(), length);
            }
            Store.verify(indexOutput);
            indexOutput.close();
            // write the checksum
            if (fileInfo.metadata().hasLegacyChecksum()) {
                Store.LegacyChecksums legacyChecksums = new Store.LegacyChecksums();
                legacyChecksums.add(fileInfo.metadata());
                legacyChecksums.write(store);

            }
            store.directory().sync(Collections.singleton(fileInfo.physicalName()));
            success = true;
        } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            try {
                store.markStoreCorrupted(ex);
            } catch (IOException e) {
                logger.warn("store cannot be marked as corrupted", e);
            }
            throw ex;
        } finally {
            if (success == false) {
                store.deleteQuiet(fileInfo.physicalName());
            }
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:50,代码来源:BlobStoreIndexShardRepository.java


示例19: read

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
@Override
public FieldInfos read(Directory directory, String segmentName, String segmentSuffix, IOContext iocontext) throws IOException {
  final String fileName = IndexFileNames.segmentFileName(segmentName, "", PreFlexRWFieldInfosWriter.FIELD_INFOS_EXTENSION);
  IndexInput input = directory.openInput(fileName, iocontext);
  
  try {
    final int format = input.readVInt();

    if (format > FORMAT_MINIMUM) {
      throw new IndexFormatTooOldException(input, format, FORMAT_MINIMUM, PreFlexRWFieldInfosWriter.FORMAT_CURRENT);
    }
    if (format < PreFlexRWFieldInfosWriter.FORMAT_CURRENT && format != PreFlexRWFieldInfosWriter.FORMAT_PREFLEX_RW) {
      throw new IndexFormatTooNewException(input, format, FORMAT_MINIMUM, PreFlexRWFieldInfosWriter.FORMAT_CURRENT);
    }

    final int size = input.readVInt(); //read in the size
    FieldInfo infos[] = new FieldInfo[size];

    for (int i = 0; i < size; i++) {
      String name = input.readString();
      final int fieldNumber = format == PreFlexRWFieldInfosWriter.FORMAT_PREFLEX_RW ? input.readInt() : i;
      byte bits = input.readByte();
      boolean isIndexed = (bits & PreFlexRWFieldInfosWriter.IS_INDEXED) != 0;
      boolean storeTermVector = (bits & PreFlexRWFieldInfosWriter.STORE_TERMVECTOR) != 0;
      boolean omitNorms = (bits & PreFlexRWFieldInfosWriter.OMIT_NORMS) != 0;
      boolean storePayloads = (bits & PreFlexRWFieldInfosWriter.STORE_PAYLOADS) != 0;
      final IndexOptions indexOptions;
      if (!isIndexed) {
        indexOptions = null;
      } else if ((bits & PreFlexRWFieldInfosWriter.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {
        indexOptions = IndexOptions.DOCS_ONLY;
      } else if ((bits & PreFlexRWFieldInfosWriter.OMIT_POSITIONS) != 0) {
        if (format <= PreFlexRWFieldInfosWriter.FORMAT_OMIT_POSITIONS) {
          indexOptions = IndexOptions.DOCS_AND_FREQS;
        } else {
          throw new CorruptIndexException("Corrupt fieldinfos, OMIT_POSITIONS set but format=" + format + " (resource: " + input + ")");
        }
      } else {
        indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
      }

      // LUCENE-3027: past indices were able to write
      // storePayloads=true when omitTFAP is also true,
      // which is invalid.  We correct that, here:
      if (indexOptions != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) {
        storePayloads = false;
      }
      
      DocValuesType normType = isIndexed && !omitNorms ? DocValuesType.NUMERIC : null;
      if (format == PreFlexRWFieldInfosWriter.FORMAT_PREFLEX_RW && normType != null) {
        // RW can have norms but doesn't write them
        normType = input.readByte() != 0 ? DocValuesType.NUMERIC : null;
      }
      
      infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, 
        omitNorms, storePayloads, indexOptions, null, normType, -1, null);
    }

    if (input.getFilePointer() != input.length()) {
      throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
    }
    return new FieldInfos(infos);
  } finally {
    input.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:67,代码来源:PreFlexRWFieldInfosReader.java


示例20: read

import org.apache.lucene.index.IndexFormatTooNewException; //导入依赖的package包/类
@Override
public FieldInfos read(Directory directory, String segmentName, IOContext iocontext) throws IOException {
  final String fileName = IndexFileNames.segmentFileName(segmentName, "", PreFlexRWFieldInfosWriter.FIELD_INFOS_EXTENSION);
  IndexInput input = directory.openInput(fileName, iocontext);
  
  try {
    final int format = input.readVInt();

    if (format > FORMAT_MINIMUM) {
      throw new IndexFormatTooOldException(input, format, FORMAT_MINIMUM, PreFlexRWFieldInfosWriter.FORMAT_CURRENT);
    }
    if (format < PreFlexRWFieldInfosWriter.FORMAT_CURRENT && format != PreFlexRWFieldInfosWriter.FORMAT_PREFLEX_RW) {
      throw new IndexFormatTooNewException(input, format, FORMAT_MINIMUM, PreFlexRWFieldInfosWriter.FORMAT_CURRENT);
    }

    final int size = input.readVInt(); //read in the size
    FieldInfo infos[] = new FieldInfo[size];

    for (int i = 0; i < size; i++) {
      String name = input.readString();
      final int fieldNumber = format == PreFlexRWFieldInfosWriter.FORMAT_PREFLEX_RW ? input.readInt() : i;
      byte bits = input.readByte();
      boolean isIndexed = (bits & PreFlexRWFieldInfosWriter.IS_INDEXED) != 0;
      boolean storeTermVector = (bits & PreFlexRWFieldInfosWriter.STORE_TERMVECTOR) != 0;
      boolean omitNorms = (bits & PreFlexRWFieldInfosWriter.OMIT_NORMS) != 0;
      boolean storePayloads = (bits & PreFlexRWFieldInfosWriter.STORE_PAYLOADS) != 0;
      final IndexOptions indexOptions;
      if (!isIndexed) {
        indexOptions = null;
      } else if ((bits & PreFlexRWFieldInfosWriter.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {
        indexOptions = IndexOptions.DOCS_ONLY;
      } else if ((bits & PreFlexRWFieldInfosWriter.OMIT_POSITIONS) != 0) {
        if (format <= PreFlexRWFieldInfosWriter.FORMAT_OMIT_POSITIONS) {
          indexOptions = IndexOptions.DOCS_AND_FREQS;
        } else {
          throw new CorruptIndexException("Corrupt fieldinfos, OMIT_POSITIONS set but format=" + format + " (resource: " + input + ")");
        }
      } else {
        indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
      }

      // LUCENE-3027: past indices were able to write
      // storePayloads=true when omitTFAP is also true,
      // which is invalid.  We correct that, here:
      if (indexOptions != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) {
        storePayloads = false;
      }
      
      DocValuesType normType = isIndexed && !omitNorms ? DocValuesType.NUMERIC : null;
      if (format == PreFlexRWFieldInfosWriter.FORMAT_PREFLEX_RW && normType != null) {
        // RW can have norms but doesn't write them
        normType = input.readByte() != 0 ? DocValuesType.NUMERIC : null;
      }
      
      infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, 
        omitNorms, storePayloads, indexOptions, null, normType, null);
    }

    if (input.getFilePointer() != input.length()) {
      throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.getFilePointer() + " vs size " + input.length() + " (resource: " + input + ")");
    }
    return new FieldInfos(infos);
  } finally {
    input.close();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:67,代码来源:PreFlexRWFieldInfosReader.java



注:本文中的org.apache.lucene.index.IndexFormatTooNewException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MapEventsReceiver类代码示例发布时间:2022-05-23
下一篇:
Java RuntimeNonElement类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap