private synchronized void syncLog(ILogRecord logRecord) throws ACIDException { ITransactionContext txnCtx = null; if (logRecord.getLogType() != LogType.FLUSH) { txnCtx = logRecord.getTxnCtx(); if (txnCtx.getTxnState() == ITransactionManager.ABORTED && logRecord.getLogType() != LogType.ABORT) { throw new ACIDException( "Aborted job(" + txnCtx.getJobId() + ") tried to write non-abort type log record."); } } if (getLogFileOffset(appendLSN.get()) + logRecord.getLogSize() > logFileSize) { prepareNextLogFile(); appendPage.isFull(true); getAndInitNewPage(); } else if (!appendPage.hasSpace(logRecord.getLogSize())) { appendPage.isFull(true); getAndInitNewPage(); } if (logRecord.getLogType() == LogType.UPDATE) { logRecord.setPrevLSN(txnCtx.getLastLSN()); } appendPage.append(logRecord, appendLSN.get()); if (logRecord.getLogType() == LogType.FLUSH) { logRecord.setLSN(appendLSN.get()); } appendLSN.addAndGet(logRecord.getLogSize()); }
@Override public void log(ILogRecord logRecord) throws ACIDException { if (logRecord.getLogSize() > logPageSize) { throw new IllegalStateException(); } syncLog(logRecord); if ((logRecord.getLogType() == LogType.JOB_COMMIT || logRecord.getLogType() == LogType.ABORT) && !logRecord.isFlushed()) { synchronized (logRecord) { while (!logRecord.isFlushed()) { try { logRecord.wait(); } catch (InterruptedException e) { // ignore } } } } }