[infinispan-commits] Infinispan SVN: r1928 - 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 Jun 21 15:10:53 EDT 2010
Author: sannegrinovero
Date: 2010-06-21 15:10:53 -0400 (Mon, 21 Jun 2010)
New Revision: 1928
Modified:
branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java
branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexIO.java
branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/CacheTestSupport.java
Log:
[ISPN-500] (Improve Lucene's performance by using SKIP_LOCKING, SKIP_REMOTE_LOOKUP and batching) - branch 4.1.x
Modified: branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java
===================================================================
--- branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java 2010-06-21 16:30:16 UTC (rev 1927)
+++ branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanDirectory.java 2010-06-21 19:10:53 UTC (rev 1928)
@@ -30,7 +30,9 @@
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.LockFactory;
+import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
+import org.infinispan.context.Flag;
import org.infinispan.lucene.locking.BaseLockFactory;
import org.infinispan.util.concurrent.ConcurrentHashSet;
import org.infinispan.util.logging.Log;
@@ -55,7 +57,7 @@
// access type will be changed in the next Lucene version
volatile boolean isOpen = true;
- private final Cache<CacheKey, Object> cache;
+ private final AdvancedCache<CacheKey, Object> cache;
// indexName is required when one common cache is used
private final String indexName;
// chunk size used in this directory, static filed not used as we want to have different chunk
@@ -65,7 +67,7 @@
private final FileListCacheKey fileListCacheKey;
public InfinispanDirectory(Cache<CacheKey, Object> cache, String indexName, LockFactory lf, int chunkSize) {
- this.cache = cache;
+ this.cache = cache.getAdvancedCache();
this.indexName = indexName;
this.setLockFactory(lf);
this.chunkSize = chunkSize;
@@ -103,7 +105,7 @@
*/
public boolean fileExists(String name) throws IOException {
checkIsOpen();
- return cache.containsKey(new FileCacheKey(indexName, name));
+ return cache.withFlags(Flag.SKIP_LOCKING).containsKey(new FileCacheKey(indexName, name));
}
/**
@@ -161,6 +163,7 @@
*/
public void renameFile(String from, String to) throws IOException {
checkIsOpen();
+ cache.startBatch();
// rename main file header
CacheKey fromKey = new FileCacheKey(indexName, from);
FileMetadata fileFrom = (FileMetadata) cache.remove(fromKey);
@@ -178,12 +181,14 @@
if (ob == null) {
break;
}
+ cache.remove(fromChunkKey);
ChunkCacheKey toChunkKey = new ChunkCacheKey(indexName, to, i);
cache.put(toChunkKey, ob);
} while (true);
if (log.isTraceEnabled()) {
log.trace("Renamed file from: {0} to: {1} in index {2}", from, to, indexName);
}
+ cache.endBatch(true);
}
/**
@@ -218,7 +223,7 @@
@SuppressWarnings("unchecked")
private Set<String> getFileList() {
- Set<String> fileList = (Set<String>) cache.get(fileListCacheKey);
+ Set<String> fileList = (Set<String>) cache.withFlags(Flag.SKIP_LOCKING).get(fileListCacheKey);
if (fileList == null)
fileList = new ConcurrentHashSet<String>();
return fileList;
@@ -247,7 +252,7 @@
private FileMetadata getFileMetadata(String fileName) {
CacheKey key = new FileCacheKey(indexName, fileName);
- return (FileMetadata) cache.get(key);
+ return (FileMetadata) cache.withFlags(Flag.SKIP_LOCKING).get(key);
}
@Override
Modified: branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexIO.java
===================================================================
--- branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexIO.java 2010-06-21 16:30:16 UTC (rev 1927)
+++ branches/4.1.x/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexIO.java 2010-06-21 19:10:53 UTC (rev 1928)
@@ -23,11 +23,11 @@
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.Map;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
-import org.infinispan.Cache;
+import org.infinispan.AdvancedCache;
+import org.infinispan.context.Flag;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
@@ -47,11 +47,17 @@
// each Lucene index segment is splitted into parts with default size defined here
public final static int DEFAULT_BUFFER_SIZE = 16 * 1024;
- private static byte[] getChunkFromPosition(Map<CacheKey, Object> cache, FileCacheKey fileKey, int pos, int bufferSize) {
+ 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));
- return (byte[]) cache.get(key);
+ return (byte[]) cache.withFlags(Flag.SKIP_LOCKING).get(key);
}
+
+ public static byte[] getChunkFromPosition(ConcurrentHashMap<CacheKey, Object> localCache, FileCacheKey fileKey, int pos, int bufferSize) {
+ CacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), getChunkNumberFromPosition(pos,
+ bufferSize));
+ return (byte[]) localCache.get(key);
+ }
private static int getPositionInBuffer(int pos, int bufferSize) {
return (pos % bufferSize);
@@ -70,20 +76,20 @@
private final int bufferSize;
- private Cache<CacheKey, Object> cache;
+ private final AdvancedCache<CacheKey, Object> cache;
+ private final FileMetadata file;
+ private final FileCacheKey fileKey;
private ConcurrentHashMap<CacheKey, Object> localCache = new ConcurrentHashMap<CacheKey, Object>();
- private FileMetadata file;
- private FileCacheKey fileKey;
private byte[] buffer;
private int bufferPosition = 0;
private int filePosition = 0;
private int lastChunkNumberLoaded = -1;
- public InfinispanIndexInput(Cache<CacheKey, Object> cache, FileCacheKey fileKey) throws IOException {
+ public InfinispanIndexInput(AdvancedCache<CacheKey, Object> cache, FileCacheKey fileKey) throws IOException {
this(cache, fileKey, InfinispanIndexIO.DEFAULT_BUFFER_SIZE);
}
- public InfinispanIndexInput(Cache<CacheKey, Object> cache, FileCacheKey fileKey, int bufferSize) throws IOException {
+ public InfinispanIndexInput(AdvancedCache<CacheKey, Object> cache, FileCacheKey fileKey, int bufferSize) throws IOException {
this.cache = cache;
this.fileKey = fileKey;
this.bufferSize = bufferSize;
@@ -111,18 +117,17 @@
}
}
- private byte[] getChunkFromPosition(Cache<CacheKey, Object> cache, FileCacheKey fileKey, int pos, int bufferSize) {
- if(lastChunkNumberLoaded != getChunkNumberFromPosition(filePosition, bufferSize)) {
- Object object = InfinispanIndexIO.getChunkFromPosition(cache, fileKey, pos, bufferSize);
- if (object == null) {
- object = InfinispanIndexIO.getChunkFromPosition(localCache, fileKey, pos, bufferSize);
- }
- lastChunkNumberLoaded = getChunkNumberFromPosition(filePosition, bufferSize);
- return (byte[]) object;
- } else {
- return buffer;
- }
-
+ private byte[] getChunkFromPosition(AdvancedCache<CacheKey, Object> cache, FileCacheKey fileKey, int pos, int bufferSize) {
+ if (lastChunkNumberLoaded != getChunkNumberFromPosition(filePosition, bufferSize)) {
+ Object object = InfinispanIndexIO.getChunkFromPosition(cache, fileKey, pos, bufferSize);
+ if (object == null) {
+ object = InfinispanIndexIO.getChunkFromPosition(localCache, fileKey, pos, bufferSize);
+ }
+ lastChunkNumberLoaded = getChunkNumberFromPosition(filePosition, bufferSize);
+ return (byte[]) object;
+ } else {
+ return buffer;
+ }
}
public byte readByte() throws IOException {
@@ -189,7 +194,7 @@
private final int bufferSize;
- private final Cache<CacheKey, Object> cache;
+ private final AdvancedCache<CacheKey, Object> cache;
private final FileMetadata file;
private final FileCacheKey fileKey;
@@ -198,7 +203,7 @@
private int filePosition = 0;
private int chunkNumber;
- public InfinispanIndexOutput(Cache<CacheKey, Object> cache, FileCacheKey fileKey, int bufferSize, FileMetadata fileMetadata) throws IOException {
+ public InfinispanIndexOutput(AdvancedCache<CacheKey, Object> cache, FileCacheKey fileKey, int bufferSize, FileMetadata fileMetadata) throws IOException {
this.cache = cache;
this.fileKey = fileKey;
this.bufferSize = bufferSize;
@@ -252,11 +257,16 @@
// and create distinct key for it
ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), chunkNumber);
// size changed, apply change to file header
- setFileLength();
+ file.touch();
+ if (file.getSize() < filePosition) {
+ file.setSize(filePosition);
+ }
+ cache.startBatch();
// add chunk to cache
- cache.put(key, buffer);
- // override existing file header with new size and last time acess
- cache.put(fileKey, file);
+ 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);
}
public void close() throws IOException {
@@ -267,6 +277,7 @@
if (log.isDebugEnabled()) {
log.debug("Closed IndexOutput for file:{0} in index: {1}", fileKey.getFileName(), fileKey.getIndexName());
}
+ // cache.compact(); //TODO investigate about this
}
public long getFilePointer() {
@@ -289,11 +300,6 @@
return file.getSize();
}
- protected void setFileLength() {
- file.touch();
- if (file.getSize() < filePosition) {
- file.setSize(filePosition);
- }
- }
}
+
}
Modified: branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/CacheTestSupport.java
===================================================================
--- branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/CacheTestSupport.java 2010-06-21 16:30:16 UTC (rev 1927)
+++ branches/4.1.x/lucene-directory/src/test/java/org/infinispan/lucene/CacheTestSupport.java 2010-06-21 19:10:53 UTC (rev 1928)
@@ -37,7 +37,6 @@
import org.infinispan.lucene.testutils.LuceneSettings;
import org.infinispan.manager.CacheContainer;
import org.infinispan.test.fwk.TestCacheManagerFactory;
-import org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
@@ -63,14 +62,12 @@
c.setCacheMode(Configuration.CacheMode.DIST_SYNC);
c.setSyncReplTimeout(10000);
c.setLockAcquisitionTimeout(10000);
- c.setUseLockStriping(false);
c.setSyncCommitPhase(true);
c.setL1CacheEnabled(true);
c.setExposeJmxStatistics(false);
- c.setUseEagerLocking(false);
c.setSyncRollbackPhase(true);
- c.setTransactionManagerLookupClass(JBossStandaloneJTAManagerLookup.class.getName());
- c.setDeadlockDetectionSpinDuration( 10000 );
+ c.setEnableDeadlockDetection(false);
+ c.setInvocationBatchingEnabled(true);
return c;
}
@@ -141,6 +138,7 @@
cfg.setExposeJmxStatistics(false);
cfg.setL1CacheEnabled(false);
cfg.setWriteSkewCheck(false);
+ cfg.setInvocationBatchingEnabled(true);
return TestCacheManagerFactory.createCacheManager(globalConfiguration, cfg, true);
}
More information about the infinispan-commits
mailing list