Package com.orientechnologies.orient.core.id

Examples of com.orientechnologies.orient.core.id.OClusterPosition


            final AddEntryResult addEntryResult = addEntry(recordVersion, entryContent, trackMode);

            updateClusterState(trackMode, 1, addEntryResult.recordsSizeDiff);

            final OClusterPosition clusterPosition = clusterPositionMap.add(addEntryResult.pageIndex, addEntryResult.pagePosition);

            endAtomicOperation(false);

            return createPhysicalPosition(recordType, clusterPosition, addEntryResult.recordVersion);
          } catch (Throwable e) {
            endAtomicOperation(true);
            throw new OStorageException(null, e);
          }
        } else {
          startAtomicOperation();
          try {
            lockTillAtomicOperationCompletes();

            final OClusterPage.TrackMode trackMode = getTrackMode();

            int entrySize = grownContentSize + OIntegerSerializer.INT_SIZE + OByteSerializer.BYTE_SIZE;

            if (useCRC32)
              entrySize += OIntegerSerializer.INT_SIZE;

            int fullEntryPosition = 0;
            byte[] fullEntry = new byte[entrySize];

            fullEntry[fullEntryPosition] = recordType;
            fullEntryPosition++;

            OIntegerSerializer.INSTANCE.serializeNative(content.length, fullEntry, fullEntryPosition);
            fullEntryPosition += OIntegerSerializer.INT_SIZE;

            System.arraycopy(content, 0, fullEntry, fullEntryPosition, content.length);
            fullEntryPosition += grownContentSize;

            if (useCRC32) {
              CRC32 crc32 = new CRC32();
              crc32.update(fullEntry, 0, fullEntryPosition);
              OIntegerSerializer.INSTANCE.serializeNative((int) crc32.getValue(), fullEntry, fullEntryPosition);
            }

            long prevPageRecordPointer = -1;
            long firstPageIndex = -1;
            int firstPagePosition = -1;

            ORecordVersion version = null;

            int from = 0;
            int to = from + (OClusterPage.MAX_RECORD_SIZE - OByteSerializer.BYTE_SIZE - OLongSerializer.LONG_SIZE);

            int recordsSizeDiff = 0;

            do {
              byte[] entryContent = new byte[to - from + OByteSerializer.BYTE_SIZE + OLongSerializer.LONG_SIZE];
              System.arraycopy(fullEntry, from, entryContent, 0, to - from);

              if (from > 0)
                entryContent[entryContent.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE] = 0;
              else
                entryContent[entryContent.length - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE] = 1;

              OLongSerializer.INSTANCE.serializeNative(-1L, entryContent, entryContent.length - OLongSerializer.LONG_SIZE);

              final AddEntryResult addEntryResult = addEntry(recordVersion, entryContent, trackMode);
              recordsSizeDiff += addEntryResult.recordsSizeDiff;

              if (firstPageIndex == -1) {
                firstPageIndex = addEntryResult.pageIndex;
                firstPagePosition = addEntryResult.pagePosition;
                version = addEntryResult.recordVersion;
              }

              long addedPagePointer = createPagePointer(addEntryResult.pageIndex, addEntryResult.pagePosition);
              if (prevPageRecordPointer >= 0) {
                long prevPageIndex = prevPageRecordPointer >>> PAGE_INDEX_OFFSET;
                int prevPageRecordPosition = (int) (prevPageRecordPointer & RECORD_POSITION_MASK);

                final OCacheEntry prevPageCacheEntry = diskCache.load(fileId, prevPageIndex, false);
                prevPageCacheEntry.acquireExclusiveLock();
                try {
                  final OClusterPage prevPage = new OClusterPage(prevPageCacheEntry, false, ODurablePage.TrackMode.FULL);
                  prevPage.setRecordLongValue(prevPageRecordPosition, -OLongSerializer.LONG_SIZE, addedPagePointer);

                  logPageChanges(prevPage, fileId, prevPageIndex, false);

                  prevPageCacheEntry.markDirty();
                } finally {
                  prevPageCacheEntry.releaseExclusiveLock();
                  diskCache.release(prevPageCacheEntry);
                }
              }

              prevPageRecordPointer = addedPagePointer;
              from = to;
              to = to + (OClusterPage.MAX_RECORD_SIZE - OLongSerializer.LONG_SIZE - OByteSerializer.BYTE_SIZE);
              if (to > fullEntry.length)
                to = fullEntry.length;

            } while (from < to);

            updateClusterState(trackMode, 1, recordsSizeDiff);

            OClusterPosition clusterPosition = clusterPositionMap.add(firstPageIndex, firstPagePosition);

            endAtomicOperation(false);

            return createPhysicalPosition(recordType, clusterPosition, version);
          } catch (Throwable e) {
View Full Code Here


  @Override
  public OPhysicalPosition getPhysicalPosition(OPhysicalPosition position) throws IOException {
    acquireSharedLock();
    try {
      OClusterPosition clusterPosition = position.clusterPosition;
      OClusterPositionMapBucket.PositionEntry positionEntry = clusterPositionMap.get(clusterPosition);

      if (positionEntry == null)
        return null;
View Full Code Here

   private void lowerPositions() throws IOException {
     setDataCommandInfo("Retrieve lower positions");

     final int clusterId = channel.readInt();
     final OClusterPosition clusterPosition = channel.readClusterPosition();

     beginResponse();
     try {
       sendOk(clientTxId);
View Full Code Here

   private void floorPositions() throws IOException {
     setDataCommandInfo("Retrieve floor positions");

     final int clusterId = channel.readInt();
     final OClusterPosition clusterPosition = channel.readClusterPosition();

     beginResponse();
     try {
       sendOk(clientTxId);
View Full Code Here

   private void higherPositions() throws IOException {
     setDataCommandInfo("Retrieve higher positions");

     final int clusterId = channel.readInt();
     final OClusterPosition clusterPosition = channel.readClusterPosition();

     beginResponse();
     try {
       sendOk(clientTxId);
View Full Code Here

   private void ceilingPositions() throws IOException {
     setDataCommandInfo("Retrieve ceiling positions");

     final int clusterId = channel.readInt();
     final OClusterPosition clusterPosition = channel.readClusterPosition();

     beginResponse();
     try {
       sendOk(clientTxId);
View Full Code Here

          cacheEntry.acquireExclusiveLock();
          bucket = new OClusterPositionMapBucket(cacheEntry, trackMode);
        }

        final long index = bucket.add(pageIndex, recordPosition);
        final OClusterPosition result = OClusterPositionFactory.INSTANCE.valueOf(index + cacheEntry.getPageIndex()
            * OClusterPositionMapBucket.MAX_ENTRIES);

        logPageChanges(bucket, fileId, cacheEntry.getPageIndex(), isNewPage);
        cacheEntry.markDirty();

View Full Code Here

    System.arraycopy(r.getClusterPosition().toStream(), 0, stream, startPosition + OShortSerializer.SHORT_SIZE, CLUSTER_POS_SIZE);
  }

  public ORecordId deserializeNativeObject(byte[] stream, int startPosition) {
    final int clusterId = OShortSerializer.INSTANCE.deserializeNative(stream, startPosition);
    final OClusterPosition clusterPosition = OClusterPositionFactory.INSTANCE.fromStream(stream, startPosition
        + OShortSerializer.SHORT_SIZE);

    return new ORecordId(clusterId, clusterPosition);
  }
View Full Code Here

  }

  @Override
  public OIdentifiable deserializeFromDirectMemoryObject(ODirectMemoryPointer pointer, long offset) {
    final int clusterId = OShortSerializer.INSTANCE.deserializeFromDirectMemory(pointer, offset);
    OClusterPosition clusterPosition = OClusterPositionFactory.INSTANCE.fromStream(pointer.get(
        offset + OShortSerializer.SHORT_SIZE, CLUSTER_POS_SIZE));

    return new ORecordId(clusterId, clusterPosition);
  }
View Full Code Here

  public void queryWithTwoRidInWhere() {
    int clusterId = database.getClusterIdByName("profile");

    List<OClusterPosition> positions = getValidPositions(clusterId);

    final OClusterPosition minPos;
    final OClusterPosition maxPos;
    if (positions.get(5).compareTo(positions.get(25)) > 0) {
      minPos = positions.get(25);
      maxPos = positions.get(5);
    } else {
      minPos = positions.get(5);
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.id.OClusterPosition

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.