public LogManager(TransactionSubsystem txnSubsystem) throws ACIDException { this.txnSubsystem = txnSubsystem; logManagerProperties = new LogManagerProperties( this.txnSubsystem.getTransactionProperties(), this.txnSubsystem.getId()); logFileSize = logManagerProperties.getLogPartitionSize(); logPageSize = logManagerProperties.getLogPageSize(); numLogPages = logManagerProperties.getNumLogPages(); logDir = logManagerProperties.getLogDir(); logFilePrefix = logManagerProperties.getLogFilePrefix(); flushLSN = new MutableLong(); appendLSN = new AtomicLong(); initializeLogManager(SMALLEST_LOG_FILE_ID); }
private void dumpConfVars(OutputStream os) { try { StringBuilder sb = new StringBuilder(); sb.append("\n>>dump_begin\t>>----- [ConfVars] -----"); sb.append(logManagerProperties.toString()); sb.append("\n>>dump_end\t>>----- [ConfVars] -----\n"); os.write(sb.toString().getBytes()); } catch (Exception e) { // ignore exception and continue dumping as much as possible. if (IS_DEBUG_MODE) { e.printStackTrace(); } } }
private long initializeLogAnchor(long nextLogFileId) { long fileId = 0; long offset = 0; File fileLogDir = new File(logDir); try { if (fileLogDir.exists()) { List<Long> logFileIds = getLogFileIds(); if (logFileIds == null) { fileId = nextLogFileId; createFileIfNotExists(getLogFilePath(fileId)); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("created a log file: " + getLogFilePath(fileId)); } } else { fileId = logFileIds.get(logFileIds.size() - 1); File logFile = new File(getLogFilePath(fileId)); offset = logFile.length(); } } else { fileId = nextLogFileId; createNewDirectory(logDir); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("created the log directory: " + logManagerProperties.getLogDir()); } createFileIfNotExists(getLogFilePath(fileId)); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("created a log file: " + getLogFilePath(fileId)); } } } catch (IOException ioe) { throw new IllegalStateException("Failed to initialize the log anchor", ioe); } if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("log file Id: " + fileId + ", offset: " + offset); } return logFileSize * fileId + offset; }