Package com.orientechnologies.orient.core.storage.fs

Examples of com.orientechnologies.orient.core.storage.fs.OFile


  public int deleteRecord(final long iPosition) throws IOException {
    acquireExclusiveLock();
    try {

      final long[] pos = getRelativePosition(iPosition);
      final OFile file = files[(int) pos[0]];

      final int recordSize = file.readInt(pos[1]);
      handleHole(iPosition, recordSize);
      return recordSize;

    } finally {
      releaseExclusiveLock();
View Full Code Here


      int holeSize = iRecordSize + RECORD_FIX_SIZE;

      final long timer = OProfiler.getInstance().startChrono();

      long[] pos = getRelativePosition(iRecordOffset);
      final OFile file = files[(int) pos[0]];

      final ODataHoleInfo closestHole = getCloserHole(iRecordOffset, iRecordSize, file, pos);

      OProfiler.getInstance().stopChrono(PROFILER_HOLE_FIND_CLOSER, timer);

      if (closestHole == null)
        // CREATE A NEW ONE
        holeSegment.createHole(iRecordOffset, holeSize);
      else if (closestHole.dataOffset + closestHole.size == iRecordOffset) {
        // IT'S CONSECUTIVE TO ANOTHER HOLE AT THE LEFT: UPDATE LAST ONE
        holeSize += closestHole.size;
        holeSegment.updateHole(closestHole, closestHole.dataOffset, holeSize);

      } else if (holePositionOffset + holeSize == closestHole.dataOffset) {
        // IT'S CONSECUTIVE TO ANOTHER HOLE AT THE RIGHT: UPDATE LAST ONE
        holeSize += closestHole.size;
        holeSegment.updateHole(closestHole, holePositionOffset, holeSize);

      } else {
        // QUITE CLOSE, AUTO-DEFRAG!
        long closestHoleOffset;
        if (iRecordOffset > closestHole.dataOffset)
          closestHoleOffset = (closestHole.dataOffset + closestHole.size) - iRecordOffset;
        else
          closestHoleOffset = closestHole.dataOffset - (iRecordOffset + iRecordSize);

        if (closestHoleOffset < 0) {
          // MOVE THE DATA ON THE RIGHT AND USE ONE HOLE FOR BOTH
          closestHoleOffset *= -1;

          // SEARCH LAST SEGMENT
          long moveFrom = closestHole.dataOffset + closestHole.size;
          int recordSize;

          final long offsetLimit = iRecordOffset;

          final List<long[]> segmentPositions = new ArrayList<long[]>();

          while (moveFrom < offsetLimit) {
            pos = getRelativePosition(moveFrom);

            if (pos[1] >= file.getFilledUpTo())
              // END OF FILE
              break;

            recordSize = file.readInt(pos[1]) + RECORD_FIX_SIZE;

            // SAVE DATA IN ARRAY
            segmentPositions.add(0, new long[] { moveFrom, recordSize });

            moveFrom += recordSize;
View Full Code Here

  }

  private int moveRecord(long iSourcePosition, long iDestinationPosition) throws IOException {
    // GET RECORD TO MOVE
    final long[] pos = getRelativePosition(iSourcePosition);
    final OFile file = files[(int) pos[0]];

    final int recordSize = file.readInt(pos[1]);

    if (recordSize < 0)
      // FOUND HOLE
      return -1;

    final long timer = OProfiler.getInstance().startChrono();

    final short clusterId = file.readShort(pos[1] + OConstants.SIZE_INT);
    final long clusterPosition = file.readLong(pos[1] + OConstants.SIZE_INT + OConstants.SIZE_SHORT);

    final byte[] content = new byte[recordSize];
    file.read(pos[1] + RECORD_FIX_SIZE, content, recordSize);

    if (clusterId > -1) {
      // CHANGE THE POINTMENT OF CLUSTER TO THE NEW POSITION
      final OCluster cluster = storage.getClusterById(clusterId);
      final OPhysicalPosition ppos = cluster.getPhysicalPosition(clusterPosition, new OPhysicalPosition());
View Full Code Here

    return recordSize + RECORD_FIX_SIZE;
  }

  protected void writeRecord(final long[] iFilePosition, final int iClusterSegment, final long iClusterPosition,
      final byte[] iContent) throws IOException {
    final OFile file = files[(int) iFilePosition[0]];

    file.writeInt(iFilePosition[1], iContent.length);
    file.writeShort(iFilePosition[1] + OConstants.SIZE_INT, (short) iClusterSegment);
    file.writeLong(iFilePosition[1] + OConstants.SIZE_INT + OConstants.SIZE_SHORT, iClusterPosition);

    file.write(iFilePosition[1] + RECORD_FIX_SIZE, iContent);
  }
View Full Code Here

  public void create() throws IOException {
    segment.create(START_SIZE);
    super.create();

    final OFile f = segment.getFile();
    if (OGlobalConfiguration.STORAGE_CONFIGURATION_SYNC_ON_UPDATE.getValueAsBoolean())
      f.synch();
  }
View Full Code Here

  }

  @Override
  public void update() throws OSerializationException {
    try {
      final OFile f = segment.getFile();

      if (!f.isOpen())
        return;

      final byte[] buffer = toStream();

      final int len = buffer.length + OBinaryProtocol.SIZE_INT;

      if (len > f.getFilledUpTo())
        f.allocateSpace(len - f.getFilledUpTo());

      f.writeInt(0, buffer.length);
      f.write(OBinaryProtocol.SIZE_INT, buffer);
      if (OGlobalConfiguration.STORAGE_CONFIGURATION_SYNC_ON_UPDATE.getValueAsBoolean())
        f.synch();

    } catch (Exception e) {
      throw new OSerializationException("Error on update storage configuration", e);
    }
  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.storage.fs.OFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.