use of org.apache.lucene.store.IndexOutput in project jackrabbit by apache.
the class PersistentIndex method copyIndex.
/**
* Copies <code>index</code> into this persistent index. This method should
* only be called when <code>this</code> index is empty otherwise the
* behaviour is undefined.
*
* @param index the index to copy from.
* @throws IOException if an error occurs while copying.
*/
void copyIndex(AbstractIndex index) throws IOException {
// commit changes to directory on other index.
index.commit(true);
// simply copy over the files
byte[] buffer = new byte[1024];
Directory dir = index.getDirectory();
Directory dest = getDirectory();
String[] files = dir.listAll();
for (String file : files) {
IndexInput in = dir.openInput(file);
try {
IndexOutput out = dest.createOutput(file);
try {
long remaining = in.length();
while (remaining > 0) {
int num = (int) Math.min(remaining, buffer.length);
in.readBytes(buffer, 0, num);
out.writeBytes(buffer, num);
remaining -= num;
}
} finally {
out.close();
}
} finally {
in.close();
}
}
// refresh current generation
indexDelPolicy.readCurrentGeneration();
}
use of org.apache.lucene.store.IndexOutput in project jackrabbit-oak by apache.
the class OakDirectoryTest method assertWrites.
byte[] assertWrites(Directory dir, int blobSize) throws IOException {
byte[] data = randomBytes(fileSize);
IndexOutput o = dir.createOutput("test", IOContext.DEFAULT);
o.writeBytes(data, data.length);
o.close();
assertTrue(dir.fileExists("test"));
assertEquals(fileSize, dir.fileLength("test"));
IndexInput i = dir.openInput("test", IOContext.DEFAULT);
assertEquals(fileSize, i.length());
byte[] result = new byte[fileSize];
i.readBytes(result, 0, result.length);
assertTrue(Arrays.equals(data, result));
NodeBuilder testNode = builder.child(INDEX_DATA_CHILD_NAME).child("test");
assertEquals(blobSize, testNode.getProperty(PROP_BLOB_SIZE).getValue(Type.LONG).longValue());
List<Blob> blobs = newArrayList(testNode.getProperty(JCR_DATA).getValue(BINARIES));
assertEquals(blobSize + UNIQUE_KEY_SIZE, blobs.get(0).length());
return data;
}
use of org.apache.lucene.store.IndexOutput in project jackrabbit-oak by apache.
the class OakDirectoryTest method dirNameInException_Writes.
@Test
public void dirNameInException_Writes() throws Exception {
FailOnDemandBlobStore blobStore = new FailOnDemandBlobStore();
FileStore store = FileStoreBuilder.fileStoreBuilder(tempFolder.getRoot()).withMemoryMapping(false).withBlobStore(blobStore).build();
SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(store).build();
String indexPath = "/foo/bar";
int minFileSize = SegmentTestConstants.MEDIUM_LIMIT;
int blobSize = minFileSize + 1000;
builder = nodeStore.getRoot().builder();
builder.setProperty(LuceneIndexConstants.BLOB_SIZE, blobSize);
Directory dir = createDir(builder, false, indexPath);
blobStore.startFailing();
IndexOutput o = dir.createOutput("test1.txt", IOContext.DEFAULT);
try {
o.writeBytes(randomBytes(blobSize + 10), blobSize + 10);
fail();
} catch (IOException e) {
assertThat(e.getMessage(), containsString(indexPath));
assertThat(e.getMessage(), containsString("test1.txt"));
}
blobStore.reset();
IndexOutput o3 = dir.createOutput("test3.txt", IOContext.DEFAULT);
o3.writeBytes(randomBytes(minFileSize), minFileSize);
blobStore.startFailing();
try {
o3.flush();
fail();
} catch (IOException e) {
assertThat(e.getMessage(), containsString(indexPath));
assertThat(e.getMessage(), containsString("test3.txt"));
}
store.close();
}
use of org.apache.lucene.store.IndexOutput in project jackrabbit-oak by apache.
the class OakDirectoryTest method writeFile.
private static void writeFile(Directory directory, String fileName, long size) throws Exception {
IndexOutput o = directory.createOutput(fileName, IOContext.DEFAULT);
o.copyBytes(new InputStreamDataInput(new NullInputStream(size)), size);
o.close();
}
use of org.apache.lucene.store.IndexOutput in project elasticsearch by elastic.
the class Store method markStoreCorrupted.
/**
* Marks this store as corrupted. This method writes a <tt>corrupted_${uuid}</tt> file containing the given exception
* message. If a store contains a <tt>corrupted_${uuid}</tt> file {@link #isMarkedCorrupted()} will return <code>true</code>.
*/
public void markStoreCorrupted(IOException exception) throws IOException {
ensureOpen();
if (!isMarkedCorrupted()) {
String uuid = CORRUPTED + UUIDs.randomBase64UUID();
try (IndexOutput output = this.directory().createOutput(uuid, IOContext.DEFAULT)) {
CodecUtil.writeHeader(output, CODEC, VERSION);
BytesStreamOutput out = new BytesStreamOutput();
out.writeException(exception);
BytesReference bytes = out.bytes();
output.writeVInt(bytes.length());
BytesRef ref = bytes.toBytesRef();
output.writeBytes(ref.bytes, ref.offset, ref.length);
CodecUtil.writeFooter(output);
} catch (IOException ex) {
logger.warn("Can't mark store as corrupted", ex);
}
directory().sync(Collections.singleton(uuid));
}
}
Aggregations