* int, boolean)
*/
public void commitPhaseOne(String master, boolean noSync) throws SqlJetException {
if (errCode != null) {
throw new SqlJetException(errCode);
}
/*
* If no changes have been made, we can leave the transaction early.
*/
if (!dbModified && (journalMode != SqlJetPagerJournalMode.DELETE || exclusiveMode())) {
assert (!dirtyCache || !journalOpen);
return;
}
PAGERTRACE("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n", fileName, master, dbSize);
/*
* If this is an in-memory db, or no pages have been written to, or this
* function has already been called, it is a no-op.
*/
try {
if (state != SqlJetPagerState.SYNCED && !memDb && dirtyCache) {
/*
* If a master journal file name has already been written to the
* journal file, then no sync is required. This happens when it
* is written, then the process fails to upgrade from a RESERVED
* to an EXCLUSIVE lock. The next time the process tries to
* commit the transaction the m-j name will have already been
* written.
*/
if (!setMaster) {
incrChangeCounter();
if (journalMode != SqlJetPagerJournalMode.OFF) {
if (dbSize < dbOrigSize) {
/*
* If this transaction has made the database
* smaller, then all pages being discarded by the
* truncation must be written to the journal file.
*/
int i;
long iSkip = PAGER_MJ_PGNO();
int dbSize = this.dbSize;
this.dbSize = this.dbOrigSize;
for (i = dbSize + 1; i <= this.dbOrigSize; i++) {
if (!SqlJetUtility.bitSetTest(pagesInJournal, i) && i != iSkip) {
final ISqlJetPage pg = getPage(i);
pg.write();
pg.unref();
}
}
this.dbSize = dbSize;
}
writeMasterJournal(master);
syncJournal();
}
}
/* Write all dirty pages to the database file */
final ISqlJetPage dirtyList = pageCache.getDirtyList();
writePageList(dirtyList);
/*
* The error might have left the dirty list all fouled up here,
* but that does not matter because if the if the dirty list did
* get corrupted, then the transaction will roll back and
* discard the dirty list. There is an assert in
* pager_get_all_dirty_pages() that verifies that no attempt is
* made to use an invalid dirty list.
*/
pageCache.cleanAll();
if (dbSize != dbFileSize) {
assert (state.compareTo(SqlJetPagerState.EXCLUSIVE) >= 0);
doTruncate(dbSize - (dbSize == PAGER_MJ_PGNO() ? 1 : 0));
}
/* Sync the database file. */
if (!this.noSync && !noSync) {
fd.sync(syncFlags);
}
state = SqlJetPagerState.SYNCED;
}
} catch (SqlJetIOException e) {
if (e.getIoErrorCode() == SqlJetIOErrorCode.IOERR_BLOCKED) {
/*
* pager_incr_changecounter() may attempt to obtain an exclusive
* lock to spill the cache and return IOERR_BLOCKED. But since
* there is no chance the cache is inconsistent, it is better to
* return SQLITE_BUSY.
*/
throw new SqlJetException(SqlJetErrorCode.BUSY);
}
}
}