[infinispan-commits] Infinispan SVN: r2121 - trunk/lucene-directory/src/main/java/org/infinispan/lucene.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Jul 29 17:49:04 EDT 2010


Author: sannegrinovero
Date: 2010-07-29 17:49:03 -0400 (Thu, 29 Jul 2010)
New Revision: 2121

Modified:
   trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexInput.java
   trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java
Log:
[ISPN-250] (Replace transactions with async methods combined with batching) - trunk

Modified: trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexInput.java
===================================================================
--- trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexInput.java	2010-07-29 21:46:53 UTC (rev 2120)
+++ trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexInput.java	2010-07-29 21:49:03 UTC (rev 2121)
@@ -68,7 +68,7 @@
       try {
 
          // get file header from file
-         this.file = (FileMetadata) cache.get(fileKey);
+         this.file = (FileMetadata) cache.withFlags(Flag.SKIP_LOCKING).get(fileKey);
 
          if (file == null) {
             throw new FileNotFoundException("Error loading medatada for index file: " + fileKey);
@@ -137,9 +137,9 @@
          chunkKey = new ChunkCacheKey(indexName, filename, ++i);
       } while (removed != null);
       cache.startBatch();
-      cache.withFlags(Flag.SKIP_REMOTE_LOOKUP,Flag.SKIP_LOCKING).remove(readLockKey);
+      cache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_LOCKING).remove(readLockKey);
       FileCacheKey key = new FileCacheKey(indexName, filename);
-      cache.withFlags(Flag.SKIP_REMOTE_LOOKUP,Flag.SKIP_LOCKING).remove(key);
+      cache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_LOCKING).remove(key);
       cache.endBatch(true);
    }
 
@@ -153,7 +153,7 @@
       // spinning as we currently don't mandate transactions, so no proper lock support is available
       boolean done = false;
       while (done == false) {
-         Object lockValue = cache.get(readLockKey);
+         Object lockValue = cache.withFlags(Flag.SKIP_LOCKING).get(readLockKey);
          if (lockValue == null)
             return; // no special locking for some core files
          int refCount = (Integer) lockValue;
@@ -229,7 +229,7 @@
 
    private void setBufferToCurrentChunk() throws IOException {
       CacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), currentLoadedChunk);
-      buffer = (byte[]) cache.get(key);
+      buffer = (byte[]) cache.withFlags(Flag.SKIP_LOCKING).get(key);
       if (buffer == null) {
          throw new IOException("Chunk value could not be found for key " + key);
       }
@@ -240,7 +240,7 @@
    // RAMDirectory teaches to position the cursor to the end of previous chunk in this case
    private void setBufferToCurrentChunkIfPossible() throws IOException {
       CacheKey key = new ChunkCacheKey(fileKey.getIndexName(), fileKey.getFileName(), currentLoadedChunk);
-      buffer = (byte[]) cache.get(key);
+      buffer = (byte[]) cache.withFlags(Flag.SKIP_LOCKING).get(key);
       if (buffer == null) {
          currentLoadedChunk--;
          bufferPosition = chunkSize;

Modified: trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java
===================================================================
--- trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java	2010-07-29 21:46:53 UTC (rev 2120)
+++ trunk/lucene-directory/src/main/java/org/infinispan/lucene/InfinispanIndexOutput.java	2010-07-29 21:49:03 UTC (rev 2121)
@@ -86,6 +86,7 @@
       bufferPosition = 0;
    }
 
+   @Override
    public void writeByte(byte b) throws IOException {
       if (isNewChunkNeeded()) {
          newChunk();
@@ -94,14 +95,15 @@
       filePosition++;
    }
 
+   @Override
    public void writeBytes(byte[] b, int offset, int length) throws IOException {
-      int writedBytes = 0;
-      while (writedBytes < length) {
-         int pieceLength = Math.min(buffer.length - bufferPosition, length - writedBytes);
-         System.arraycopy(b, offset + writedBytes, buffer, bufferPosition, pieceLength);
+      int writtenBytes = 0;
+      while (writtenBytes < length) {
+         int pieceLength = Math.min(buffer.length - bufferPosition, length - writtenBytes);
+         System.arraycopy(b, offset + writtenBytes, buffer, bufferPosition, pieceLength);
          bufferPosition += pieceLength;
          filePosition += pieceLength;
-         writedBytes += pieceLength;
+         writtenBytes += pieceLength;
          if (isNewChunkNeeded()) {
             newChunk();
          }
@@ -112,6 +114,7 @@
       return (bufferPosition == buffer.length);
    }
 
+   @Override
    public void flush() throws IOException {
       // select right chunkNumber
       chunkNumber = getChunkNumberFromPosition(filePosition - 1, bufferSize);
@@ -130,6 +133,7 @@
       cache.endBatch(true);
    }
 
+   @Override
    public void close() throws IOException {
       flush();
       bufferPosition = 0;
@@ -141,10 +145,12 @@
       // cache.compact(); //TODO investigate about this
    }
 
+   @Override
    public long getFilePointer() {
       return filePosition;
    }
 
+   @Override
    public void seek(long pos) throws IOException {
       flush();
       if (pos > file.getSize()) {
@@ -155,6 +161,7 @@
       filePosition = (int) pos;
    }
 
+   @Override
    public long length() throws IOException {
       return file.getSize();
    }



More information about the infinispan-commits mailing list