Skip to content

Commit

Permalink
segment info changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed May 3, 2024
1 parent e1bd26f commit 75618e3
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ private SegmentInfo parseSegmentInfo(
diagnostics,
segmentID,
attributes,
indexSort);
indexSort,
null);
si.setFiles(files);
return si;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ private SegmentInfo parseSegmentInfo(
diagnostics,
segmentID,
attributes,
indexSort);
indexSort,
null);
si.setFiles(files);
return si;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private SegmentInfo parseSegmentInfo(
diagnostics,
segmentID,
attributes,
indexSort);
indexSort,
null);
si.setFiles(files);
return si;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private SegmentInfo parseSegmentInfo(
diagnostics,
segmentID,
attributes,
indexSort);
indexSort,
null);
si.setFiles(files);
return si;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public SegmentInfo read(
diagnostics,
id,
attributes,
indexSort);
indexSort,
null); // TODO
info.setFiles(files);
return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public void testFileIsUTF8() throws IOException {
Collections.<String, String>emptyMap(),
id,
Collections.emptyMap(),
null);
null,
null); // TODO
info.setFiles(Collections.<String>emptySet());
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
String segFileName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,21 @@ private SegmentInfo parseSegmentInfo(
}

// TODO : bwc tests are failing , need to check how to handle this
DataCubesConfig compositeConfig = null;
// int numCompositeFields = input.readVInt();
// DataCubesConfig compositeConfig;
// if (numCompositeFields > 0) {
// DataCubeField[] compositeIndexFields = new DataCubeField[numCompositeFields];
// for (int i = 0; i < numCompositeFields; i++) {
DataCubesConfig dataCubesConfig = null;
// int numDataCubeFields = input.readVInt();
// DataCubesConfig dataCubesConfig;
// if (numDataCubeFields > 0) {
// DataCubeField[] dataCubeFields = new DataCubeField[numDataCubeFields];
// for (int i = 0; i < numDataCubeFields; i++) {
// String name = input.readString();
// compositeIndexFields[i] =
// DataCubeFieldProvider.forName(name).readDataCubeField(input);
// dataCubeFields[i] = DataCubeFieldProvider.forName(name).readDataCubeField(input);
// }
// compositeConfig = new DataCubesConfig(compositeIndexFields);
// } else if (numCompositeFields < 0) {
// dataCubesConfig = new DataCubesConfig(dataCubeFields);
// } else if (numDataCubeFields < 0) {
// throw new CorruptIndexException(
// "invalid composite field count: " + numCompositeFields, input);
// "invalid data cubes field count: " + numDataCubeFields, input);
// } else {
// compositeConfig = null;
// dataCubesConfig = null;
// }

SegmentInfo si =
Expand All @@ -182,7 +181,7 @@ private SegmentInfo parseSegmentInfo(
segmentID,
attributes,
indexSort,
compositeConfig);
dataCubesConfig);
si.setFiles(files);
return si;
}
Expand Down Expand Up @@ -252,14 +251,15 @@ private void writeSegmentInfo(DataOutput output, SegmentInfo si) throws IOExcept
output.writeString(sorter.getProviderName());
SortFieldProvider.write(sortField, output);
}

// TODO
// DataCubesConfig compositeConfig = si.getDataCubesConfig();
// int numCompositeFields = compositeConfig == null ? 0 : compositeConfig.getFields().length;
// output.writeVInt(numCompositeFields);
// for (int i = 0; i < numCompositeFields; ++i) {
// DataCubeField compositeIndexField = compositeConfig.getFields()[i];
// output.writeString(compositeIndexField.getProviderName());
// DataCubeFieldProvider.write(compositeIndexField, output);
// DataCubesConfig dataCubesConfig = si.getDataCubesConfig();
// int numDataCubeFields = dataCubesConfig == null ? 0 : dataCubesConfig.getFields().length;
// output.writeVInt(numDataCubeFields);
// for (int i = 0; i < numDataCubeFields; ++i) {
// DataCubeField dataCubeField = dataCubesConfig.getFields()[i];
// output.writeString(dataCubeField.getProviderName());
// DataCubeFieldProvider.write(dataCubeField, output);
// }
}
}
30 changes: 0 additions & 30 deletions lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,36 +146,6 @@ public SegmentInfo(
this.dataCubesConfig = dataCubesConfig;
}

/** TODO: remove this? */
public SegmentInfo(
Directory dir,
Version version,
Version minVersion,
String name,
int maxDoc,
boolean isCompoundFile,
boolean hasBlocks,
Codec codec,
Map<String, String> diagnostics,
byte[] id,
Map<String, String> attributes,
Sort indexSort) {
this(
dir,
version,
minVersion,
name,
maxDoc,
isCompoundFile,
hasBlocks,
codec,
diagnostics,
id,
attributes,
indexSort,
null);
}

/**
* Mark whether this segment is stored as a compound file.
*
Expand Down
19 changes: 19 additions & 0 deletions lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ MergeState merge() throws IOException {

TaskExecutor taskExecutor = new TaskExecutor(mergeState.intraMergeTaskExecutor);
List<Callable<Void>> mergingTasks = new ArrayList<>();

mergingTasks.add(
() -> {
if (mergeState.mergeFieldInfos.hasNorms()) {
Expand Down Expand Up @@ -183,6 +184,14 @@ MergeState merge() throws IOException {
return null;
});
}
if (mergeState.segmentInfo.getDataCubesConfig() != null) {
mergingTasks.add(
() -> {
mergeWithLogging(
this::mergeDataCubes, segmentWriteState, segmentReadState, "data cubes", numMerged);
return null;
});
}

taskExecutor.invokeAll(mergingTasks);
// write the merged infos
Expand Down Expand Up @@ -276,6 +285,16 @@ private int mergeTermVectors() throws IOException {
}
}

private void mergeDataCubes(
SegmentWriteState segmentWriteState, SegmentReadState segmentReadState) throws IOException {
try (DataCubesDocValuesConsumer consumer =
codec
.dataCubesFormat()
.fieldsConsumer(segmentWriteState, mergeState.segmentInfo.getDataCubesConfig())) {
consumer.merge(mergeState);
}
}

private void mergeVectorValues(
SegmentWriteState segmentWriteState, SegmentReadState segmentReadState) throws IOException {
try (KnnVectorsWriter writer = codec.knnVectorsFormat().fieldsWriter(segmentWriteState)) {
Expand Down
2 changes: 2 additions & 0 deletions lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public void testFixedPostings() throws Throwable {
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
null,
null);

this.write(si, fieldInfos, dir, fields);
Expand Down Expand Up @@ -331,6 +332,7 @@ public void testRandomPostings() throws Throwable {
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
null,
null);
this.write(si, fieldInfos, dir, fields);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ public void merge(MergePolicy.OneMerge merge) throws IOException {
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
null,
null),
0,
0,
Expand Down
1 change: 1 addition & 0 deletions lucene/core/src/test/org/apache/lucene/index/TestDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ private SegmentCommitInfo merge(
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
null,
null);

SegmentMerger merger =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private static MergePolicy.MergeSpecification createRandomMergeSpecification(
random(), StringHelper.ID_LENGTH, StringHelper.ID_LENGTH)
.getBytes(StandardCharsets.US_ASCII),
Collections.emptyMap(), // attributes
null /* indexSort */);
null /* indexSort */,
null /*datacubesconfig*/);
final List<SegmentCommitInfo> segments = new LinkedList<SegmentCommitInfo>();
segments.add(new SegmentCommitInfo(si, 0, 0, 0, 0, 0, StringHelper.randomId()));
ms.add(new MergePolicy.OneMerge(segments));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private static MergePolicy.MergeSpecification createRandomMergeSpecification(Dir
random(), StringHelper.ID_LENGTH, StringHelper.ID_LENGTH)
.getBytes(StandardCharsets.US_ASCII),
Collections.emptyMap(), // attributes
null /* indexSort */);
null /* indexSort */,
null /*datacubesconfig*/);
final List<SegmentCommitInfo> segments = new LinkedList<SegmentCommitInfo>();
segments.add(new SegmentCommitInfo(si, 0, 0, 0, 0, 0, StringHelper.randomId()));
ms.add(new MergePolicy.OneMerge(segments));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void testDeleteDoc() throws IOException {
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
null,
null);
SegmentCommitInfo commitInfo =
new SegmentCommitInfo(si, 0, 0, -1, -1, -1, StringHelper.randomId());
Expand Down Expand Up @@ -98,6 +99,7 @@ public void testWriteLiveDocs() throws IOException {
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
null,
null);
SegmentCommitInfo commitInfo =
new SegmentCommitInfo(si, 0, 0, -1, -1, -1, StringHelper.randomId());
Expand Down
24 changes: 18 additions & 6 deletions lucene/core/src/test/org/apache/lucene/index/TestSegmentInfos.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void testVersionsOneSegment() throws IOException {
Collections.<String, String>emptyMap(),
id,
Collections.<String, String>emptyMap(),
null,
null);
info.setFiles(Collections.<String>emptySet());
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
Expand Down Expand Up @@ -116,6 +117,7 @@ public void testVersionsTwoSegments() throws IOException {
Collections.<String, String>emptyMap(),
id,
Collections.<String, String>emptyMap(),
null,
null);
info.setFiles(Collections.<String>emptySet());
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
Expand All @@ -136,6 +138,7 @@ public void testVersionsTwoSegments() throws IOException {
Collections.<String, String>emptyMap(),
id,
Collections.<String, String>emptyMap(),
null,
null);
info.setFiles(Collections.<String>emptySet());
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
Expand Down Expand Up @@ -181,7 +184,8 @@ public void testToString() throws Throwable {
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
Sort.INDEXORDER);
Sort.INDEXORDER,
null);
assertEquals(
"TEST(" + Version.LATEST.toString() + ")" + ":C10000" + ":[indexSort=<doc>]",
si.toString());
Expand All @@ -200,7 +204,8 @@ public void testToString() throws Throwable {
diagnostics,
StringHelper.randomId(),
new HashMap<>(),
Sort.INDEXORDER);
Sort.INDEXORDER,
null); // TODO
assertEquals(
"TEST("
+ Version.LATEST.toString()
Expand All @@ -226,7 +231,8 @@ public void testToString() throws Throwable {
Collections.emptyMap(),
StringHelper.randomId(),
attributes,
Sort.INDEXORDER);
Sort.INDEXORDER,
null);
assertEquals(
"TEST("
+ Version.LATEST.toString()
Expand All @@ -252,7 +258,8 @@ public void testToString() throws Throwable {
diagnostics,
StringHelper.randomId(),
attributes,
Sort.INDEXORDER);
Sort.INDEXORDER,
null);
assertEquals(
"TEST("
+ Version.LATEST.toString()
Expand Down Expand Up @@ -287,6 +294,7 @@ public void testIDChangesOnAdvance() throws IOException {
Collections.<String, String>emptyMap(),
StringHelper.randomId(),
Collections.<String, String>emptyMap(),
null,
null);
SegmentCommitInfo commitInfo = new SegmentCommitInfo(info, 0, 0, -1, -1, -1, id);
assertEquals(StringHelper.idToString(id), StringHelper.idToString(commitInfo.getId()));
Expand Down Expand Up @@ -334,6 +342,7 @@ public void testBitFlippedTriggersCorruptIndexException() throws IOException {
Collections.<String, String>emptyMap(),
id,
Collections.<String, String>emptyMap(),
null,
null);
info.setFiles(Collections.<String>emptySet());
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
Expand All @@ -354,6 +363,7 @@ public void testBitFlippedTriggersCorruptIndexException() throws IOException {
Collections.<String, String>emptyMap(),
id,
Collections.<String, String>emptyMap(),
null,
null);
info.setFiles(Collections.<String>emptySet());
codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);
Expand Down Expand Up @@ -426,7 +436,8 @@ public void testAddDiagnostics() throws Throwable {
diagnostics,
StringHelper.randomId(),
new HashMap<>(),
Sort.INDEXORDER);
Sort.INDEXORDER,
null);
si.addDiagnostics(Map.of("key3", "value3"));
assertEquals(Map.of("key1", "value1", "key2", "value2", "key3", "value3"), si.getDiagnostics());

Expand All @@ -444,7 +455,8 @@ public void testAddDiagnostics() throws Throwable {
diagnostics,
StringHelper.randomId(),
new HashMap<>(),
Sort.INDEXORDER);
Sort.INDEXORDER,
null);
si.addDiagnostics(Map.of("key2", "foo"));
assertEquals(Map.of("key1", "value1", "key2", "foo"), si.getDiagnostics());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void testMerge() throws IOException {
Collections.emptyMap(),
StringHelper.randomId(),
new HashMap<>(),
null,
null);

SegmentMerger merger =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void split(Path destDir, String[] segs) throws IOException {
info.getDiagnostics(),
info.getId(),
Collections.emptyMap(),
null,
null);
destInfos.add(
new SegmentCommitInfo(
Expand Down
Loading

0 comments on commit 75618e3

Please sign in to comment.