-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Lucene version to UploadedSegmentMetadata #1
Conversation
Signed-off-by: Bhumika Saini <[email protected]>
Signed-off-by: Bhumika Saini <[email protected]>
Signed-off-by: Bhumika Saini <[email protected]>
Signed-off-by: Bhumika Saini <[email protected]>
Signed-off-by: Bhumika Saini <[email protected]>
Signed-off-by: Bhumika Saini <[email protected]>
Gradle Check (Jenkins) Run Completed with:
|
get AI code review |
Names();\n+ for (String segFile : segFiles) {\n+ segmentToLuceneVersion.put(segFile, info.getVersion());\n+ }\n+ }\n+\n try {\n VersionedCodecStreamWrapper.wrap(indexOutput, CURRENT_VERSION, (out) -> {\n ByteBuffersDataOutput dataOutput = new ByteBuffersDataOutput(out);\n dataOutput.writeVInt(segmentInfosSnapshot.size());\n- for (SegmentCommitInfo segmentCommitInfo : segmentInfosSnapshot) {\n+ for (SegmentCommitInfo segmentCommitInfo : segmentInfosSnapshot) {\n+ Version luceneVersion = segmentToLuceneVersion.get(segmentCommitInfo.info.name);\n dataOutput.writeString(segmentCommitInfo.info.name);\n dataOutput.writeString(segmentCommitInfo.info.getId().toString());\n+ dataOutput.writeString(luceneVersion.toString());\n }\n });\n } finally {\n" No performance or security issues can be identified from the code/pull request. However, there may be bugs in the code, such as incorrect handling of the Lucene version information or incorrect handling of segment files. Additionally, it is possible that the code is missing necessary error handling. |
get AI code review |
\n+ segmentToLuceneVersion.put(info.name, info.getVersion());\n+ }\n+\n try (VersionedCodecStreamWrapper out = new VersionedCodecStreamWrapper(indexOutput)) {\n- out.writeVInt(VERSION);\n+ out.writeVInt(VERSION_WITH_LUCENE_VERSION);\n out.writeVInt(segmentInfosSnapshot.size());\n for (SegmentCommitInfo segmentCommitInfo : segmentInfosSnapshot) {\n SegmentInfo info = segmentCommitInfo.info;\n- out.writeString(info.name);\n+ out.writeString(info.name);\n+ Version luceneVersion = segmentToLuceneVersion.get(info.name);\n+ if (luceneVersion != null) {\n+ out.writeString(luceneVersion.toString());\n+ } else {\n+ out.writeString(Version.LATEST.toString());\n+ }\n out.writeVLong(info.getSizeInBytes());\n }\n }\n@@ -535,7 +575,7 @@ public void uploadMetadata(\n }\n \n // Write the segment info\n- writeSegmentInfo(segmentInfo, segmentInfoFilename);\n+ writeSegmentInfo(segmentInfo, segmentInfoFilename, segmentToLuceneVersion.get(segmentInfo.name));\n \n // Update the remote store with the segment info\n uploadSegmentInfo(segmentInfoFilename);\n@@ -562,7 +602,7 @@ public void uploadMetadata(\n }\n } finally {\n CodecUtil.checkFooter(in);\n- in.close();\n+ IOUtils.close(in);\n }\n }\n \n@@ -629,6 +669,14 @@ private void writeSegmentInfo(SegmentInfo segmentInfo, String segmentInfoFilename)\n // Write the segment info\n try (ByteBuffersDataOutput out = new |
get AI code review |
= segmentCommitInfo.info;\n+ segmentToLuceneVersion.put(in.name, in.getVersion());\n+ }\n VersionedCodecStreamWrapper.writeVersioned(indexOutput, out -> {\n out.writeVInt(metadata.size());\n for (Map.Entry<String, UploadedSegmentMetadata> entry : metadata.entrySet()) {\n out.writeString(entry.getKey());\n- out.writeString(entry.getValue().toString());\n+ UploadedSegmentMetadata value = entry.getValue();\n+ Version version = segmentToLuceneVersion.get(value.getOriginalFilename());\n+ if (version != null) {\n+ value.setWrittenBy(version);\n+ }\n+ out.writeString(value.toString());\n }\n });\n } finally {\n" Security:
Performance:
Maintainability:
Best Practices:
|
get AI code review |
= segmentCommitInfo.info;\n+ segmentToLuceneVersion.put(in.name, in.getVersion());\n+ }\n+\n VersionedCodecStreamWrapper.write(indexOutput, out -> {\n out.writeVInt(segmentInfosSnapshot.size());\n for (SegmentCommitInfo segmentCommitInfo : segmentInfosSnapshot) {\n SegmentInfo in = segmentCommitInfo.info;\n- out.writeString(in.name);\n+ out.writeString(in.name);\n+ out.writeString(segmentToLuceneVersion.get(in.name).toString());\n out.writeVLong(in.getDelGen());\n out.writeVLong(in.getDelCount());\n out.writeVLong(in.getFieldInfosGen());\n }\n });\n+\n+ for (SegmentCommitInfo segmentCommitInfo : segmentInfosSnapshot) {\n+ SegmentInfo in = segmentCommitInfo.info;\n+ UploadedSegmentMetadata metadata = new UploadedSegmentMetadata(in.name, metadataFilename, CodecUtil.retrieveChecksum(indexOutput), indexOutput.length());\n+ metadata.setWrittenBy(segmentToLuceneVersion.get(in.name));\n+ segmentMetadata.put(in.name, metadata);\n+ }\n } finally {\n indexOutput.close();\n }\n Security:
Performance:
Maintainability:
Best Practices:
|
get AI code review |
segmentInfos) {\n+ segmentToLuceneVersion.put(segmentCommitInfo.info.name, segmentCommitInfo.info.getVersion());\n+ }\n+\n VersionedCodecStreamWrapper wrapper = new VersionedCodecStreamWrapper(indexOutput);\n wrapper.writeVInt(CURRENT_VERSION);\n wrapper.writeVInt(segmentInfos.size());\n for (SegmentCommitInfo segmentCommitInfo : segmentInfos) {\n- wrapper.writeString(segmentCommitInfo.info.name);\n+ wrapper.writeString(segmentCommitInfo.info.name);\n+ Version luceneVersion = segmentToLuceneVersion.get(segmentCommitInfo.info.name);\n+ if (luceneVersion != null) {\n+ wrapper.writeString(luceneVersion.toString());\n+ } else {\n+ wrapper.writeString(Version.LATEST.toString());\n+ }\n }\n wrapper.close();\n } catch (IOException e) {\nRecommendations:
|
get AI code review |
itInfo : segmentInfos) {\n+ segmentToLuceneVersion.put(segmentComitInfo.info.name, segmentComitInfo.info.getVersion());\n+ }\n+\n VersionedCodecStreamWrapper versionedCodecStreamWrapper = new VersionedCodecStreamWrapper(indexOutput);\n try (DataOutput dataOutput = versionedCodecStreamWrapper.getDataOutput()) {\n dataOutput.writeVInt(segmentInfos.size());\n for (SegmentCommitInfo segmentCommitInfo : segmentInfos) {\n- dataOutput.writeString(segmentCommitInfo.info.name);\n+ dataOutput.writeString(segmentCommitInfo.info.name);\n+ dataOutput.writeString(segmentToLuceneVersion.get(segmentCommitInfo.info.name).toString());\n dataOutput.writeVLong(segmentCommitInfo.info.getSizeInBytes());\n }\n }\n+\n+ for (Map.Entry<String, UploadedSegmentMetadata> entry : uploadedSegmentMetadataMap.entrySet()) {\n+ UploadedSegmentMetadata metadata = entry.getValue();\n+ metadata.setWrittenBy(segmentToLuceneVersion.get(metadata.getOriginalFilename()));\n+ }\n+\n for (Map.Entry<String, UploadedSegmentMetadata> entry : uploadedSegmentMetadataMap.entrySet()) {\n UploadedSegmentMetadata metadata = entry.getValue();\n dataOutput.writeString(metadata.toString());\n Recommendations:
|
get AI code review |
try {\n+ for (SegmentCommitInfo segmentCommitInfo : segmentInfos) {\n+ segmentToLuceneVersion.put(segmentCommitInfo.info.name, segmentCommitInfo.info.getVersion());\n+ }\n+ } catch (CorruptIndexException e) {\n+ logger.warn("Unable to get Lucene version for segment {}", segmentInfos.getSegmentsFileName(), e);\n+ }\n try (VersionedCodecStreamWrapper streamWrapper = new VersionedCodecStreamWrapper(indexOutput)) {\n for (String segmentName : segmentInfos.getSegmentsFileName()) {\n SegmentInfo segmentInfo = segmentInfos.info(segmentName);\n- UploadedSegmentMetadata metadata = new UploadedSegmentMetadata(segmentName, segmentName, CodecUtil.retrieveChecksum(segmentInfo.dir), segmentInfo.sizeInBytes());\n+ UploadedSegmentMetadata metadata = new UploadedSegmentMetadata(segmentName, segmentName, CodecUtil.retrieveChecksum(segmentInfo.dir), segmentInfo.sizeInBytes());\n+ Version luceneVersion = segmentToLuceneVersion.get(segmentName);\n+ if (luceneVersion != null) {\n+ metadata.setWrittenBy(luceneVersion);\n+ }\n streamWrapper.writeObject(metadata);\n }\n }\nSecurity:
Performance:
Maintainability:
Correctness:
Concurrency:
Resource Consumption:
Best Practices:
|
de91d60
to
b9edb5a
Compare
Description
This PR associates the Lucene version with each uploaded segment file metadata entry that is maintained in remote store.
For the segment files that house the segment data (
.cfe
,.cfs
, etc.), we track the Lucene version as captured in the respectiveSegmentInfo
instance.For the
segment_N
files that house the information on segments, we track the Lucene version used for the commit as captured in the respectiveSegmentInfos
instance.Related Issues
Resolves opensearch-project#7722