Skip to content

Commit fbd38ac

Browse files
committed
add (hopefully) explanatory comments about term traversal
1 parent d091b4b commit fbd38ac

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/org/opensolaris/opengrok/index/IndexDatabase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ public void update() throws IOException, HistoryException {
429429
indexDown(sourceRoot, dir, false, 0,
430430
getFileCount(sourceRoot, dir));
431431

432+
// Remove data for the trailing terms that indexDown()
433+
// did not traverse. These correspond to files that have
434+
// been removed and have higher ordering that any terms
435+
// in the index.
432436
while (uidIter != null && uidIter.term() != null
433437
&& uidIter.term().utf8ToString().startsWith(startuid)) {
434438

@@ -910,18 +914,29 @@ private int indexDown(File dir, String parent, boolean count_only,
910914
DateTools.timeToString(file.lastModified(),
911915
DateTools.Resolution.MILLISECOND)); // construct uid for doc
912916
BytesRef buid = new BytesRef(uid);
917+
// Traverse terms that have smaller UID than the current
918+
// file, i.e. given the ordering they positioned before the file
919+
// or it is the file that has been modified.
913920
while (uidIter != null && uidIter.term() != null
914921
&& uidIter.term().compareTo(emptyBR) != 0
915922
&& uidIter.term().compareTo(buid) < 0) {
916923

924+
// If the term's path matches path of currently processed file,
925+
// it is clear that the file has been modified and thus
926+
// removeFile() will be followed by call to addFile() below.
927+
// In such case, instruct removeFile() not to remove history
928+
// cache for the file so that incremental history cache
929+
// generation works.
917930
String termPath = Util.uid2url(uidIter.term().utf8ToString());
918931
removeFile(!termPath.equals(path));
932+
919933
BytesRef next = uidIter.next();
920934
if (next == null) {
921935
uidIter = null;
922936
}
923937
}
924938

939+
// If the file was not modified, skip to the next one.
925940
if (uidIter != null && uidIter.term() != null
926941
&& uidIter.term().bytesEquals(buid)) {
927942
BytesRef next = uidIter.next(); // keep matching docs

0 commit comments

Comments
 (0)