Examples of OFile


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

      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;

            int recordContentSize = file.readInt(pos[1]);
            if (recordContentSize < 0)
              // FOUND HOLE
              break;

            recordSize = recordContentSize + RECORD_FIX_SIZE;
View Full Code Here

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

  }

  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

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

          if (files[i] != null)
            files[i].delete();
        }

        // UPDATE FILE STRUCTURE
        final OFile f = files[0];
        files = new OFile[1];
        files[0] = f;

        // UPDATE CONFIGURATION
        final OStorageFileConfiguration fileConfig = config.infoFiles[0];
View Full Code Here

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

   * @return a pair file-id/file-pos
   * @throws IOException
   */
  protected long[] allocateSpace(final int iRecordSize) throws IOException {
    // IT'S PREFEREABLE TO FIND SPACE WITHOUT ENLARGE ANY FILES: FIND THE FIRST FILE WITH FREE SPACE TO USE
    OFile file;
    for (int i = 0; i < files.length; ++i) {
      file = files[i];

      if (file.getFreeSpace() >= iRecordSize)
        // FOUND: RETURN THIS OFFSET
        return new long[] { i, file.allocateSpace(iRecordSize) };
    }

    // NOT FOUND: CHECK IF CAN OVERSIZE SOME FILES
    for (int i = 0; i < files.length; ++i) {
      file = files[i];

      if (file.canOversize(iRecordSize)) {
        // FOUND SPACE: ENLARGE IT
        return new long[] { i, file.allocateSpace(iRecordSize) };
      }
    }

    // TRY TO CREATE A NEW FILE
    if (maxSize > 0 && getSize() >= maxSize)
      // OUT OF MAX SIZE
      throw new OStorageException("Unable to allocate the requested space of " + iRecordSize
          + " bytes because the segment is full: max-Size=" + maxSize + ", currentSize=" + getFilledUpTo());

    // COPY THE OLD ARRAY TO THE NEW ONE
    OFile[] newFiles = new OFile[files.length + 1];
    for (int i = 0; i < files.length; ++i)
      newFiles[i] = files[i];
    files = newFiles;

    // CREATE THE NEW FILE AND PUT IT AS LAST OF THE ARRAY
    file = createNewFile();
    file.allocateSpace(iRecordSize);

    config.root.update();

    return new long[] { files.length - 1, 0 };
  }
View Full Code Here

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

  }

  private OFile createNewFile() throws IOException {
    final int num = files.length - 1;

    final OFile file = OFileFactory.create(type, storage.getStoragePath() + "/" + name + "." + num + fileExtension,
        storage.getMode());
    file.setMaxSize((int) OFileUtils.getSizeAsNumber(config.root.fileTemplate.fileMaxSize));
    file.create(fileStartSize);
    files[num] = file;

    addInfoFileConfigEntry(file);

    return file;
View Full Code Here

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

    acquireSharedLock();
    try {
      final long[] pos = getRelativePosition(iPosition);

      final OFile file = files[(int) pos[0]];
      long p = pos[1];

      iPPosition.dataSegment = file.readShort(p);
      iPPosition.dataPosition = file.readLong(p += OConstants.SIZE_SHORT);
      iPPosition.type = file.readByte(p += OConstants.SIZE_LONG);
      iPPosition.version = file.readInt(p += OConstants.SIZE_BYTE);
      return iPPosition;

    } finally {
      releaseSharedLock();
    }
View Full Code Here

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

    acquireSharedLock();
    try {
      final long[] pos = getRelativePosition(iPosition);

      final OFile file = files[(int) pos[0]];
      long p = pos[1];

      file.writeShort(p, (short) iDataId);
      file.writeLong(p += OConstants.SIZE_SHORT, iDataPosition);
      file.writeByte(p += OConstants.SIZE_LONG, iRecordType);

    } finally {
      releaseSharedLock();
    }
  }
View Full Code Here

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

    acquireSharedLock();
    try {
      final long[] pos = getRelativePosition(iPosition);

      final OFile file = files[(int) pos[0]];
      long p = pos[1];

      file.writeLong(p += OConstants.SIZE_SHORT, iDataPosition);

    } finally {
      releaseSharedLock();
    }
  }
View Full Code Here

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

    final long position = iPosition * RECORD_SIZE;

    acquireSharedLock();
    try {
      final long[] pos = getRelativePosition(position);
      final OFile file = files[(int) pos[0]];
      long p = pos[1];

      // SAVE THE OLD DATA AND RETRIEVE THEM TO THE CALLER
      iPPosition.dataSegment = file.readShort(p);
      iPPosition.dataPosition = file.readLong(p += OConstants.SIZE_SHORT);
      iPPosition.type = file.readByte(p += OConstants.SIZE_LONG);
      iPPosition.version = file.readInt(p += OConstants.SIZE_BYTE);

      holeSegment.pushPosition(position);

      // SET VERSION = -1
      file.writeInt(p, -1);

      if (iPosition == beginOffsetData) {
        if (getEntries() == 0)
          beginOffsetData = -1;
        else {
View Full Code Here

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

        // NO HOLES FOUND: ALLOCATE MORE SPACE
        pos = allocateSpace(RECORD_SIZE);
        offset = getAbsolutePosition(pos);
      }

      OFile file = files[(int) pos[0]];
      long p = pos[1];

      file.writeShort(p, (short) iDataSegmentId);
      file.writeLong(p += OConstants.SIZE_SHORT, iPosition);
      file.writeByte(p += OConstants.SIZE_LONG, iRecordType);
      file.writeInt(p += OConstants.SIZE_BYTE, 0);

      final long returnedPosition = offset / RECORD_SIZE;

      if (returnedPosition < beginOffsetData || beginOffsetData == -1) {
        // UPDATE END OF DATA
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.