Search in sources :

Example 16 with IOContext

use of org.apache.lucene.store.IOContext in project lucene-solr by apache.

the class BlockDirectoryTest method testEof.

private void testEof(String name, Directory directory, long length) throws IOException {
    IndexInput input = directory.openInput(name, new IOContext());
    try {
        input.seek(length);
        try {
            input.readByte();
            fail("should throw eof");
        } catch (IOException e) {
        }
    } finally {
        input.close();
    }
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) IOContext(org.apache.lucene.store.IOContext) IOException(java.io.IOException)

Example 17 with IOContext

use of org.apache.lucene.store.IOContext in project lucene-solr by apache.

the class BlockDirectoryTest method ensureCacheConfigurable.

/**
   * Verify the configuration options for the block cache are handled
   * appropriately.
   */
@Test
public void ensureCacheConfigurable() throws Exception {
    IOContext mergeContext = new IOContext(new MergeInfo(1, 1, false, 1));
    BlockDirectory d = directory;
    assertTrue(d.useReadCache("", IOContext.DEFAULT));
    if (d.getCache() instanceof MapperCache) {
        assertTrue(d.useWriteCache("", IOContext.DEFAULT));
    } else {
        assertFalse(d.useWriteCache("", IOContext.DEFAULT));
    }
    assertFalse(d.useWriteCache("", mergeContext));
    d = new BlockDirectory("test", directory, mapperCache, null, true, false);
    assertTrue(d.useReadCache("", IOContext.DEFAULT));
    assertFalse(d.useWriteCache("", IOContext.DEFAULT));
    assertFalse(d.useWriteCache("", mergeContext));
    d = new BlockDirectory("test", directory, mapperCache, null, false, true);
    assertFalse(d.useReadCache("", IOContext.DEFAULT));
    if (d.getCache() instanceof MapperCache) {
        assertTrue(d.useWriteCache("", IOContext.DEFAULT));
    } else {
        assertFalse(d.useWriteCache("", IOContext.DEFAULT));
    }
    assertFalse(d.useWriteCache("", mergeContext));
}
Also used : MergeInfo(org.apache.lucene.store.MergeInfo) IOContext(org.apache.lucene.store.IOContext) Test(org.junit.Test)

Example 18 with IOContext

use of org.apache.lucene.store.IOContext in project lucene-solr by apache.

the class TestOfflineSorter method testBitFlippedOnPartition1.

/** Make sure corruption on a temp file (partition) is caught, even if the corruption didn't confuse OfflineSorter! */
public void testBitFlippedOnPartition1() throws Exception {
    try (Directory dir0 = newMockDirectory()) {
        Directory dir = new FilterDirectory(dir0) {

            boolean corrupted;

            @Override
            public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
                IndexOutput out = in.createTempOutput(prefix, suffix, context);
                if (corrupted == false && suffix.equals("sort")) {
                    corrupted = true;
                    return new CorruptingIndexOutput(dir0, 544677, out);
                } else {
                    return out;
                }
            }
        };
        IndexOutput unsorted = dir.createTempOutput("unsorted", "tmp", IOContext.DEFAULT);
        writeAll(unsorted, generateFixed((int) (OfflineSorter.MB * 3)));
        CorruptIndexException e = expectThrows(CorruptIndexException.class, () -> {
            new OfflineSorter(dir, "foo", OfflineSorter.DEFAULT_COMPARATOR, BufferSize.megabytes(1), 10, -1, null, 0).sort(unsorted.getName());
        });
        assertTrue(e.getMessage().contains("checksum failed (hardware problem?)"));
    }
}
Also used : FilterDirectory(org.apache.lucene.store.FilterDirectory) IOContext(org.apache.lucene.store.IOContext) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput) IndexOutput(org.apache.lucene.store.IndexOutput) FilterDirectory(org.apache.lucene.store.FilterDirectory) Directory(org.apache.lucene.store.Directory) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput)

Example 19 with IOContext

use of org.apache.lucene.store.IOContext in project lucene-solr by apache.

the class TestOfflineSorter method testBitFlippedOnPartition2.

/** Make sure corruption on a temp file (partition) is caught, if the corruption did confuse OfflineSorter! */
public void testBitFlippedOnPartition2() throws Exception {
    try (Directory dir0 = newMockDirectory()) {
        Directory dir = new FilterDirectory(dir0) {

            boolean corrupted;

            @Override
            public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
                IndexOutput out = in.createTempOutput(prefix, suffix, context);
                if (corrupted == false && suffix.equals("sort")) {
                    corrupted = true;
                    return new CorruptingIndexOutput(dir0, 544677, out) {

                        @Override
                        protected void corruptFile() throws IOException {
                            String newTempName;
                            try (IndexOutput tmpOut = dir0.createTempOutput("tmp", "tmp", IOContext.DEFAULT);
                                IndexInput in = dir0.openInput(out.getName(), IOContext.DEFAULT)) {
                                newTempName = tmpOut.getName();
                                tmpOut.copyBytes(in, 1025905);
                                short v = in.readShort();
                                assertEquals(254, v);
                                tmpOut.writeShort(Short.MAX_VALUE);
                                tmpOut.copyBytes(in, in.length() - 1025905 - Short.BYTES);
                            }
                            // Delete original and copy corrupt version back:
                            dir0.deleteFile(out.getName());
                            dir0.copyFrom(dir0, newTempName, out.getName(), IOContext.DEFAULT);
                            dir0.deleteFile(newTempName);
                        }
                    };
                } else {
                    return out;
                }
            }
        };
        IndexOutput unsorted = dir.createTempOutput("unsorted", "tmp", IOContext.DEFAULT);
        writeAll(unsorted, generateFixed((int) (OfflineSorter.MB * 3)));
        EOFException e = expectThrows(EOFException.class, () -> {
            new OfflineSorter(dir, "foo", OfflineSorter.DEFAULT_COMPARATOR, BufferSize.megabytes(1), 10, -1, null, 0).sort(unsorted.getName());
        });
        assertEquals(1, e.getSuppressed().length);
        assertTrue(e.getSuppressed()[0] instanceof CorruptIndexException);
        assertTrue(e.getSuppressed()[0].getMessage().contains("checksum failed (hardware problem?)"));
    }
}
Also used : FilterDirectory(org.apache.lucene.store.FilterDirectory) EOFException(java.io.EOFException) IOContext(org.apache.lucene.store.IOContext) IndexInput(org.apache.lucene.store.IndexInput) ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput) IndexOutput(org.apache.lucene.store.IndexOutput) FilterDirectory(org.apache.lucene.store.FilterDirectory) Directory(org.apache.lucene.store.Directory) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput)

Example 20 with IOContext

use of org.apache.lucene.store.IOContext in project lucene-solr by apache.

the class TestOfflineSorter method testBitFlippedOnInput1.

/** Make sure corruption on the incoming (unsorted) file is caught, even if the corruption didn't confuse OfflineSorter! */
public void testBitFlippedOnInput1() throws Exception {
    try (Directory dir0 = newMockDirectory()) {
        Directory dir = new FilterDirectory(dir0) {

            @Override
            public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) throws IOException {
                IndexOutput out = in.createTempOutput(prefix, suffix, context);
                if (prefix.equals("unsorted")) {
                    return new CorruptingIndexOutput(dir0, 22, out);
                } else {
                    return out;
                }
            }
        };
        IndexOutput unsorted = dir.createTempOutput("unsorted", "tmp", IOContext.DEFAULT);
        writeAll(unsorted, generateFixed(10 * 1024));
        CorruptIndexException e = expectThrows(CorruptIndexException.class, () -> {
            new OfflineSorter(dir, "foo").sort(unsorted.getName());
        });
        assertTrue(e.getMessage().contains("checksum failed (hardware problem?)"));
    }
}
Also used : FilterDirectory(org.apache.lucene.store.FilterDirectory) IOContext(org.apache.lucene.store.IOContext) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput) IndexOutput(org.apache.lucene.store.IndexOutput) FilterDirectory(org.apache.lucene.store.FilterDirectory) Directory(org.apache.lucene.store.Directory) CorruptingIndexOutput(org.apache.lucene.store.CorruptingIndexOutput)

Aggregations

IOContext (org.apache.lucene.store.IOContext)40 Directory (org.apache.lucene.store.Directory)18 FilterDirectory (org.apache.lucene.store.FilterDirectory)15 FlushInfo (org.apache.lucene.store.FlushInfo)13 IndexOutput (org.apache.lucene.store.IndexOutput)12 IndexInput (org.apache.lucene.store.IndexInput)10 Test (org.junit.Test)8 IOException (java.io.IOException)7 TrackingDirectoryWrapper (org.apache.lucene.store.TrackingDirectoryWrapper)7 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)6 CorruptingIndexOutput (org.apache.lucene.store.CorruptingIndexOutput)6 MergeInfo (org.apache.lucene.store.MergeInfo)6 Codec (org.apache.lucene.codecs.Codec)5 RAMDirectory (org.apache.lucene.store.RAMDirectory)5 ForwardingListeningExecutorService (com.google.common.util.concurrent.ForwardingListeningExecutorService)4 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)4 ExecutorService (java.util.concurrent.ExecutorService)4 BytesRef (org.apache.lucene.util.BytesRef)4 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3