lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r778490 [2/2] - in /lucene/java/trunk: ./ docs/ src/java/org/apache/lucene/index/ src/java/org/apache/lucene/store/ src/java/org/apache/lucene/util/ src/site/src/documentation/content/xdocs/ src/test/org/apache/lucene/index/
Date Mon, 25 May 2009 20:07:25 GMT
Modified: lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/MultiReader.java Mon May 25 20:07:24
2009
@@ -360,7 +360,7 @@
     doCommit(null);
   }
   
-  protected void doCommit(String commitUserData) throws IOException {
+  protected void doCommit(Map commitUserData) throws IOException {
     for (int i = 0; i < subReaders.length; i++)
       subReaders[i].commit(commitUserData);
   }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/ParallelReader.java Mon May 25 20:07:24
2009
@@ -441,7 +441,7 @@
     doCommit(null);
   }
 
-  protected void doCommit(String commitUserData) throws IOException {
+  protected void doCommit(Map commitUserData) throws IOException {
     for (int i = 0; i < readers.size(); i++)
       ((IndexReader)readers.get(i)).commit(commitUserData);
   }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfo.java Mon May 25 20:07:24
2009
@@ -23,7 +23,10 @@
 import org.apache.lucene.util.BitVector;
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 import java.util.ArrayList;
+import java.util.Collections;
 
 final class SegmentInfo {
 
@@ -79,6 +82,8 @@
 
   private boolean hasProx;                        // True if this segment has any fields
with omitTermFreqAndPositions==false
 
+  private Map diagnostics;
+
   public String toString() {
     return "si: "+dir.toString()+" "+name+" docCount: "+docCount+" delCount: "+delCount+"
delFileName: "+getDelFileName();
   }
@@ -139,6 +144,16 @@
     delCount = src.delCount;
   }
 
+  // must be Map<String, String>
+  void setDiagnostics(Map diagnostics) {
+    this.diagnostics = diagnostics;
+  }
+
+  // returns Map<String, String>
+  Map getDiagnostics() {
+    return diagnostics;
+  }
+
   /**
    * Construct a new SegmentInfo instance by reading a
    * previously saved SegmentInfo from input.
@@ -192,6 +207,12 @@
         hasProx = input.readByte() == 1;
       else
         hasProx = true;
+
+      if (format <= SegmentInfos.FORMAT_DIAGNOSTICS) {
+        diagnostics = input.readStringStringMap();
+      } else {
+        diagnostics = Collections.EMPTY_MAP;
+      }
     } else {
       delGen = CHECK_DIR;
       normGen = null;
@@ -203,6 +224,7 @@
       docStoreSegment = null;
       delCount = -1;
       hasProx = true;
+      diagnostics = Collections.EMPTY_MAP;
     }
   }
   
@@ -290,8 +312,10 @@
     si.isCompoundFile = isCompoundFile;
     si.delGen = delGen;
     si.delCount = delCount;
+    si.hasProx = hasProx;
     si.preLockless = preLockless;
     si.hasSingleNormFile = hasSingleNormFile;
+    si.diagnostics = new HashMap(diagnostics);
     if (normGen != null) {
       si.normGen = (long[]) normGen.clone();
     }
@@ -527,6 +551,7 @@
     output.writeByte(isCompoundFile);
     output.writeInt(delCount);
     output.writeByte((byte) (hasProx ? 1:0));
+    output.writeStringStringMap(diagnostics);
   }
 
   void setHasProx(boolean hasProx) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Mon May 25 20:07:24
2009
@@ -31,7 +31,10 @@
 import java.io.PrintStream;
 import java.util.Vector;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Map;
 
 final class SegmentInfos extends Vector {
 
@@ -76,8 +79,12 @@
   /** This format adds optional commit userData (String) storage. */
   public static final int FORMAT_USER_DATA = -8;
 
+  /** This format adds optional per-segment String
+   *  dianostics storage, and switches userData to Map */
+  public static final int FORMAT_DIAGNOSTICS = -9;
+
   /* This must always point to the most recent file format. */
-  static final int CURRENT_FORMAT = FORMAT_USER_DATA;
+  static final int CURRENT_FORMAT = FORMAT_DIAGNOSTICS;
   
   public int counter = 0;    // used to name new segments
   /**
@@ -91,7 +98,7 @@
                                    // or wrote; this is normally the same as generation except
if
                                    // there was an IOException that had interrupted a commit
 
-  private String userData;                        // Opaque String that user can specify
during IndexWriter.commit
+  private Map userData = Collections.EMPTY_MAP;       // Opaque Map<String, String>
that user can specify during IndexWriter.commit
 
   /**
    * If non-null, information about loading segments_N files
@@ -252,10 +259,16 @@
       }
 
       if (format <= FORMAT_USER_DATA) {
-        if (0 == input.readByte())
-          userData = null;
-        else
-          userData = input.readString();
+        if (format <= FORMAT_DIAGNOSTICS) {
+          userData = input.readStringStringMap();
+        } else {
+          userData = Collections.EMPTY_MAP;
+          if (0 != input.readByte()) {
+            userData.put("userData", input.readString());
+          }
+        }
+      } else {
+        userData = Collections.EMPTY_MAP;
       }
 
       if (format <= FORMAT_CHECKSUM) {
@@ -323,12 +336,7 @@
       for (int i = 0; i < size(); i++) {
         info(i).write(segnOutput);
       }
-      if (userData == null)
-        segnOutput.writeByte((byte) 0);
-      else {
-        segnOutput.writeByte((byte) 1);
-        segnOutput.writeString(userData);
-      }
+      segnOutput.writeStringStringMap(userData);
       segnOutput.prepareCommit();
       success = true;
       pendingSegnOutput = segnOutput;
@@ -362,6 +370,7 @@
     for(int i=0;i<sis.size();i++) {
       sis.set(i, sis.info(i).clone());
     }
+    sis.userData = new HashMap(userData);
     return sis;
   }
 
@@ -422,7 +431,7 @@
    * @throws CorruptIndexException if the index is corrupt
    * @throws IOException if there is a low-level IO error
    */
-  public static String readCurrentUserData(Directory directory)
+  public static Map readCurrentUserData(Directory directory)
     throws CorruptIndexException, IOException {
     SegmentInfos sis = new SegmentInfos();
     sis.read(directory);
@@ -899,12 +908,16 @@
     return buffer.toString();
   }
 
-  public String getUserData() {
+  public Map getUserData() {
     return userData;
   }
 
-  public void setUserData(String data) {
-    userData = data;
+  public void setUserData(Map data) {
+    if (data == null) {
+      userData = Collections.EMPTY_MAP;
+    } else {
+      userData = data;
+    }
   }
 
   /** Replaces all segments in this instance, but keeps

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java Mon May
25 20:07:24 2009
@@ -20,6 +20,7 @@
 import java.util.Collection;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Map;
 import java.io.IOException;
 import org.apache.lucene.store.Directory;
 
@@ -118,7 +119,7 @@
     public long getGeneration() {
       return cp.getGeneration();
     }
-    public String getUserData() throws IOException {
+    public Map getUserData() throws IOException {
       return cp.getUserData();
     }
   }

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/IndexInput.java Mon May 25 20:07:24
2009
@@ -18,6 +18,8 @@
  */
 
 import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
 
 /** Abstract base class for input from a file in a {@link Directory}.  A
  * random-access input stream.  Used for all Lucene index input operations.
@@ -226,4 +228,16 @@
     return clone;
   }
 
+  // returns Map<String, String>
+  public Map readStringStringMap() throws IOException {
+    final Map map = new HashMap();
+    final int count = readInt();
+    for(int i=0;i<count;i++) {
+      final String key = readString();
+      final String val = readString();
+      map.put(key, val);
+    }
+
+    return map;
+  }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/IndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/IndexOutput.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/IndexOutput.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/IndexOutput.java Mon May 25 20:07:24
2009
@@ -18,6 +18,8 @@
  */
 
 import java.io.IOException;
+import java.util.Map;
+import java.util.Iterator;
 import org.apache.lucene.util.UnicodeUtil;
 
 /** Abstract base class for output to a file in a Directory.  A random-access
@@ -206,4 +208,19 @@
    * @param length file length
    */
   public void setLength(long length) throws IOException {};
+
+  // map must be Map<String, String>
+  public void writeStringStringMap(Map map) throws IOException {
+    if (map == null) {
+      writeInt(0);
+    } else {
+      writeInt(map.size());
+      final Iterator it = map.entrySet().iterator();
+      while(it.hasNext()) {
+        Map.Entry entry = (Map.Entry) it.next();
+        writeString((String) entry.getKey());
+        writeString((String) entry.getValue());
+      }
+    }
+  }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java Mon May 25 20:07:24 2009
@@ -17,6 +17,11 @@
  * limitations under the License.
  */
 
+import java.util.jar.Manifest;
+import java.util.jar.Attributes;
+import java.io.InputStream;
+import java.net.URL;
+
 /**
  * Some useful constants.
  *
@@ -44,4 +49,36 @@
   public static final boolean WINDOWS = OS_NAME.startsWith("Windows");
   /** True iff running on SunOS. */
   public static final boolean SUN_OS = OS_NAME.startsWith("SunOS");
+
+  public static final String OS_ARCH = System.getProperty("os.arch");
+  public static final String OS_VERSION = System.getProperty("os.version");
+  public static final String JAVA_VENDOR = System.getProperty("java.vendor");
+
+  public static final String LUCENE_VERSION;
+
+  public static final String LUCENE_MAIN_VERSION = "2.9-dev";
+
+  static {
+    String v = LUCENE_MAIN_VERSION;
+    try {
+      // TODO: this should have worked, but doesn't seem to?
+      // Package.getPackage("org.apache.lucene.util").getImplementationVersion();
+      String classContainer = Constants.class.getProtectionDomain().getCodeSource().getLocation().toString();
+      URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF");
+      InputStream s = manifestUrl.openStream();
+      try {
+        Manifest manifest = new Manifest(s);
+        Attributes attr = manifest.getMainAttributes();
+        v = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
+      } finally {
+        if (s != null) {
+          s.close();
+        }
+      }
+    } catch (Throwable t) {
+      // ignore
+    }
+
+    LUCENE_VERSION = v;
+  }
 }

Modified: lucene/java/trunk/src/site/src/documentation/content/xdocs/fileformats.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/site/src/documentation/content/xdocs/fileformats.xml?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/site/src/documentation/content/xdocs/fileformats.xml (original)
+++ lucene/java/trunk/src/site/src/documentation/content/xdocs/fileformats.xml Mon May 25
20:07:24 2009
@@ -757,6 +757,21 @@
                 </p>
 
             </section>
+        </section>
+
+        <section id="Compound Types"><title>Compound Types</title>
+            <section id="String"><title>Map&lt;String,String&gt;</title>
+
+                <p>
+		    In a couple places Lucene stores a Map
+                    String-&gt;String.
+                </p>
+
+                <p>
+  		    Map&lt;String,String&gt; --&gt; Count&lt;String,String&gt;<sup>Count</sup>
+                </p>
+
+            </section>
 
         </section>
 
@@ -834,7 +849,7 @@
                     <b>2.9 and above:</b>
                     Segments --&gt; Format, Version, NameCounter, SegCount, &lt;SegName,
SegSize, DelGen, DocStoreOffset, [DocStoreSegment, DocStoreIsCompoundFile], HasSingleNormFile,
NumField,
                     NormGen<sup>NumField</sup>,
-                    IsCompoundFile, DeletionCount, HasProx&gt;<sup>SegCount</sup>,
HasUserData, CommitUserData?, Checksum
+                    IsCompoundFile, DeletionCount, HasProx, Diagnostics&gt;<sup>SegCount</sup>,
CommitUserData, Checksum
                 </p>
 
                 <p>
@@ -842,21 +857,29 @@
                     DocStoreOffset, DeletionCount --&gt; Int32
                 </p>
 
-                <p>
+               <p>
                     Version, DelGen, NormGen, Checksum --&gt; Int64
                 </p>
 
                 <p>
-                    SegName, DocStoreSegment, CommitUserData --&gt; String
+                   SegName, DocStoreSegment --&gt; String
                 </p>
 
+		<p>
+		   Diagnostics --&gt; Map&lt;String,String&gt;
+		</p>
+
                 <p>
                     IsCompoundFile, HasSingleNormFile,
-                    DocStoreIsCompoundFile, HasProx, HasUserData --&gt; Int8
+                    DocStoreIsCompoundFile, HasProx --&gt; Int8
+                </p>
+
+		<p>
+		    CommitUserData --&gt; Map&lt;String,String&gt;
                 </p>
 
                 <p>
-                    Format is -1 as of Lucene 1.4, -3 (SegmentInfos.FORMAT_SINGLE_NORM_FILE)
as of Lucene 2.1 and 2.2, -4 (SegmentInfos.FORMAT_SHARED_DOC_STORE) as of Lucene 2.3, -7 (SegmentInfos.FORMAT_HAS_PROX)
as of Lucene 2.4, and -8 (SegmentInfos.FORMAT_USER_DATA) as of Lucene 2.9.
+                    Format is -1 as of Lucene 1.4, -3 (SegmentInfos.FORMAT_SINGLE_NORM_FILE)
as of Lucene 2.1 and 2.2, -4 (SegmentInfos.FORMAT_SHARED_DOC_STORE) as of Lucene 2.3, -7 (SegmentInfos.FORMAT_HAS_PROX)
as of Lucene 2.4, and -9 (SegmentInfos.FORMAT_DIAGNOSTICS) as of Lucene 2.9.
                 </p>
 
                 <p>
@@ -958,10 +981,17 @@
 		</p>
 
 		<p>
-		    If HasUserData is 1, then the string
-		    CommitUserData is non-null and is stored.  This is
-		    a string previously passed to IndexWriter's commit
-		    or prepareCommit method.
+		    CommitUserData stores an optional user-supplied
+		    opaque Map&lt;String,String&gt; that was passed to
+		    IndexWriter's commit or prepareCommit, or
+		    IndexReader's flush methods.
+                </p>
+		<p>
+		    The Diagnostics Map is privately written by
+		    IndexWriter, as a debugging aid, for each segment
+		    it creates.  It includes metadata like the current
+		    Lucene version, OS, Java version, why the segment
+		    was created (merge, flush, addIndexes), etc.
                 </p>
 
             </section>

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestCheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestCheckIndex.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestCheckIndex.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestCheckIndex.java Mon May 25 20:07:24
2009
@@ -28,6 +28,7 @@
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
+import org.apache.lucene.util.Constants;
 
 public class TestCheckIndex extends LuceneTestCase {
 
@@ -55,11 +56,22 @@
       System.out.println(bos.toString());
       fail();
     }
-    assertTrue(((CheckIndex.Status.SegmentInfoStatus) indexStatus.segmentInfos.get(0)).openReaderPassed);
+    
+    final CheckIndex.Status.SegmentInfoStatus seg = (CheckIndex.Status.SegmentInfoStatus)
indexStatus.segmentInfos.get(0);
+    assertTrue(seg.openReaderPassed);
 
+    assertNotNull(seg.diagnostics);
+    assertTrue(seg.diagnostics.size() > 0);
     final List onlySegments = new ArrayList();
     onlySegments.add("_0");
     
     assertTrue(checker.checkIndex(onlySegments).clean == true);
   }
+
+  public void testLuceneConstantVersion() throws IOException {
+    // common-build.xml sets lucene.version
+    final String version = System.getProperty("lucene.version");
+    assertEquals(version, Constants.LUCENE_MAIN_VERSION);
+    assertTrue(Constants.LUCENE_VERSION.startsWith(version));
+  }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Mon May 25 20:07:24
2009
@@ -26,6 +26,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.HashMap;
 import java.util.Set;
 
 import junit.framework.TestSuite;
@@ -70,8 +71,9 @@
     
     public void testCommitUserData() throws Exception {
       RAMDirectory d = new MockRAMDirectory();
-      
-      String cmpCommitUserData = "foo fighters";
+
+      Map commitUserData = new HashMap();
+      commitUserData.put("foo", "fighters");
       
       // set up writer
       IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
@@ -82,14 +84,14 @@
       
       IndexReader r = IndexReader.open(d);
       r.deleteDocument(5);
-      r.flush(cmpCommitUserData);
+      r.flush(commitUserData);
       r.close();
       
       SegmentInfos sis = new SegmentInfos();
       sis.read(d);
       IndexReader r2 = IndexReader.open(d);
       IndexCommit c = r.getIndexCommit();
-      assertEquals(c.getUserData(), cmpCommitUserData);
+      assertEquals(c.getUserData(), commitUserData);
 
       assertEquals(sis.getCurrentSegmentFileName(), c.getSegmentsFileName());
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReaderReopen.java Mon May
25 20:07:24 2009
@@ -25,6 +25,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Random;
+import java.util.Map;
+import java.util.HashMap;
 import java.util.Set;
 
 import org.apache.lucene.analysis.KeywordAnalyzer;
@@ -1233,11 +1235,15 @@
       Document doc = new Document();
       doc.add(new Field("id", ""+i, Field.Store.NO, Field.Index.NOT_ANALYZED));
       writer.addDocument(doc);
-      writer.commit(""+i);
+      Map data = new HashMap();
+      data.put("index", i+"");
+      writer.commit(data);
     }
     for(int i=0;i<4;i++) {
       writer.deleteDocuments(new Term("id", ""+i));
-      writer.commit(""+(4+i));
+      Map data = new HashMap();
+      data.put("index", (4+i)+"");
+      writer.commit(data);
     }
     writer.close();
 
@@ -1259,13 +1265,13 @@
         // expected
       }
 
-      final String s = commit.getUserData();
+      final Map s = commit.getUserData();
       final int v;
-      if (s == null) {
+      if (s.size() == 0) {
         // First commit created by IW
         v = -1;
       } else {
-        v = Integer.parseInt(s);
+        v = Integer.parseInt((String) s.get("index"));
       }
       if (v < 4) {
         assertEquals(1+v, r2.numDocs());

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Mon May 25 20:07:24
2009
@@ -26,6 +26,8 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
+import java.util.Map;
+import java.util.HashMap;
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.SinkTokenizer;
@@ -4096,31 +4098,33 @@
       addDoc(w);
     w.close();
 
-    assertEquals(null, IndexReader.getCommitUserData(dir));
+    assertEquals(0, IndexReader.getCommitUserData(dir).size());
 
     IndexReader r = IndexReader.open(dir);
-    // commit(String) never called for this index
-    assertEquals(null, r.getCommitUserData());
+    // commit(Map) never called for this index
+    assertEquals(0, r.getCommitUserData().size());
     r.close();
       
     w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
     w.setMaxBufferedDocs(2);
     for(int j=0;j<17;j++)
       addDoc(w);
-    w.commit("test1");
+    Map data = new HashMap();
+    data.put("label", "test1");
+    w.commit(data);
     w.close();
       
-    assertEquals("test1", IndexReader.getCommitUserData(dir));
+    assertEquals("test1", IndexReader.getCommitUserData(dir).get("label"));
 
     r = IndexReader.open(dir);
-    assertEquals("test1", r.getCommitUserData());
+    assertEquals("test1", r.getCommitUserData().get("label"));
     r.close();
 
     w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
     w.optimize();
     w.close();
 
-    assertEquals("test1", IndexReader.getCommitUserData(dir));
+    assertEquals("test1", IndexReader.getCommitUserData(dir).get("label"));
       
     dir.close();
   }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactionRollback.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactionRollback.java?rev=778490&r1=778489&r2=778490&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactionRollback.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestTransactionRollback.java Mon May
25 20:07:24 2009
@@ -23,6 +23,8 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 
 import junit.framework.TestCase;
 
@@ -55,9 +57,9 @@
     Collection commits = IndexReader.listCommits(dir);
     for (Iterator iterator = commits.iterator(); iterator.hasNext();) {
       IndexCommit commit = (IndexCommit) iterator.next();
-      String ud=commit.getUserData();
-      if (ud != null)
-        if (ud.endsWith(ids))
+      Map ud=commit.getUserData();
+      if (ud.size() > 0)
+        if (((String) ud.get("index")).endsWith(ids))
           last=commit;
     }
 
@@ -66,7 +68,9 @@
 		
     IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(),
                                     new RollbackDeletionPolicy(id), MaxFieldLength.UNLIMITED,
last);
-    w.commit("Rolled back to 1-"+id);
+    Map data = new HashMap();
+    data.put("index", "Rolled back to 1-"+id);
+    w.commit(data);
     w.close();
   }
 
@@ -101,6 +105,7 @@
     assertEquals("Should have 0 docs remaining ", 0 ,expecteds.cardinality());
   }
 
+  /*
   private void showAvailableCommitPoints() throws Exception {
     Collection commits = IndexReader.listCommits(dir);
     for (Iterator iterator = commits.iterator(); iterator.hasNext();) {
@@ -114,6 +119,7 @@
       System.out.println();
     }
   }
+  */
 
   protected void setUp() throws Exception {
     dir = new MockRAMDirectory();
@@ -126,15 +132,15 @@
     //Build index, of records 1 to 100, committing after each batch of 10
     IndexDeletionPolicy sdp=new KeepAllDeletionPolicy();
     IndexWriter w=new IndexWriter(dir,new WhitespaceAnalyzer(),sdp,MaxFieldLength.UNLIMITED);
-    int firstRecordIdInThisTransaction=1;
     for(int currentRecordId=1;currentRecordId<=100;currentRecordId++) {
       Document doc=new Document();
       doc.add(new Field(FIELD_RECORD_ID,""+currentRecordId,Field.Store.YES,Field.Index.ANALYZED));
       w.addDocument(doc);
 			
       if (currentRecordId%10 == 0) {
-        String userData="records 1-"+currentRecordId;
-        w.commit(userData);
+        Map data = new HashMap();
+        data.put("index", "records 1-"+currentRecordId);
+        w.commit(data);
       }
     }
 
@@ -155,12 +161,13 @@
     public void onInit(List commits) throws IOException {
       for (Iterator iterator = commits.iterator(); iterator.hasNext();) {
         IndexCommit commit = (IndexCommit) iterator.next();
-        String userData=commit.getUserData();
-        if (userData != null) {
+        Map userData=commit.getUserData();
+        if (userData.size() > 0) {
           // Label for a commit point is "Records 1-30"
           // This code reads the last id ("30" in this example) and deletes it
           // if it is after the desired rollback point
-          String lastVal = userData.substring(userData.lastIndexOf("-")+1);
+          String x = (String) userData.get("index");
+          String lastVal = x.substring(x.lastIndexOf("-")+1);
           int last = Integer.parseInt(lastVal);
           if (last>rollbackPoint) {
             /*



Mime
View raw message