bruno-roustant commented on code in PR #3412: URL: https://github.com/apache/solr/pull/3412#discussion_r2176927723
########## solr/core/src/java/org/apache/solr/update/UpdateLog.java: ########## @@ -1592,10 +1595,45 @@ protected void deleteBufferLogs() { } } + /** + * Ensures a transaction log is ready. It is either the current one, or a new one. This method + * must be called with the synchronization monitor on this {@link UpdateLog}. + */ protected void ensureLog() { if (tlog == null) { - String newLogName = String.format(Locale.ROOT, LOG_FILENAME_PATTERN, TLOG_NAME, id); - tlog = newTransactionLog(tlogDir.resolve(newLogName), globalStrings, false); + Path newLogPath; + int numAttempts = 0; + while (true) { + String newLogName = String.format(Locale.ROOT, LOG_FILENAME_PATTERN, TLOG_NAME, id); + newLogPath = tlogDir.resolve(newLogName); + // We expect that the log file does not exist since id is designed to give the index of the + // next transaction log to create. But in very rare cases, the log files listed in the + // init() method may be stale here (file system delay?), and id may point to an existing + // file. + if (!Files.exists(newLogPath)) { + break; + } + // If the "new" log file already exists, refresh the log list and recompute id. Review Comment: Actually I tried but the code is not simpler. The loops allows me to repeat the log path construction based on the newly computed id. I find the loop structure more concise. So I just changed the numAttempts threshold to 2 before aborting. -- 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org