Commit a07edba3 authored by afreyssin's avatar afreyssin
Browse files

Allows to deactivate the default syncOnWrite mechanism.

parent d4aec689
......@@ -145,6 +145,16 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
public final int getNbLogFiles() {
return nbLogFile;
}
/** If true every write in the log file is synced to disk. */
boolean syncOnWrite = false;
/**
* @return the syncOnWrite
*/
public boolean isSyncOnWrite() {
return syncOnWrite;
}
/**
* Number of pooled operation, by default 1000.
......@@ -265,7 +275,7 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
public int getNbLoadedObjects() {
return repository.getNbLoadedObjects();
}
LogManager logManager = null;
Repository repository = null;
......@@ -297,7 +307,9 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
"NTransaction, cannot initializes the repository ", exc);
throw new IOException(exc.getMessage());
}
logManager = new LogManager(dir, repository);
syncOnWrite = Boolean.getBoolean("Transaction.SyncOnWrite");
logManager = new LogManager(dir, repository, syncOnWrite);
}
/**
......@@ -580,7 +592,9 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
File dir;
LogManager(File dir, Repository repository) throws IOException {
private String mode;
LogManager(File dir, Repository repository, boolean syncOnWrite) throws IOException {
super(4 * Kb);
this.repository = repository;
......@@ -596,6 +610,11 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
lockFile.deleteOnExit();
}
if (syncOnWrite)
mode = "rwd";
else
mode = "rw";
log = new Hashtable(LogMemoryCapacity);
long start = System.currentTimeMillis();
......@@ -621,7 +640,7 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
// are garbaged.
if (logidx == -1) logidx = idx;
try {
LogFile logf = new LogFile(dir, idx);
LogFile logf = new LogFile(dir, idx, mode);
int optype = logf.read();
if (optype == Operation.END) {
// The log is empty
......@@ -740,7 +759,7 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
if (logFile[logidx%nbLogFile] == null) {
// Creates a log file
logFile[logidx%nbLogFile] = new LogFile(dir, logidx);
logFile[logidx%nbLogFile] = new LogFile(dir, logidx, mode);
logFile[logidx%nbLogFile].setLength(MaxLogFileSize);
// Initializes the log file
......@@ -884,7 +903,7 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
}
// Creates and initializes a new log file
logFile[logidx%nbLogFile] = new LogFile(dir, logidx);
logFile[logidx%nbLogFile] = new LogFile(dir, logidx, mode);
logFile[logidx%nbLogFile].setLength(MaxLogFileSize);
// Cleans log file (needed only for new log file, already done in garbage).
......@@ -1175,8 +1194,8 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
*
* @param file the specified file.
*/
public LogFile(File dir, int logidx) throws FileNotFoundException {
super(new File(dir, "log#" + logidx), "rwd");
public LogFile(File dir, int logidx, String mode) throws FileNotFoundException {
super(new File(dir, "log#" + logidx), mode);
this.logidx = logidx;
this.dir = dir;
}
......
......@@ -71,6 +71,12 @@ public interface NGTransactionMBean extends TransactionMBean {
*/
int getNbLogFiles();
/**
* Returns true if every write in the log file is synced to disk.
* @return true if every write in the log file is synced to disk.
*/
boolean isSyncOnWrite();
/**
* Returns the pool size for <code>operation</code> objects, by default 1000.
*
......
......@@ -146,6 +146,16 @@ public final class NTransaction extends AbstractTransaction implements NTransact
public final int getLogFileSize() {
return (logFile.getLogFileSize() /Kb);
}
/** If true every write in the log file is synced to disk. */
boolean syncOnWrite = false;
/**
* @return the syncOnWrite
*/
public boolean isSyncOnWrite() {
return syncOnWrite;
}
/**
* Number of pooled operation, by default 1000.
......@@ -375,7 +385,9 @@ public final class NTransaction extends AbstractTransaction implements NTransact
"NTransaction, cannot initializes the repository ", exc);
throw new IOException(exc.getMessage());
}
logFile = new LogFile(dir, repository);
syncOnWrite = Boolean.getBoolean("NTSyncOnWrite");
logFile = new LogFile(dir, repository, syncOnWrite);
// Be careful, setGarbageDelay and garbageAsync use logFile !!
setGarbageDelay(Configuration.getInteger("NTGarbageDelay", getGarbageDelay()).intValue());
......@@ -485,7 +497,6 @@ public final class NTransaction extends AbstractTransaction implements NTransact
System.arraycopy(buf, 0, op.value, 0, buf.length);
}
if (old != null) old.free();
}
private final byte[] getFromLog(Hashtable log, Object key) throws IOException {
......@@ -722,8 +733,10 @@ public final class NTransaction extends AbstractTransaction implements NTransact
private File lockFile = null;
private Repository repository = null;
private String mode;
LogFile(File dir, Repository repository) throws IOException {
LogFile(File dir, Repository repository, boolean syncOnWrite) throws IOException {
super(4 * Kb);
this.repository = repository;
......@@ -741,6 +754,11 @@ public final class NTransaction extends AbstractTransaction implements NTransact
lockFile.deleteOnExit();
}
if (syncOnWrite)
mode = "rwd";
else
mode = "rw";
log = new Hashtable(LogMemoryCapacity);
// Search for old log file, then apply all committed operation,
......@@ -769,8 +787,7 @@ public final class NTransaction extends AbstractTransaction implements NTransact
if (Debug.debug && logmon.isLoggable(BasicLevel.DEBUG))
logmon.log(BasicLevel.DEBUG,
"NTransaction.init(), OPERATION=" +
optype + ", " + name);
"NTransaction.init(), OPERATION=" + optype + ", " + name);
Operation op = null;
if ((optype == Operation.SAVE) || (optype == Operation.CREATE)) {
......@@ -809,10 +826,10 @@ public final class NTransaction extends AbstractTransaction implements NTransact
logFile.close();
}
logFile = new RandomAccessFile(logFilePN, "rwd");
logFile = new RandomAccessFile(logFilePN, mode);
garbage();
} else {
logFile = new RandomAccessFile(logFilePN, "rwd");
logFile = new RandomAccessFile(logFilePN, mode);
logFile.setLength(MaxLogFileSize);
current = 1;
......@@ -909,15 +926,8 @@ public final class NTransaction extends AbstractTransaction implements NTransact
}
write(Operation.END);
// AF: Is it needed? Normally the file pointer should already set at
// the right position... To be verified, but not really a big cost.
logFile.seek(current);
logFile.write(buf, 0, count);
// AF: May be we can avoid this second synchronous write, using a
// marker: determination d'un marqueur lie au log courant (date en
// millis par exemple), ecriture du marqueur au debut du log, puis
// ecriture du marqueur apres chaque Operation.COMMIT.
logFile.seek(current -1);
logFile.write(Operation.COMMIT);
......
......@@ -70,6 +70,12 @@ public interface NTransactionMBean extends TransactionMBean {
* @return The size of disk log in Mb.
*/
int getLogFileSize();
/**
* Returns true if every write in the log file is synced to disk.
* @return true if every write in the log file is synced to disk.
*/
boolean isSyncOnWrite();
/**
* Returns the pool size for <code>operation</code> objects, by default 1000.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment