[infinispan-commits] Infinispan SVN: r1975 - in branches/4.1.x/lucene-directory/src: test/java/org/infinispan/lucene and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Jul 5 11:07:59 EDT 2010
Author: sannegrinovero
Date: 2010-07-05 11:07:59 -0400 (Mon, 05 Jul 2010)
New Revision: 1975
Modified:
branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java
branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/DirectoryIntegrityCheck.java
Log:
[ISPN-523] (reduce Lucene Directory memory usage: store only initialized buffer ranges) - REVERTING on branch 4.1.x
Modified: branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java
===================================================================
--- branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java 2010-07-05 11:00:20 UTC (rev 1974)
+++ branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java 2010-07-05 15:07:59 UTC (rev 1975)
@@ -66,18 +66,7 @@
private static byte[] getChunkFromPosition(AdvancedCache<CacheKey, Object> cache, FileCacheKey fileKey, int pos, int bufferSize) {
CacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), getChunkNumberFromPosition(pos, bufferSize));
- byte[] readBuffer = (byte[]) cache.withFlags(Flag.SKIP_LOCKING).get(key);
- if (readBuffer==null) {
- return new byte[bufferSize];
- }
- else if (readBuffer.length==bufferSize) {
- return readBuffer;
- }
- else {
- byte[] newBuffer = new byte[bufferSize];
- System.arraycopy(readBuffer, 0, newBuffer, 0, readBuffer.length);
- return newBuffer;
- }
+ return (byte[]) cache.withFlags(Flag.SKIP_LOCKING).get(key);
}
private static int getPositionInBuffer(int pos, int bufferSize) {
@@ -91,7 +80,9 @@
private void newChunk() throws IOException {
flush();// save data first
// check if we have to create new chunk, or get already existing in cache for modification
- buffer = getChunkFromPosition(cache, fileKey, filePosition, bufferSize);
+ if ((buffer = getChunkFromPosition(cache, fileKey, filePosition, bufferSize)) == null) {
+ buffer = new byte[bufferSize];
+ }
bufferPosition = 0;
}
@@ -106,7 +97,7 @@
public void writeBytes(byte[] b, int offset, int length) throws IOException {
int writedBytes = 0;
while (writedBytes < length) {
- int pieceLength = Math.min(bufferSize - bufferPosition, length - writedBytes);
+ int pieceLength = Math.min(buffer.length - bufferPosition, length - writedBytes);
System.arraycopy(b, offset + writedBytes, buffer, bufferPosition, pieceLength);
bufferPosition += pieceLength;
filePosition += pieceLength;
@@ -131,17 +122,9 @@
if (file.getSize() < filePosition) {
file.setSize(filePosition);
}
- int newBufferSize = (int) (file.getSize() % bufferSize);
- byte[] shortedBuffer;
- if (newBufferSize != 0) {
- shortedBuffer = new byte[newBufferSize];
- System.arraycopy(buffer, 0, shortedBuffer, 0, newBufferSize);
- } else {
- shortedBuffer = buffer;
- }
cache.startBatch();
// add chunk to cache
- cache.withFlags(Flag.SKIP_REMOTE_LOOKUP).put(key, shortedBuffer);
+ cache.withFlags(Flag.SKIP_REMOTE_LOOKUP).put(key, buffer);
// override existing file header with new size and last time access
cache.withFlags(Flag.SKIP_REMOTE_LOOKUP).put(fileKey, file);
cache.endBatch(true);
Modified: branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/DirectoryIntegrityCheck.java
===================================================================
--- branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/DirectoryIntegrityCheck.java 2010-07-05 11:00:20 UTC (rev 1974)
+++ branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/DirectoryIntegrityCheck.java 2010-07-05 15:07:59 UTC (rev 1975)
@@ -77,7 +77,7 @@
FileMetadata metadata = (FileMetadata) value;
long totalFileSize = metadata.getSize();
long actualFileSize = deepCountFileSize(fileCacheKey, cache);
- Assert.assertEquals(actualFileSize, totalFileSize);
+// Assert.assertEquals(actualFileSize, totalFileSize); Depends on ISPN-523
} else if (key instanceof FileListCacheKey) {
fileListCacheKeyInstances++;
Assert.assertEquals(1, fileListCacheKeyInstances);
More information about the infinispan-commits
mailing list