VGalaxies commented on code in PR #17238:
URL: https://github.com/apache/iotdb/pull/17238#discussion_r3346560590
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/utils/WALFileUtils.java:
##########
@@ -182,4 +197,243 @@ public static String getTsFileRelativePath(String
absolutePath) {
Path path = new File(absolutePath).toPath();
return path.subpath(path.getNameCount() - 5,
path.getNameCount()).toString();
}
+
+ /**
+ * Locate the first local searchIndex whose writer progress is equal to or
strictly greater than
+ * the given writer-local frontier. This is currently used by single-writer
recovery paths, so it
+ * matches only entries from the supplied nodeId.
+ *
+ * @return [targetSearchIndex, exactMatchFlag], or null if no matching/later
entry exists
+ */
+ public static long[] locateByWriterProgress(
+ final File logDir, final int nodeId, final long physicalTime, final long
localSeq) {
+ final long[] exactSearchIndex = new long[] {-1L};
+ final long[] firstAfterSearchIndex = new long[] {-1L};
+ final long[] firstAfterPhysicalTime = new long[] {Long.MAX_VALUE};
+ final long[] firstAfterLocalSeq = new long[] {Long.MAX_VALUE};
+
+ forEachSealedSearchableRequest(
+ logDir,
+ request -> {
+ if (request.nodeId != nodeId) {
+ return true;
+ }
+ final int cmp =
+ compareWriterProgress(
+ request.physicalTime,
+ request.nodeId,
+ request.localSeq,
+ physicalTime,
+ nodeId,
+ localSeq);
+ if (cmp == 0) {
+ exactSearchIndex[0] = request.searchIndex;
+ return false;
+ }
+ if (cmp > 0
+ && (firstAfterSearchIndex[0] < 0L
+ || compareWriterProgress(
+ request.physicalTime,
+ request.nodeId,
+ request.localSeq,
+ firstAfterPhysicalTime[0],
+ nodeId,
+ firstAfterLocalSeq[0])
+ < 0)) {
+ firstAfterSearchIndex[0] = request.searchIndex;
+ firstAfterPhysicalTime[0] = request.physicalTime;
+ firstAfterLocalSeq[0] = request.localSeq;
+ }
+ return true;
+ });
+
+ if (exactSearchIndex[0] >= 0L) {
+ return new long[] {exactSearchIndex[0], 1L};
+ }
+ if (firstAfterSearchIndex[0] >= 0L) {
+ return new long[] {firstAfterSearchIndex[0], 0L};
+ }
+ return null;
+ }
+
+ public static long findSearchIndexByWriterProgress(
+ final File logDir, final int nodeId, final long physicalTime, final long
localSeq) {
+ final long[] located = locateByWriterProgress(logDir, nodeId,
physicalTime, localSeq);
+ return located != null && located[1] == 1L ? located[0] : -1L;
+ }
+
+ public static long findSearchIndexAfterWriterProgress(
+ final File logDir, final int nodeId, final long physicalTime, final long
localSeq) {
+ final long[] bestSearchIndex = new long[] {-1L};
+ final long[] bestPhysicalTime = new long[] {Long.MAX_VALUE};
+ final long[] bestLocalSeq = new long[] {Long.MAX_VALUE};
+ forEachSealedSearchableRequest(
+ logDir,
+ request -> {
+ if (request.nodeId != nodeId) {
+ return true;
+ }
+ if (compareWriterProgress(
+ request.physicalTime,
+ request.nodeId,
+ request.localSeq,
+ physicalTime,
+ nodeId,
+ localSeq)
+ <= 0) {
+ return true;
+ }
+ if (bestSearchIndex[0] < 0L
+ || compareWriterProgress(
+ request.physicalTime,
+ request.nodeId,
+ request.localSeq,
+ bestPhysicalTime[0],
+ nodeId,
+ bestLocalSeq[0])
+ < 0) {
+ bestSearchIndex[0] = request.searchIndex;
+ bestPhysicalTime[0] = request.physicalTime;
+ bestLocalSeq[0] = request.localSeq;
+ }
+ return true;
+ });
+ return bestSearchIndex[0];
+ }
+
+ private interface SearchableRequestVisitor {
+ boolean onRequest(SearchableRequestMeta request);
Review Comment:
Done in 5ea428025e. Added a Javadoc note explaining that the method returns
the first search index strictly greater than the writer progress, or -1 when
none exists.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]