Apache Solr open-source search software
LUCENE-6085: add back SI.attributes
Robert Muir972ae5392ad4
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 3992b2c96fa..491b62c41e1 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -236,6 +236,10 @@ API Changes* LUCENE-6087: Allow passing custom DirectoryReader to SearcherManager(Mike McCandless)+* LUCENE-6085: Undeprecate SegmentInfo attributes, but add safety so they+ won't be trappy if codec tries to use them during docvalues updates.+ (Robert Muir)+Bug Fixes* LUCENE-5650: Enforce read-only access to any path outside the temporarydiff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.javaindex 3c35d68cf30..113ed49e5b3 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java@@ -21,6 +21,7 @@ import java.io.IOException;import java.nio.charset.StandardCharsets;import java.text.ParseException;import java.util.Arrays;+import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.Map;@@ -52,6 +53,9 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {final static BytesRef SI_NUM_DIAG = new BytesRef(" diagnostics ");final static BytesRef SI_DIAG_KEY = new BytesRef(" key ");final static BytesRef SI_DIAG_VALUE = new BytesRef(" value ");+ final static BytesRef SI_NUM_ATT = new BytesRef(" attributes ");+ final static BytesRef SI_ATT_KEY = new BytesRef(" key ");+ final static BytesRef SI_ATT_VALUE = new BytesRef(" value ");final static BytesRef SI_NUM_FILES = new BytesRef(" files ");final static BytesRef SI_FILE = new BytesRef(" file ");final static BytesRef SI_ID = new BytesRef(" id ");@@ -96,6 +100,22 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {diagnostics.put(key, value);}+ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_NUM_ATT);+ int numAtt = Integer.parseInt(readString(SI_NUM_ATT.length, scratch));+ Map<String,String> attributes = new HashMap<>(numAtt);++ for (int i = 0; i < numAtt; i++) {+ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_ATT_KEY);+ String key = readString(SI_ATT_KEY.length, scratch);++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_ATT_VALUE);+ String value = readString(SI_ATT_VALUE.length, scratch);+ attributes.put(key, value);+ }+SimpleTextUtil.readLine(input, scratch);assert StringHelper.startsWith(scratch.get(), SI_NUM_FILES);int numFiles = Integer.parseInt(readString(SI_NUM_FILES.length, scratch));@@ -120,7 +140,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {SimpleTextUtil.checkFooter(input);SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,- isCompoundFile, null, diagnostics, id);+ isCompoundFile, null, diagnostics, id, Collections.unmodifiableMap(attributes));info.setFiles(files);return info;}@@ -169,6 +189,21 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {}}+ Map<String,String> attributes = si.getAttributes();+ SimpleTextUtil.write(output, SI_NUM_ATT);+ SimpleTextUtil.write(output, Integer.toString(attributes.size()), scratch);+ SimpleTextUtil.writeNewline(output);++ for (Map.Entry<String,String> attEntry : attributes.entrySet()) {+ SimpleTextUtil.write(output, SI_ATT_KEY);+ SimpleTextUtil.write(output, attEntry.getKey(), scratch);+ SimpleTextUtil.writeNewline(output);++ SimpleTextUtil.write(output, SI_ATT_VALUE);+ SimpleTextUtil.write(output, attEntry.getValue(), scratch);+ SimpleTextUtil.writeNewline(output);+ }+Set<String> files = si.files();int numFiles = files == null ? 0 : files.size();SimpleTextUtil.write(output, SI_NUM_FILES);diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.javaindex 8a665b619ad..6b673fb3b2b 100755--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java@@ -18,6 +18,7 @@ package org.apache.lucene.codecs.lucene50;*/import java.io.IOException;+import java.util.Collections;import java.util.Map;import java.util.Set;@@ -33,7 +34,6 @@ import org.apache.lucene.store.DataOutput; // javadocsimport org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexOutput;-import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.Version;/**@@ -41,7 +41,7 @@ import org.apache.lucene.util.Version;* <p>* Files:* <ul>- * <li><tt>.si</tt>: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Files, Footer+ * <li><tt>.si</tt>: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Files, Attributes, Footer* </ul>* </p>* Data types:@@ -51,7 +51,7 @@ import org.apache.lucene.util.Version;* <li>SegSize --> {@link DataOutput#writeInt Int32}</li>* <li>SegVersion --> {@link DataOutput#writeString String}</li>* <li>Files --> {@link DataOutput#writeStringSet Set<String>}</li>- * <li>Diagnostics --> {@link DataOutput#writeStringStringMap Map<String,String>}</li>+ * <li>Diagnostics,Attributes --> {@link DataOutput#writeStringStringMap Map<String,String>}</li>* <li>IsCompoundFile --> {@link DataOutput#writeByte Int8}</li>* <li>Footer --> {@link CodecUtil#writeFooter CodecFooter}</li>* </ul>@@ -101,8 +101,9 @@ public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;final Map<String,String> diagnostics = input.readStringStringMap();final Set<String> files = input.readStringSet();+ final Map<String,String> attributes = input.readStringStringMap();- si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID);+ si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID, Collections.unmodifiableMap(attributes));si.setFiles(files);} catch (Throwable exception) {priorE = exception;@@ -144,6 +145,7 @@ public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {}}output.writeStringSet(files);+ output.writeStringStringMap(si.getAttributes());CodecUtil.writeFooter(output);}}diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.javaindex 21a0840844d..79fda8a9d30 100644--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java@@ -19,6 +19,7 @@ package org.apache.lucene.index;import java.io.IOException;import java.text.NumberFormat;+import java.util.HashMap;import java.util.HashSet;import java.util.Locale;import java.util.Set;@@ -178,7 +179,7 @@ class DocumentsWriterPerThread {pendingUpdates.clear();deleteSlice = deleteQueue.newSlice();- segmentInfo = new SegmentInfo(directoryOrig, Version.LATEST, segmentName, -1, false, codec, null, StringHelper.randomId());+ segmentInfo = new SegmentInfo(directoryOrig, Version.LATEST, segmentName, -1, false, codec, null, StringHelper.randomId(), new HashMap<>());assert numDocsInRAM == 0;if (INFO_VERBOSE && infoStream.isEnabled("DWPT")) {infoStream.message("DWPT", Thread.currentThread().getName() + " init seg=" + segmentName + " delQueue=" + deleteQueue);diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex e53793a3e69..f0c910ac819 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -2535,7 +2535,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(directory);SegmentInfo info = new SegmentInfo(directory, Version.LATEST, mergedName, -1,- false, codec, null, StringHelper.randomId());+ false, codec, null, StringHelper.randomId(), new HashMap<>());SegmentMerger merger = new SegmentMerger(mergeReaders, info, infoStream, trackingDir,MergeState.CheckAbort.NONE, globalFieldNumberMap,@@ -2631,7 +2631,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {// Same SI as before but we change directory and nameSegmentInfo newInfo = new SegmentInfo(directory, info.info.getVersion(), segName, info.info.getDocCount(),info.info.getUseCompoundFile(), info.info.getCodec(),- info.info.getDiagnostics(), info.info.getId());+ info.info.getDiagnostics(), info.info.getId(), info.info.getAttributes());SegmentCommitInfo newInfoPerCommit = new SegmentCommitInfo(newInfo, info.getDelCount(), info.getDelGen(),info.getFieldInfosGen(), info.getDocValuesGen());@@ -3742,7 +3742,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {// ConcurrentMergePolicy we keep deterministic segment// names.final String mergeSegmentName = newSegmentName();- SegmentInfo si = new SegmentInfo(directory, Version.LATEST, mergeSegmentName, -1, false, codec, null, StringHelper.randomId());+ SegmentInfo si = new SegmentInfo(directory, Version.LATEST, mergeSegmentName, -1, false, codec, null, StringHelper.randomId(), new HashMap<>());Map<String,String> details = new HashMap<>();details.put("mergeMaxNumSegments", "" + merge.maxNumSegments);details.put("mergeFactor", Integer.toString(merge.segments.size()));diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.javaindex 2a8f580d9ab..3a4f728622a 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java@@ -21,8 +21,10 @@ package org.apache.lucene.index;import java.util.Arrays;import java.util.Collection;import java.util.Collections;+import java.util.HashMap;import java.util.HashSet;import java.util.Map;+import java.util.Objects;import java.util.Set;import java.util.regex.Matcher;@@ -65,6 +67,8 @@ public final class SegmentInfo {private Codec codec;private Map<String,String> diagnostics;++ private Map<String,String> attributes;// Tracks the Lucene version this segment was created with, since 3.1. Null// indicates an older than 3.0 index, and it's used to detect a too old index.@@ -90,7 +94,7 @@ public final class SegmentInfo {*/public SegmentInfo(Directory dir, Version version, String name, int docCount,boolean isCompoundFile, Codec codec, Map<String,String> diagnostics,- byte[] id) {+ byte[] id, Map<String,String> attributes) {assert !(dir instanceof TrackingDirectoryWrapper);this.dir = dir;this.version = version;@@ -103,6 +107,7 @@ public final class SegmentInfo {if (id.length != StringHelper.ID_LENGTH) {throw new IllegalArgumentException("invalid id: " + Arrays.toString(id));}+ this.attributes = Objects.requireNonNull(attributes);}/**@@ -267,4 +272,34 @@ public final class SegmentInfo {String namedForThisSegment(String file) {return name + IndexFileNames.stripSegmentName(file);}++ /**+ * Get a codec attribute value, or null if it does not exist+ */+ public String getAttribute(String key) {+ return attributes.get(key);+ }++ /**+ * Puts a codec attribute value.+ * <p>+ * This is a key-value mapping for the field that the codec can use to store+ * additional metadata, and will be available to the codec when reading the+ * segment via {@link #getAttribute(String)}+ * <p>+ * If a value already exists for the field, it will be replaced with the new+ * value.+ */+ public String putAttribute(String key, String value) {+ return attributes.put(key, value);+ }++ /**+ * Returns the internal codec attributes map.+ * @return internal codec attributes map.+ */+ public Map<String,String> getAttributes() {+ return attributes;+ }}+diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java b/lucene/core/src/test/org/apache/lucene/index/TestCodecs.javaindex 9241caf4fc0..5ae4d89b92a 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java@@ -19,6 +19,7 @@ package org.apache.lucene.index;import java.io.IOException;import java.util.Arrays;+import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Random;@@ -220,7 +221,7 @@ public class TestCodecs extends LuceneTestCase {final FieldInfos fieldInfos = builder.finish();final Directory dir = newDirectory();Codec codec = Codec.getDefault();- final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null, StringHelper.randomId());+ final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null, StringHelper.randomId(), new HashMap<>());this.write(si, fieldInfos, dir, fields);final FieldsProducer reader = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random())));@@ -277,7 +278,7 @@ public class TestCodecs extends LuceneTestCase {}Codec codec = Codec.getDefault();- final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null, StringHelper.randomId());+ final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null, StringHelper.randomId(), new HashMap<>());this.write(si, fieldInfos, dir, fields);if (VERBOSE) {diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java b/lucene/core/src/test/org/apache/lucene/index/TestDoc.javaindex acba877dc22..9900c7c2096 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java@@ -28,6 +28,7 @@ import java.nio.file.Files;import java.nio.file.Path;import java.util.Arrays;import java.util.Collection;+import java.util.HashMap;import java.util.HashSet;import java.util.LinkedList;@@ -220,7 +221,7 @@ public class TestDoc extends LuceneTestCase {final Codec codec = Codec.getDefault();TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(si1.info.dir);- final SegmentInfo si = new SegmentInfo(si1.info.dir, Version.LATEST, merged, -1, false, codec, null, StringHelper.randomId());+ final SegmentInfo si = new SegmentInfo(si1.info.dir, Version.LATEST, merged, -1, false, codec, null, StringHelper.randomId(), new HashMap<>());SegmentMerger merger = new SegmentMerger(Arrays.<LeafReader>asList(r1, r2),si, InfoStream.getDefault(), trackingDir,diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.javaindex 6f474ff1546..a1187032d42 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java@@ -19,6 +19,7 @@ package org.apache.lucene.index;import java.io.IOException;import java.util.Arrays;+import java.util.HashMap;import org.apache.lucene.codecs.Codec;import org.apache.lucene.document.Document;@@ -79,7 +80,7 @@ public class TestSegmentMerger extends LuceneTestCase {public void testMerge() throws IOException {final Codec codec = Codec.getDefault();- final SegmentInfo si = new SegmentInfo(mergedDir, Version.LATEST, mergedSegment, -1, false, codec, null, StringHelper.randomId());+ final SegmentInfo si = new SegmentInfo(mergedDir, Version.LATEST, mergedSegment, -1, false, codec, null, StringHelper.randomId(), new HashMap<>());SegmentMerger merger = new SegmentMerger(Arrays.<LeafReader>asList(reader1, reader2),si, InfoStream.getDefault(), mergedDir,diff --git a/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.java b/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.javaindex 49028920348..b5e93b48c74 100644--- a/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.java+++ b/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.java@@ -24,6 +24,7 @@ import java.text.DecimalFormat;import java.text.DecimalFormatSymbols;import java.util.ArrayList;import java.util.Collection;+import java.util.HashMap;import java.util.List;import java.util.Locale;@@ -137,7 +138,7 @@ public class IndexSplitter {SegmentInfo info = infoPerCommit.info;// Same info just changing the dir:SegmentInfo newInfo = new SegmentInfo(destFSDir, info.getVersion(), info.name, info.getDocCount(),- info.getUseCompoundFile(), info.getCodec(), info.getDiagnostics(), info.getId());+ info.getUseCompoundFile(), info.getCodec(), info.getDiagnostics(), info.getId(), new HashMap<>());destInfos.add(new SegmentCommitInfo(newInfo, infoPerCommit.getDelCount(),infoPerCommit.getDelGen(), infoPerCommit.getFieldInfosGen(),infoPerCommit.getDocValuesGen()));diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.javaindex 393de11e08b..a0c04cf4ffd 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java@@ -21,6 +21,7 @@ import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;+import java.util.HashMap;import java.util.List;import org.apache.lucene.codecs.Codec;@@ -626,7 +627,7 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest/** Returns a new fake segment */protected static SegmentInfo newSegmentInfo(Directory dir, String name) {- return new SegmentInfo(dir, Version.LATEST, name, 10000, false, Codec.getDefault(), null, StringHelper.randomId());+ return new SegmentInfo(dir, Version.LATEST, name, 10000, false, Codec.getDefault(), null, StringHelper.randomId(), new HashMap<>());}/** Creates a file of the specified size with random data. */diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.javaindex 6bb68405bd5..3ef4f2ddc07 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseFieldInfoFormatTestCase.java@@ -18,6 +18,7 @@ package org.apache.lucene.index;*/import java.io.IOException;+import java.util.HashMap;import java.util.HashSet;import java.util.Random;import java.util.Set;@@ -175,7 +176,7 @@ public abstract class BaseFieldInfoFormatTestCase extends BaseIndexFileFormatTes/** Returns a new fake segment */protected static SegmentInfo newSegmentInfo(Directory dir, String name) {- return new SegmentInfo(dir, Version.LATEST, name, 10000, false, Codec.getDefault(), null, StringHelper.randomId());+ return new SegmentInfo(dir, Version.LATEST, name, 10000, false, Codec.getDefault(), null, StringHelper.randomId(), new HashMap<>());}@Overridediff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.javaindex 5d33f44b671..6024c7e835a 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java@@ -23,6 +23,7 @@ import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.EnumSet;+import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;@@ -674,7 +675,7 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest// randomly index at lower IndexOptionprivate FieldsProducer buildIndex(Directory dir, IndexOptions maxAllowed, boolean allowPayloads, boolean alwaysTestMax) throws IOException {Codec codec = getCodec();- SegmentInfo segmentInfo = new SegmentInfo(dir, Version.LATEST, "_0", maxDoc, false, codec, null, StringHelper.randomId());+ SegmentInfo segmentInfo = new SegmentInfo(dir, Version.LATEST, "_0", maxDoc, false, codec, null, StringHelper.randomId(), new HashMap<>());int maxIndexOption = Arrays.asList(IndexOptions.values()).indexOf(maxAllowed);if (VERBOSE) {diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.javaindex 2d3500f2e62..8a9a51dbf9e 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java@@ -49,7 +49,7 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTCodec codec = getCodec();byte id[] = StringHelper.randomId();SegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,- Collections.<String,String>emptyMap(), id);+ Collections.<String,String>emptyMap(), id, new HashMap<>());info.setFiles(Collections.<String>emptySet());codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT);@@ -63,7 +63,7 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTCodec codec = getCodec();byte id[] = StringHelper.randomId();SegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,- Collections.<String,String>emptyMap(), id);+ Collections.<String,String>emptyMap(), id, new HashMap<>());Set<String> originalFiles = Collections.singleton("_123.a");info.setFiles(originalFiles);codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);@@ -86,7 +86,7 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTdiagnostics.put("key1", "value1");diagnostics.put("key2", "value2");SegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,- diagnostics, id);+ diagnostics, id, new HashMap<>());info.setFiles(Collections.<String>emptySet());codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT);@@ -94,13 +94,30 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTdir.close();}+ /** Test attributes map */+ public void testAttributes() throws Exception {+ Directory dir = newDirectory();+ Codec codec = getCodec();+ byte id[] = StringHelper.randomId();+ Map<String,String> attributes = new HashMap<>();+ attributes.put("key1", "value1");+ attributes.put("key2", "value2");+ SegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,+ Collections.emptyMap(), id, attributes);+ info.setFiles(Collections.<String>emptySet());+ codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);+ SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT);+ assertEquals(attributes, info2.getAttributes());+ dir.close();+ }+/** Test unique ID */public void testUniqueID() throws Exception {Codec codec = getCodec();Directory dir = newDirectory();byte id[] = StringHelper.randomId();SegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,- Collections.<String,String>emptyMap(), id);+ Collections.<String,String>emptyMap(), id, new HashMap<>());info.setFiles(Collections.<String>emptySet());codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT);@@ -115,7 +132,7 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTDirectory dir = newDirectory();byte id[] = StringHelper.randomId();SegmentInfo info = new SegmentInfo(dir, v, "_123", 1, false, codec,- Collections.<String,String>emptyMap(), id);+ Collections.<String,String>emptyMap(), id, new HashMap<>());info.setFiles(Collections.<String>emptySet());codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", id, IOContext.DEFAULT);@@ -153,7 +170,14 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTbyte id[] = new byte[StringHelper.ID_LENGTH];random().nextBytes(id);- SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile, codec, diagnostics, id);+ Map<String,String> attributes = new HashMap<>();+ int numAttributes = random().nextInt(10);+ for (int j = 0; j < numAttributes; j++) {+ attributes.put(TestUtil.randomUnicodeString(random()),+ TestUtil.randomUnicodeString(random()));+ }++ SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile, codec, diagnostics, id, attributes);info.setFiles(files);codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);SegmentInfo info2 = codec.segmentInfoFormat().read(dir, name, id, IOContext.DEFAULT);@@ -174,6 +198,7 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTassertIDEquals(expected.getId(), actual.getId());assertEquals(expected.getUseCompoundFile(), actual.getUseCompoundFile());assertEquals(expected.getVersion(), actual.getVersion());+ assertEquals(expected.getAttributes(), actual.getAttributes());}/** Returns the versions this SI should test */