Search in sources :

Example 81 with IndexOutput

use of org.apache.lucene.store.IndexOutput in project elasticsearch by elastic.

the class StoreRecoveryTests method testStatsDirWrapper.

public void testStatsDirWrapper() throws IOException {
    Directory dir = newDirectory();
    Directory target = newDirectory();
    RecoveryState.Index indexStats = new RecoveryState.Index();
    StoreRecovery.StatsDirectoryWrapper wrapper = new StoreRecovery.StatsDirectoryWrapper(target, indexStats);
    try (IndexOutput output = dir.createOutput("foo.bar", IOContext.DEFAULT)) {
        CodecUtil.writeHeader(output, "foo", 0);
        int numBytes = randomIntBetween(100, 20000);
        for (int i = 0; i < numBytes; i++) {
            output.writeByte((byte) i);
        }
        CodecUtil.writeFooter(output);
    }
    wrapper.copyFrom(dir, "foo.bar", "bar.foo", IOContext.DEFAULT);
    assertNotNull(indexStats.getFileDetails("bar.foo"));
    assertNull(indexStats.getFileDetails("foo.bar"));
    assertEquals(dir.fileLength("foo.bar"), indexStats.getFileDetails("bar.foo").length());
    assertEquals(dir.fileLength("foo.bar"), indexStats.getFileDetails("bar.foo").recovered());
    assertFalse(indexStats.getFileDetails("bar.foo").reused());
    IOUtils.close(dir, target);
}
Also used : IndexOutput(org.apache.lucene.store.IndexOutput) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) Directory(org.apache.lucene.store.Directory)

Example 82 with IndexOutput

use of org.apache.lucene.store.IndexOutput in project elasticsearch by elastic.

the class StoreTests method testStoreStats.

public void testStoreStats() throws IOException {
    final ShardId shardId = new ShardId("index", "_na_", 1);
    DirectoryService directoryService = new LuceneManagedDirectoryService(random());
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT).put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), TimeValue.timeValueMinutes(0)).build();
    Store store = new Store(shardId, IndexSettingsModule.newIndexSettings("index", settings), directoryService, new DummyShardLock(shardId));
    long initialStoreSize = 0;
    for (String extraFiles : store.directory().listAll()) {
        assertTrue("expected extraFS file but got: " + extraFiles, extraFiles.startsWith("extra"));
        initialStoreSize += store.directory().fileLength(extraFiles);
    }
    StoreStats stats = store.stats();
    assertEquals(stats.getSize().getBytes(), initialStoreSize);
    Directory dir = store.directory();
    final long length;
    try (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);
        }
        length = output.getFilePointer();
    }
    assertTrue(numNonExtraFiles(store) > 0);
    stats = store.stats();
    assertEquals(stats.getSizeInBytes(), length + initialStoreSize);
    deleteContent(store.directory());
    IOUtils.close(store);
}
Also used : IndexOutput(org.apache.lucene.store.IndexOutput) ShardId(org.elasticsearch.index.shard.ShardId) DummyShardLock(org.elasticsearch.test.DummyShardLock) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) BytesRef(org.apache.lucene.util.BytesRef) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 83 with IndexOutput

use of org.apache.lucene.store.IndexOutput in project gerrit by GerritCodeReview.

the class QueryDocumentationExecutor method readIndexDirectory.

protected Directory readIndexDirectory() throws IOException {
    Directory dir = new RAMDirectory();
    byte[] buffer = new byte[4096];
    InputStream index = getClass().getResourceAsStream(Constants.INDEX_ZIP);
    if (index == null) {
        log.warn("No index available");
        return null;
    }
    try (ZipInputStream zip = new ZipInputStream(index)) {
        ZipEntry entry;
        while ((entry = zip.getNextEntry()) != null) {
            try (IndexOutput out = dir.createOutput(entry.getName(), null)) {
                int count;
                while ((count = zip.read(buffer)) != -1) {
                    out.writeBytes(buffer, count);
                }
            }
        }
    }
    // We must NOT call dir.close() here, as DirectoryReader.open() expects an opened directory.
    return dir;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IndexOutput(org.apache.lucene.store.IndexOutput) RAMDirectory(org.apache.lucene.store.RAMDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory)

Example 84 with IndexOutput

use of org.apache.lucene.store.IndexOutput in project zm-mailbox by Zimbra.

the class LuceneDirectoryTest method write.

@Test
public void write() throws IOException {
    long count = ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getCount();
    long total = ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getTotal();
    LuceneDirectory dir = LuceneDirectory.open(new File("/tmp"));
    IndexOutput out = dir.createOutput("write");
    out.writeBytes(new byte[] { 0, 1, 2 }, 3);
    out.close();
    Assert.assertEquals(1, ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getCount() - count);
    Assert.assertEquals(3, ZimbraPerf.COUNTER_IDX_BYTES_WRITTEN.getTotal() - total);
}
Also used : IndexOutput(org.apache.lucene.store.IndexOutput) File(java.io.File) Test(org.junit.Test)

Example 85 with IndexOutput

use of org.apache.lucene.store.IndexOutput in project jackrabbit-oak by apache.

the class LuceneBlobCacheTest method assertWrites.

byte[] assertWrites(Directory dir, int blobSize) throws IOException {
    byte[] data = randomBytes(blobSize);
    IndexOutput o = dir.createOutput("test", IOContext.DEFAULT);
    o.writeBytes(data, data.length);
    o.close();
    IndexInput i = dir.openInput("test", IOContext.DEFAULT);
    assertEquals(blobSize, i.length());
    byte[] result = new byte[blobSize];
    i.readBytes(result, 0, result.length);
    assertTrue(Arrays.equals(data, result));
    // Load agagin to see if cached
    i = dir.openInput("test", IOContext.DEFAULT);
    assertEquals(blobSize, i.length());
    result = new byte[blobSize];
    i.readBytes(result, 0, result.length);
    assertTrue(Arrays.equals(data, result));
    assertEquals(1, fileDataStore.count);
    return data;
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) IndexOutput(org.apache.lucene.store.IndexOutput)

Aggregations

IndexOutput (org.apache.lucene.store.IndexOutput)157 IndexInput (org.apache.lucene.store.IndexInput)69 Directory (org.apache.lucene.store.Directory)66 RAMDirectory (org.apache.lucene.store.RAMDirectory)28 FilterDirectory (org.apache.lucene.store.FilterDirectory)26 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)22 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)19 CorruptingIndexOutput (org.apache.lucene.store.CorruptingIndexOutput)18 BytesRef (org.apache.lucene.util.BytesRef)18 RAMFile (org.apache.lucene.store.RAMFile)16 RAMOutputStream (org.apache.lucene.store.RAMOutputStream)16 IOException (java.io.IOException)14 IOContext (org.apache.lucene.store.IOContext)12 BufferedChecksumIndexInput (org.apache.lucene.store.BufferedChecksumIndexInput)11 RAMInputStream (org.apache.lucene.store.RAMInputStream)11 NRTCachingDirectory (org.apache.lucene.store.NRTCachingDirectory)10 ArrayList (java.util.ArrayList)9 IntersectVisitor (org.apache.lucene.index.PointValues.IntersectVisitor)9 Relation (org.apache.lucene.index.PointValues.Relation)9 HashMap (java.util.HashMap)8