private void writeToLockFile(int lockSignal) {
   ByteArrayBuffer lockBuffer = newLockFileBuffer();
   lockBuffer.writeInt(lockSignal);
   lockBuffer.writeInt(lockSignal);
   write(_lockFile, lockBuffer);
   _lockFile.sync();
 }
  @Override
  public void applySlotChanges(
      Visitable<SlotChange> slotChangeTree, int slotChangeCount, Slot reservedSlot) {
    if (slotChangeCount < 1) {
      return;
    }

    Runnable commitHook = _container.commitHook();
    flushDatabaseFile();

    ensureLogAndLock();
    int length = transactionLogSlotLength(slotChangeCount);
    ByteArrayBuffer logBuffer = new ByteArrayBuffer(length);
    logBuffer.writeInt(length);
    logBuffer.writeInt(slotChangeCount);

    appendSlotChanges(logBuffer, slotChangeTree);
    write(_logFile, logBuffer);
    _logFile.sync();

    writeToLockFile(LOCK_INT);

    writeSlots(slotChangeTree);
    commitHook.run();
    flushDatabaseFile();
    writeToLockFile(0);
  }
Exemplo n.º 3
0
 public Slot debugReadPointerSlot(int id) {
   if (Deploy.debug) {
     readBytes(_pointerIo._buffer, id, Const4.POINTER_LENGTH);
     _pointerIo.seek(0);
     _pointerIo.readBegin(Const4.YAPPOINTER);
     int debugAddress = _pointerIo.readInt();
     int debugLength = _pointerIo.readInt();
     _pointerIo.readEnd();
     return new Slot(debugAddress, debugLength);
   }
   return null;
 }
 private boolean lockFileSignalsInterruptedTransaction() {
   openLockFile();
   ByteArrayBuffer buffer = newLockFileBuffer();
   read(_lockFile, buffer);
   for (int i = 0; i < 2; i++) {
     int checkInt = buffer.readInt();
     if (checkInt != LOCK_INT) {
       closeLockFile();
       return false;
     }
   }
   closeLockFile();
   return true;
 }
Exemplo n.º 5
0
  public ByteArrayBuffer readBufferBySlot(Slot slot) {
    if (Slot.isNull(slot)) {
      return null;
    }

    if (DTrace.enabled) {
      DTrace.READ_SLOT.logLength(slot.address(), slot.length());
    }

    ByteArrayBuffer buffer = new ByteArrayBuffer(slot.length());

    buffer.readEncrypt(this, slot.address());
    return buffer;
  }
 public void completeInterruptedTransaction(int transactionId1, int transactionId2) {
   if (!File4.exists(lockFileName(_fileName))) {
     return;
   }
   if (!lockFileSignalsInterruptedTransaction()) {
     return;
   }
   ByteArrayBuffer buffer = new ByteArrayBuffer(Const4.INT_LENGTH);
   openLogFile();
   read(_logFile, buffer);
   int length = buffer.readInt();
   if (length > 0) {
     buffer = new ByteArrayBuffer(length);
     read(_logFile, buffer);
     buffer.incrementOffset(Const4.INT_LENGTH);
     readWriteSlotChanges(buffer);
   }
   deleteLockFile();
   closeLogFile();
   deleteLogFile();
 }
Exemplo n.º 7
0
 public void writePointer(int id, Slot slot) {
   if (DTrace.enabled) {
     DTrace.WRITE_POINTER.log(id);
     DTrace.WRITE_POINTER.logLength(slot);
   }
   _pointerIo.seek(0);
   if (Deploy.debug) {
     _pointerIo.writeBegin(Const4.YAPPOINTER);
   }
   _pointerIo.writeInt(slot.address());
   _pointerIo.writeInt(slot.length());
   if (Deploy.debug) {
     _pointerIo.writeEnd();
   }
   if (Debug4.xbytes) {
     _pointerIo.checkXBytes(false);
   }
   writeBytes(_pointerIo, id, 0);
 }
 private void write(Bin storage, ByteArrayBuffer buffer) {
   storage.write(0, buffer._buffer, buffer.length());
 }
 private void read(Bin storage, ByteArrayBuffer buffer) {
   storage.read(0, buffer._buffer, buffer.length());
 }