public static Operation alloc(int type, String dirName, String name, byte[] value) { Operation op = null; try { op = (Operation) pool.allocElement(); } catch (Exception exc) { return new Operation(type, dirName, name, value); } op.type = type; op.dirName = dirName; op.name = name; op.value = value; return op; }
public final void initRepository() throws IOException { Operation.initPool(CLEANUP_THRESHOLD_OPERATION); // Search for log files: plog then clog, reads it, then apply all // committed operation, finally deletes it. lockFile = new File(dir, LOCK); if (! lockFile.createNewFile()) { logmon.log(BasicLevel.FATAL, "ATransaction.init(): Either the server is already running, " + "either you have to remove lock file: " + lockFile.getAbsolutePath()); throw new IOException("Transaction already running."); } lockFile.deleteOnExit(); logFilePN = new File(dir, LOG); plogFilePN = new File(dir, PLOG); Hashtable tempLog = new Hashtable(); restart(tempLog, logFilePN); restart(tempLog, plogFilePN); commit(tempLog); plogFilePN.delete(); logFilePN.delete(); clog = new Hashtable(CLEANUP_THRESHOLD_OPERATION / 2); plog = new Hashtable(CLEANUP_THRESHOLD_OPERATION / 2); baos = new ByteArrayOutputStream(10 * Kb); dos = new DataOutputStream(baos); newLogFile(); lock = new Object(); garbage = false; gThread = new Thread(this, "TGarbage"); gThread.start(); }
if (op != null) op.free();
public static Operation alloc(int type, String dirName, String name) { return alloc(type, dirName, name, null); }
if (op != null) op.free();
public static Operation alloc(int type, String dirName, String name) { return alloc(type, dirName, name, null); }
"ATransaction, can't delete " + file.getCanonicalPath()); op.free();
public void delete(String dirName, String name) { if (phase == RUN) { // We are during a transaction mark the object deleted in the log. Object key = OperationKey.newKey(dirName, name); log.put(key, Operation.alloc(Operation.DELETE, dirName, name)); } else { File file; if (dirName == null) { file = new File(dir, name); file.delete(); } else { File parentDir = new File(dir, dirName); file = new File(parentDir, name); file.delete(); deleteDir(parentDir); } } }
public final void initRepository() throws IOException { Operation.initPool(CLEANUP_THRESHOLD_OPERATION); // Search for log files: plog then clog, reads it, then apply all // committed operation, finally deletes it. lockFile = new File(dir, LOCK); if (! lockFile.createNewFile()) { logmon.log(BasicLevel.FATAL, "ATransaction.init(): Either the server is already running, " + "either you have to remove lock file: " + lockFile.getAbsolutePath()); throw new IOException("Transaction already running."); } lockFile.deleteOnExit(); logFilePN = new File(dir, LOG); plogFilePN = new File(dir, PLOG); Hashtable tempLog = new Hashtable(); restart(tempLog, logFilePN); restart(tempLog, plogFilePN); commit(tempLog); plogFilePN.delete(); logFilePN.delete(); clog = new Hashtable(CLEANUP_THRESHOLD_OPERATION / 2); plog = new Hashtable(CLEANUP_THRESHOLD_OPERATION / 2); baos = new ByteArrayOutputStream(10 * Kb); dos = new DataOutputStream(baos); newLogFile(); lock = new Object(); garbage = false; gThread = new Thread(this, "TGarbage"); gThread.start(); }
public static Operation alloc(int type, String dirName, String name, byte[] value) { Operation op = null; try { op = (Operation) pool.allocElement(); } catch (Exception exc) { return new Operation(type, dirName, name, value); } op.type = type; op.dirName = dirName; op.name = name; op.value = value; return op; }
public final void delete(String dirName, String name) { if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "NTransaction, delete(" + dirName + ", " + name + ")"); Object key = OperationKey.newKey(dirName, name); Hashtable log = ((Context) perThreadContext.get()).getLog(); Operation op = Operation.alloc(Operation.DELETE, dirName, name); Operation old = (Operation) log.put(key, op); if (old != null) { if (old.type == Operation.CREATE) op.type = Operation.NOOP; old.free(); } }
"ATransaction, can't delete " + file.getCanonicalPath()); op.free();
public void delete(String dirName, String name) { if (phase == RUN) { // We are during a transaction mark the object deleted in the log. Object key = OperationKey.newKey(dirName, name); log.put(key, Operation.alloc(Operation.DELETE, dirName, name)); } else { File file; if (dirName == null) { file = new File(dir, name); file.delete(); } else { File parentDir = new File(dir, dirName); file = new File(parentDir, name); file.delete(); deleteDir(parentDir); } } }
Operation.initPool(LogThresholdOperation);
public final void delete(String dirName, String name) { if (logmon.isLoggable(BasicLevel.DEBUG)) logmon.log(BasicLevel.DEBUG, "NTransaction, delete(" + dirName + ", " + name + ")"); Object key = OperationKey.newKey(dirName, name); Hashtable<Object, Operation> log = perThreadContext.get().getLog(); Operation op = Operation.alloc(Operation.DELETE, dirName, name); Operation old = log.put(key, op); if (old != null) { if (old.type == Operation.CREATE) op.type = Operation.NOOP; old.free(); } }