jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1501748 - in /jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene: LuceneIndex.java LuceneIndexEditorContext.java OakDirectory.java ReadOnlyOakDirectory.java ReadWriteOakDirectory.java
Date Wed, 10 Jul 2013 12:21:45 GMT
Author: jukka
Date: Wed Jul 10 12:21:44 2013
New Revision: 1501748

URL: http://svn.apache.org/r1501748
Log:
OAK-895: Random access for Lucene index binaries

Merge the read-only and read-write Directory classes to just one for simplicity

Added:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java
  (contents, props changed)
      - copied, changed from r1501669, jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ReadOnlyOakDirectory.java
Removed:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ReadOnlyOakDirectory.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ReadWriteOakDirectory.java
Modified:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java?rev=1501748&r1=1501747&r2=1501748&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndex.java
Wed Jul 10 12:21:44 2013
@@ -165,7 +165,7 @@ public class LuceneIndex implements Full
             if (index == null) {
                 return null;
             }
-            return new ReadOnlyOakDirectory(new ReadOnlyBuilder(index));
+            return new OakDirectory(new ReadOnlyBuilder(index));
         }
 
         if (PERSISTENCE_FILE.equalsIgnoreCase(type)) {

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java?rev=1501748&r1=1501747&r2=1501748&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorContext.java
Wed Jul 10 12:21:44 2013
@@ -66,7 +66,7 @@ public class LuceneIndexEditorContext {
             throws IOException {
         String path = getString(definition, PERSISTENCE_PATH);
         if (path == null) {
-            return new ReadWriteOakDirectory(
+            return new OakDirectory(
                     definition.child(INDEX_DATA_CHILD_NAME));
         } else {
             // try {

Copied: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java
(from r1501669, jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ReadOnlyOakDirectory.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java?p2=jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java&p1=jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ReadOnlyOakDirectory.java&r1=1501669&r2=1501748&rev=1501748&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ReadOnlyOakDirectory.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java
Wed Jul 10 12:21:44 2013
@@ -22,8 +22,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 
-import javax.jcr.UnsupportedRepositoryOperationException;
-
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -34,15 +32,14 @@ import org.apache.lucene.store.IndexOutp
 import org.apache.lucene.store.NoLockFactory;
 
 /**
- * A read-only implementation of the Lucene {@link Directory} (a flat list of
- * files) that only allows reading of the Lucene index content stored in an Oak
- * repository.
+ * Implementation of the Lucene {@link Directory} (a flat list of files)
+ * based on an Oak {@link NodeBuilder}.
  */
-class ReadOnlyOakDirectory extends Directory {
+class OakDirectory extends Directory {
 
     protected final NodeBuilder directoryBuilder;
 
-    public ReadOnlyOakDirectory(NodeBuilder directoryBuilder) {
+    public OakDirectory(NodeBuilder directoryBuilder) {
         this.lockFactory = NoLockFactory.getNoLockFactory();
         this.directoryBuilder = directoryBuilder;
     }
@@ -81,9 +78,10 @@ class ReadOnlyOakDirectory extends Direc
     @Override
     public IndexOutput createOutput(String name, IOContext context)
             throws IOException {
-        throw new IOException(new UnsupportedRepositoryOperationException());
+        return new OakIndexOutput(name);
     }
 
+
     @Override
     public IndexInput openInput(String name, IOContext context)
             throws IOException {
@@ -191,4 +189,79 @@ class ReadOnlyOakDirectory extends Direc
 
     }
 
+    private final class OakIndexOutput extends IndexOutput {
+
+        private final String name;
+
+        private byte[] buffer;
+
+        private int size;
+
+        private int position;
+
+        public OakIndexOutput(String name) throws IOException {
+            this.name = name;
+            this.buffer = readFile(name);
+            this.size = buffer.length;
+            this.position = 0;
+        }
+
+        @Override
+        public long length() {
+            return size;
+        }
+
+        @Override
+        public long getFilePointer() {
+            return position;
+        }
+
+        @Override
+        public void seek(long pos) throws IOException {
+            if (pos < 0 || pos > Integer.MAX_VALUE) {
+                throw new IOException("Invalid file position: " + pos);
+            }
+            this.position = (int) pos;
+        }
+
+        @Override
+        public void writeBytes(byte[] b, int offset, int length) {
+            while (position + length > buffer.length) {
+                byte[] tmp = new byte[Math.max(4096, buffer.length * 2)];
+                System.arraycopy(buffer, 0, tmp, 0, size);
+                buffer = tmp;
+            }
+
+            System.arraycopy(b, offset, buffer, position, length);
+
+            position += length;
+            if (position > size) {
+                size = position;
+            }
+        }
+
+        @Override
+        public void writeByte(byte b) {
+            writeBytes(new byte[] { b }, 0, 1);
+        }
+
+        @Override
+        public void flush() throws IOException {
+            byte[] data = buffer;
+            if (data.length > size) {
+                data = new byte[size];
+                System.arraycopy(buffer, 0, data, 0, size);
+            }
+
+            NodeBuilder fileBuilder = directoryBuilder.child(name);
+            fileBuilder.setProperty("jcr:lastModified", System.currentTimeMillis());
+            fileBuilder.setProperty("jcr:data", data);
+        }
+
+        @Override
+        public void close() throws IOException {
+            flush();
+        }
+    }
+
 }

Propchange: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message