mirror of https://github.com/apache/lucene.git
LUCENE-475 - patch from Volodymyr Bychkoviak to reduce memory usage
when loading an index into RAMDirectory. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@351779 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
abb213261d
commit
6cabdf3726
|
@ -304,7 +304,10 @@ Bug fixes
|
|||
17. A single hit using the expert level sorted search methods
|
||||
resulted in the score not being normalized.
|
||||
(Yonik Seeley, LUCENE-462)
|
||||
|
||||
|
||||
18. Fixed inefficient memory usage when loading an index into RAMDirectory.
|
||||
(Volodymyr Bychkoviak via Bernhard, LUCENE-475)
|
||||
|
||||
Optimizations
|
||||
|
||||
1. Disk usage (peak requirements during indexing and optimization)
|
||||
|
|
|
@ -53,6 +53,7 @@ public final class RAMDirectory extends Directory {
|
|||
|
||||
private RAMDirectory(Directory dir, boolean closeDir) throws IOException {
|
||||
final String[] files = dir.list();
|
||||
byte[] buf = new byte[BufferedIndexOutput.BUFFER_SIZE];
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
// make place on ram disk
|
||||
IndexOutput os = createOutput(files[i]);
|
||||
|
@ -60,9 +61,14 @@ public final class RAMDirectory extends Directory {
|
|||
IndexInput is = dir.openInput(files[i]);
|
||||
// and copy to ram disk
|
||||
int len = (int) is.length();
|
||||
byte[] buf = new byte[len];
|
||||
is.readBytes(buf, 0, len);
|
||||
os.writeBytes(buf, len);
|
||||
int readCount = 0;
|
||||
while (readCount < len) {
|
||||
int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len ? len - readCount : BufferedIndexOutput.BUFFER_SIZE;
|
||||
is.readBytes(buf, 0, toRead);
|
||||
os.writeBytes(buf, toRead);
|
||||
readCount += toRead;
|
||||
}
|
||||
|
||||
// graceful cleanup
|
||||
is.close();
|
||||
os.close();
|
||||
|
|
Loading…
Reference in New Issue