Skip to content

Commit

Permalink
improve suggester logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Jul 11, 2023
1 parent 7b642ab commit 55e6fd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions suggester/src/main/java/org/opengrok/suggest/Suggester.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ private void submitInitIfIndexExists(final ExecutorService executorService, fina
if (indexExists(indexDir.path)) {
executorService.submit(getInitRunnable(indexDir, progress));
} else {
LOGGER.log(Level.FINE, "Index in {0} directory does not exist, skipping...", indexDir);
LOGGER.log(Level.FINE, "Index in ''{0}'' directory does not exist, skipping...", indexDir);
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Could not check if index exists", e);
LOGGER.log(Level.WARNING, String.format("Could not check if index in '%s' exists", indexDir), e);
}
}

Expand All @@ -236,7 +236,7 @@ private Runnable getInitRunnable(final NamedIndexDir indexDir, Progress progress
}

Instant start = Instant.now();
LOGGER.log(Level.FINE, "Initializing {0}", indexDir);
LOGGER.log(Level.FINE, "Initializing suggester data in ''{0}''", indexDir);

SuggesterProjectData wfst = new SuggesterProjectData(FSDirectory.open(indexDir.path),
getSuggesterDir(indexDir.name), allowMostPopular, allowedFields);
Expand All @@ -248,10 +248,11 @@ private Runnable getInitRunnable(final NamedIndexDir indexDir, Progress progress
}

Duration d = Duration.between(start, Instant.now());
LOGGER.log(Level.FINE, "Finished initialization of {0}, took {1}", new Object[] {indexDir, d});
LOGGER.log(Level.FINE, "Finished initialization of suggester data in ''{0}'', took {1}",
new Object[] {indexDir, d});
progress.increment();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, String.format("Could not initialize suggester data for %s", indexDir), e);
LOGGER.log(Level.SEVERE, String.format("Could not initialize suggester data for '%s'", indexDir), e);
}
};
}
Expand Down Expand Up @@ -830,5 +831,4 @@ private static class BooleanWrapper {
private volatile boolean value;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public void init() throws IOException {
private long getCommitVersion() throws IOException {
List<IndexCommit> commits = DirectoryReader.listCommits(indexDir);
if (commits.size() > 1) {
throw new IllegalStateException("IndexDeletionPolicy changed, normally only one commit should be stored");
throw new IllegalStateException(String.format("IndexDeletionPolicy changed, normally only one commit "
+ "should be stored. There are %d commits in '%s'", commits.size(), indexDir));
}
IndexCommit commit = commits.get(0);

Expand Down Expand Up @@ -283,7 +284,7 @@ private void createSuggesterDir() throws IOException {
if (!suggesterDir.toFile().exists()) {
boolean directoryCreated = suggesterDir.toFile().mkdirs();
if (!directoryCreated) {
throw new IOException("Could not create suggester directory " + suggesterDir);
throw new IOException(String.format("Could not create suggester directory '%s'", suggesterDir));
}
}
}
Expand All @@ -296,8 +297,8 @@ private void initSearchCountMap() throws IOException {
for (String field : fields) {
int numEntries = (int) lookups.get(field).getCount();
if (numEntries == 0) {
logger.log(Level.FINE, "Skipping creation of ChronicleMap for field " + field + " in directory "
+ suggesterDir + " due to zero number of entries");
logger.log(Level.FINE, String.format("Skipping creation of ChronicleMap for field %s " +
"in directory '%s' due to zero number of entries", field, suggesterDir));
continue;
}

Expand All @@ -313,18 +314,18 @@ private void initSearchCountMap() throws IOException {
try {
m = new ChronicleMapAdapter(field, conf.getAverageKeySize(), conf.getEntries(), f);
} catch (IllegalArgumentException e) {
logger.log(Level.SEVERE, "Could not create ChronicleMap for field " + field + " in directory "
+ suggesterDir + " due to invalid key size ("
+ conf.getAverageKeySize() + ") or number of entries: (" + conf.getEntries() + "):", e);
logger.log(Level.SEVERE, String.format("Could not create ChronicleMap for field %s in directory " +
"'%s' due to invalid key size (%f) or number of entries: (%d):",
field, suggesterDir, conf.getAverageKeySize(), conf.getEntries()), e);
return;
} catch (Throwable t) {
logger.log(Level.SEVERE,
"Could not create ChronicleMap for field " + field + " in directory "
+ suggesterDir + " , most popular completion disabled, if you are using "
String.format("Could not create ChronicleMap for field %s in directory '%s'"
+ " , most popular completion disabled, if you are using "
+ "JDK9+ make sure to specify: "
+ "--add-exports java.base/jdk.internal.ref=ALL-UNNAMED "
+ "--add-exports java.base/jdk.internal.misc=ALL-UNNAMED "
+ "--add-exports java.base/sun.nio.ch=ALL-UNNAMED", t);
+ "--add-exports java.base/sun.nio.ch=ALL-UNNAMED", field, suggesterDir), t);
return;
}

Expand Down Expand Up @@ -396,13 +397,13 @@ public void remove() {
try {
close();
} catch (IOException e) {
logger.log(Level.WARNING, "Could not close opened index directory {0}", indexDir);
logger.log(Level.WARNING, "Could not close opened index directory ''{0}''", indexDir);
}

try {
FileUtils.deleteDirectory(suggesterDir.toFile());
} catch (IOException e) {
logger.log(Level.WARNING, "Cannot remove suggester data: {0}", suggesterDir);
logger.log(Level.WARNING, "Cannot remove suggester data in ''{0}''", suggesterDir);
}
} finally {
lock.writeLock().unlock();
Expand Down Expand Up @@ -439,7 +440,7 @@ boolean incrementSearchCount(final Term term, final int value, boolean waitForLo
} else {
gotLock = lock.readLock().tryLock();
if (!gotLock) {
logger.log(Level.INFO, "Cannot increment search count for term {0} in {1}, rebuild in progress",
logger.log(Level.INFO, "Cannot increment search count for term {0} in ''{1}'', rebuild in progress",
new Object[]{term, suggesterDir});
return false;
}
Expand All @@ -448,7 +449,7 @@ boolean incrementSearchCount(final Term term, final int value, boolean waitForLo
try {
WFSTCompletionLookup lookup = lookups.get(term.field());
if (lookup == null || lookup.get(term.text()) == null) {
logger.log(Level.FINE, "Cannot increment search count for unknown term {0} in {1}",
logger.log(Level.FINE, "Cannot increment search count for unknown term {0} in ''{1}''",
new Object[]{term, suggesterDir});
return false; // unknown term
}
Expand Down Expand Up @@ -648,5 +649,4 @@ public BytesRef next() throws IOException {
return last;
}
}

}

0 comments on commit 55e6fd6

Please sign in to comment.