lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From va...@apache.org
Subject svn commit: r394214 - in /lucene/java/trunk/contrib/db/bdb-je/src: java/org/apache/lucene/store/je/File.java test/org/apache/lucene/store/je/JEStoreTest.java
Date Fri, 14 Apr 2006 22:23:34 GMT
Author: vajda
Date: Fri Apr 14 15:23:20 2006
New Revision: 394214

URL: http://svn.apache.org/viewcvs?rev=394214&view=rev
Log:
resolved JIRA issue 536

Modified:
    lucene/java/trunk/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/File.java
    lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java

Modified: lucene/java/trunk/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/File.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/File.java?rev=394214&r1=394213&r2=394214&view=diff
==============================================================================
--- lucene/java/trunk/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/File.java (original)
+++ lucene/java/trunk/contrib/db/bdb-je/src/java/org/apache/lucene/store/je/File.java Fri
Apr 14 15:23:20 2006
@@ -192,8 +192,12 @@
 
                 if (cursor.getSearchKey(cursorKey, cursorData, null) != OperationStatus.NOTFOUND)
{
                     cursor.delete();
-
-                    while (cursor.getNextDup(cursorKey, cursorData, null) != OperationStatus.NOTFOUND)
{
+                    advance: while (cursor.getNext(cursorKey, cursorData, null) != OperationStatus.NOTFOUND)
{
+                        byte[] temp = cursorKey.getData();
+                        for (int i = 0; i < bytes.length; i++)
+                            if (bytes[i] != temp[i]) {
+                                break advance;
+                            }
                         cursor.delete();
                     }
                 }

Modified: lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java?rev=394214&r1=394213&r2=394214&view=diff
==============================================================================
--- lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java
(original)
+++ lucene/java/trunk/contrib/db/bdb-je/src/test/org/apache/lucene/store/je/JEStoreTest.java
Fri Apr 14 15:23:20 2006
@@ -27,29 +27,34 @@
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.store.je.JEDirectory;
 
+import com.sleepycat.je.Cursor;
 import com.sleepycat.je.Database;
 import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DatabaseEntry;
 import com.sleepycat.je.DatabaseException;
 import com.sleepycat.je.Environment;
 import com.sleepycat.je.EnvironmentConfig;
+import com.sleepycat.je.LockMode;
+import com.sleepycat.je.OperationStatus;
 import com.sleepycat.je.Transaction;
 
 /**
  * Tests {@link JEDirectory}.
- *
+ * 
  * Adapted from Andi Vajda's org.apache.lucene.db.DbStoreTest.
+ * 
  * @author Aaron Donovan
  */
 public class JEStoreTest extends TestCase {
     protected File dbHome = new File("index");
+
     protected Environment env;
+
     protected Database index, blocks;
-    
-    public void setUp()
-        throws Exception
-    {
+
+    public void setUp() throws Exception {
+
         if (!dbHome.exists())
             dbHome.mkdir();
         else {
@@ -79,8 +84,7 @@
             index = env.openDatabase(txn, "__index__", dbConfig);
             blocks = env.openDatabase(txn, "__blocks__", dbConfig);
         } catch (DatabaseException e) {
-            if (txn != null)
-            {
+            if (txn != null) {
                 txn.abort();
                 txn = null;
             }
@@ -94,9 +98,8 @@
         }
     }
 
-    public void tearDown()
-        throws Exception
-    {
+    public void tearDown() throws Exception {
+
         if (index != null)
             index.close();
         if (blocks != null)
@@ -105,9 +108,7 @@
             env.close();
     }
 
-    public void testBytes()
-        throws Exception
-    {
+    public void tesBytes() throws Exception {
         final int count = 250;
         final int LENGTH_MASK = 0xffff;
 
@@ -115,7 +116,7 @@
         int totalLength = 0;
         int duration;
         Date end;
-    
+
         Date veryStart = new Date();
         Date start = new Date();
         Transaction txn = null;
@@ -135,10 +136,10 @@
                 totalLength += length;
 
                 for (int j = 0; j < length; j++) {
-                    byte b = (byte)(gen.nextInt() & 0x7F);
+                    byte b = (byte) (gen.nextInt() & 0x7F);
                     file.writeByte(b);
                 }
-      
+
                 file.close();
             }
         } catch (IOException e) {
@@ -146,8 +147,7 @@
             txn = null;
             throw e;
         } catch (DatabaseException e) {
-            if (txn != null)
-            {
+            if (txn != null) {
                 txn.abort();
                 txn = null;
             }
@@ -183,7 +183,7 @@
                     throw new Exception("length incorrect");
 
                 for (int j = 0; j < length; j++) {
-                    byte b = (byte)(gen.nextInt() & 0x7F);
+                    byte b = (byte) (gen.nextInt() & 0x7F);
 
                     if (file.readByte() != b)
                         throw new Exception("contents incorrect");
@@ -196,8 +196,7 @@
             txn = null;
             throw e;
         } catch (DatabaseException e) {
-            if (txn != null)
-            {
+            if (txn != null) {
                 txn.abort();
                 txn = null;
             }
@@ -233,8 +232,202 @@
             txn = null;
             throw e;
         } catch (DatabaseException e) {
+            if (txn != null) {
+                txn.abort();
+                txn = null;
+            }
+            throw e;
+        } finally {
+            if (txn != null)
+                txn.commit();
+
+            store.close();
+        }
+
+        end = new Date();
+
+        System.out.print(end.getTime() - start.getTime());
+        System.out.println(" total milliseconds to delete");
+
+        System.out.print(end.getTime() - veryStart.getTime());
+        System.out.println(" total milliseconds");
+    }
+
+    public void testDelete() throws Exception {
+        final int count = 250;
+        final int LENGTH_MASK = 0xffff;
+
+        Random gen = new Random(1251971);
+        int totalLength = 0;
+        int duration;
+        Date end;
+
+        Date veryStart = new Date();
+        Date start = new Date();
+        Transaction txn = null;
+        Directory store = null;
+
+        System.out.println("Writing files byte by byte");
+
+        try {
+            txn = env.beginTransaction(null, null);
+            store = new JEDirectory(txn, index, blocks);
+
+            for (int i = 0; i < count; i++) {
+                String name = i + ".dat";
+                int length = gen.nextInt() & LENGTH_MASK;
+                IndexOutput file = store.createOutput(name);
+
+                totalLength += length;
+
+                for (int j = 0; j < length; j++) {
+                    byte b = (byte) (gen.nextInt() & 0x7F);
+                    file.writeByte(b);
+                }
+
+                file.close();
+            }
+        } catch (IOException e) {
+            txn.abort();
+            txn = null;
+            throw e;
+        } catch (DatabaseException e) {
+            if (txn != null) {
+                txn.abort();
+                txn = null;
+            }
+            throw e;
+        } finally {
+            if (txn != null)
+                txn.commit();
+
+            store.close();
+        }
+
+        end = new Date();
+
+        duration = (int) (end.getTime() - start.getTime());
+        System.out.print(duration);
+        System.out.print(" total milliseconds to read, ");
+        System.out.print(totalLength / duration);
+        System.out.println(" kb/s");
+
+        try {
+            txn = env.beginTransaction(null, null);
+            store = new JEDirectory(txn, index, blocks);
+
+            gen = new Random(1251971);
+            start = new Date();
+
+            for (int i = 0; i < count; i++) {
+                if (i % 2 == 0) {
+                    String name = i + ".dat";
+                    store.deleteFile(name);
+                }
+            }
+        } catch (IOException e) {
+            txn.abort();
+            txn = null;
+            throw e;
+        } catch (DatabaseException e) {
+            if (txn != null) {
+                txn.abort();
+                txn = null;
+            }
+            throw e;
+        } finally {
+            if (txn != null)
+                txn.commit();
+
+            store.close();
+        }
+
+        end = new Date();
+
+        System.out.print(end.getTime() - start.getTime());
+        System.out.println(" total milliseconds to delete even files");
+
+        duration = (int) (end.getTime() - start.getTime());
+        System.out.print(duration);
+        System.out.print(" total milliseconds to create, ");
+        System.out.print(totalLength / duration);
+        System.out.println(" kb/s");
+
+        try {
+            txn = env.beginTransaction(null, null);
+            store = new JEDirectory(txn, index, blocks);
+
+            gen = new Random(1251971);
+            start = new Date();
+
+            for (int i = 0; i < count; i++) {
+                int length = gen.nextInt() & LENGTH_MASK;
+
+                if (i % 2 != 0) {
+                    String name = i + ".dat";
+                    IndexInput file = store.openInput(name);
+                    if (file.length() != length)
+                        throw new Exception("length incorrect");
+
+                    for (int j = 0; j < length; j++) {
+                        byte b = (byte) (gen.nextInt() & 0x7F);
+
+                        if (file.readByte() != b)
+                            throw new Exception("contents incorrect");
+                    }
+
+                    file.close();
+                } else {
+                    for (int j = 0; j < length; j++) {
+                        gen.nextInt();
+                    }
+                }
+            }
+        } catch (IOException e) {
+            txn.abort();
+            txn = null;
+            throw e;
+        } catch (DatabaseException e) {
+            if (txn != null) {
+                txn.abort();
+                txn = null;
+            }
+            throw e;
+        } finally {
             if (txn != null)
-            {
+                txn.commit();
+
+            store.close();
+        }
+
+        end = new Date();
+
+        duration = (int) (end.getTime() - start.getTime());
+        System.out.print(duration);
+        System.out.print(" total milliseconds to read, ");
+        System.out.print(totalLength / duration);
+        System.out.println(" kb/s");
+
+        try {
+            txn = env.beginTransaction(null, null);
+            store = new JEDirectory(txn, index, blocks);
+
+            gen = new Random(1251971);
+            start = new Date();
+
+            for (int i = 0; i < count; i++) {
+                if (i % 2 != 0) {
+                    String name = i + ".dat";
+                    store.deleteFile(name);
+                }
+            }
+
+        } catch (IOException e) {
+            txn.abort();
+            txn = null;
+            throw e;
+        } catch (DatabaseException e) {
+            if (txn != null) {
                 txn.abort();
                 txn = null;
             }
@@ -253,11 +446,43 @@
 
         System.out.print(end.getTime() - veryStart.getTime());
         System.out.println(" total milliseconds");
+
+        Cursor cursor = null;
+        try {
+            cursor = index.openCursor(null, null);
+
+            DatabaseEntry foundKey = new DatabaseEntry();
+            DatabaseEntry foundData = new DatabaseEntry();
+
+            if (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS)
{
+                fail("index database is not empty");
+            }
+        } catch (DatabaseException e) {
+            throw e;
+        } finally {
+            if (cursor != null)
+                cursor.close();
+        }
+
+        cursor = null;
+        try {
+            cursor = blocks.openCursor(null, null);
+
+            DatabaseEntry foundKey = new DatabaseEntry();
+            DatabaseEntry foundData = new DatabaseEntry();
+
+            if (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS)
{
+                fail("blocks database is not empty");
+            }
+        } catch (DatabaseException e) {
+            throw e;
+        } finally {
+            if (cursor != null)
+                cursor.close();
+        }
     }
 
-    public void testArrays()
-        throws Exception
-    {
+    public void tesArrays() throws Exception {
         final int count = 250;
         final int LENGTH_MASK = 0xffff;
 
@@ -265,7 +490,7 @@
         int totalLength = 0;
         int duration;
         Date end;
-    
+
         Date veryStart = new Date();
         Date start = new Date();
         Transaction txn = null;
@@ -286,7 +511,7 @@
                 totalLength += length;
                 gen.nextBytes(data);
                 file.writeBytes(data, length);
-      
+
                 file.close();
             }
         } catch (IOException e) {
@@ -294,8 +519,7 @@
             txn = null;
             throw e;
         } catch (DatabaseException e) {
-            if (txn != null)
-            {
+            if (txn != null) {
                 txn.abort();
                 txn = null;
             }
@@ -326,7 +550,7 @@
                 String name = i + ".dat";
                 int length = gen.nextInt() & LENGTH_MASK;
                 IndexInput file = store.openInput(name);
-                
+
                 if (file.length() != length)
                     throw new Exception("length incorrect");
 
@@ -345,8 +569,7 @@
             txn = null;
             throw e;
         } catch (DatabaseException e) {
-            if (txn != null)
-            {
+            if (txn != null) {
                 txn.abort();
                 txn = null;
             }
@@ -372,18 +595,17 @@
 
             gen = new Random(1251971);
             start = new Date();
-
             for (int i = 0; i < count; i++) {
                 String name = i + ".dat";
                 store.deleteFile(name);
             }
+
         } catch (IOException e) {
             txn.abort();
             txn = null;
             throw e;
         } catch (DatabaseException e) {
-            if (txn != null)
-            {
+            if (txn != null) {
                 txn.abort();
                 txn = null;
             }
@@ -404,4 +626,3 @@
         System.out.println(" total milliseconds");
     }
 }
-



Mime
View raw message