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 UpdateLog.
()
| 1641 | } |
| 1642 | |
| 1643 | /** |
| 1644 | * Ensures a transaction log is ready. It is either the current one, or a new one. This method |
| 1645 | * must be called with the synchronization monitor on this {@link UpdateLog}. |
| 1646 | */ |
| 1647 | protected void ensureLog() { |
| 1648 | if (tlog == null) { |
| 1649 | Path newLogPath; |
| 1650 | int numAttempts = 0; |
| 1651 | while (true) { |
| 1652 | String newLogName = String.format(Locale.ROOT, LOG_FILENAME_PATTERN, TLOG_NAME, id); |
| 1653 | newLogPath = tlogDir.resolve(newLogName); |
| 1654 | // We expect that the log file does not exist since id is designed to give the index of the |
| 1655 | // next transaction log to create. But in very rare cases, the log files listed in the |
| 1656 | // init() method may be stale here (file system delay?), and id may point to an existing |
| 1657 | // file. |
| 1658 | if (!Files.exists(newLogPath)) { |
| 1659 | break; |
| 1660 | } |
| 1661 | // If the "new" log file already exists, refresh the log list and recompute id. |
| 1662 | // Ideally we would want to include the missing log in the old logs tracking (see init()), |
| 1663 | // but the init() method is not designed to be executed twice. Given that in the rare cases |
| 1664 | // we have seen this missing log, the log was always empty (file size 0), then we simply |
| 1665 | // refresh log list and update the id. |
| 1666 | try { |
| 1667 | log.error( |
| 1668 | "New transaction log already exists {} size={}, skipping it", |
| 1669 | newLogPath, |
| 1670 | Files.size(newLogPath)); |
| 1671 | } catch (IOException e) { |
| 1672 | log.error("New transaction log already exists {} size unknown, skipping it", newLogPath); |
| 1673 | } |
| 1674 | if (++numAttempts >= 2) { |
| 1675 | throw new SolrException( |
| 1676 | ErrorCode.SERVER_ERROR, "Cannot recover from already existing logs"); |
| 1677 | } |
| 1678 | tlogFiles = getLogList(tlogDir); |
| 1679 | id = scanLastLogId(tlogFiles) + 1; // add 1 since we create a new log |
| 1680 | } |
| 1681 | tlog = newTransactionLog(newLogPath, globalStrings, false); |
| 1682 | } |
no test coverage detected