bruno-roustant commented on code in PR #3412:
URL: https://github.com/apache/solr/pull/3412#discussion_r2175408605


##########
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:
   Additional robustness mechanism: this method ensures we use either the 
current log, or create a *new* one. If the id field points to an existing one, 
don't be blocked here, just find the next id for the next non-existing log file.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to