Package eu.stratosphere.core.memory

Examples of eu.stratosphere.core.memory.MemorySegment


    final int segmentOffsetI = (i % this.recordsPerSegment) * this.recordSize;
   
    final int bufferNumJ = j / this.recordsPerSegment;
    final int segmentOffsetJ = (j % this.recordsPerSegment) * this.recordSize;
   
    final MemorySegment segI = this.sortBuffer.get(bufferNumI);
    final MemorySegment segJ = this.sortBuffer.get(bufferNumJ);
   
    int val = MemorySegment.compare(segI, segJ, segmentOffsetI, segmentOffsetJ, this.numKeyBytes);
    return this.useNormKeyUninverted ? val : -val;
  }
View Full Code Here


    final int segmentOffsetI = (i % this.recordsPerSegment) * this.recordSize;
   
    final int bufferNumJ = j / this.recordsPerSegment;
    final int segmentOffsetJ = (j % this.recordsPerSegment) * this.recordSize;
   
    final MemorySegment segI = this.sortBuffer.get(bufferNumI);
    final MemorySegment segJ = this.sortBuffer.get(bufferNumJ);
   
    MemorySegment.swapBytes(segI, segJ, this.swapBuffer, segmentOffsetI, segmentOffsetJ, this.recordSize);
  }
View Full Code Here

    final int recordsPerSegment = this.recordsPerSegment;
    int recordsLeft = this.numRecords;
    int currentMemSeg = 0;
   
    while (recordsLeft > 0) {
      final MemorySegment currentIndexSegment = this.sortBuffer.get(currentMemSeg++);
      inView.set(currentIndexSegment, 0);
     
      // check whether we have a full or partially full segment
      if (recordsLeft >= recordsPerSegment) {
        // full segment
View Full Code Here

    final int recordsPerSegment = this.recordsPerSegment;
    int currentMemSeg = start / recordsPerSegment;
    int offset = (start % recordsPerSegment) * this.recordSize;
   
    while (num > 0) {
      final MemorySegment currentIndexSegment = this.sortBuffer.get(currentMemSeg++);
      inView.set(currentIndexSegment, offset);
     
      // check whether we have a full or partially full segment
      if (num >= recordsPerSegment && offset == 0) {
        // full segment
View Full Code Here

   *
   * @param numberOfSegments allocation count
   */
  public void allocateSegments(int numberOfSegments) {
    while(getBlockCount() < numberOfSegments) {
      MemorySegment next = this.availableMemory.nextSegment();
      if(next != null) {
        this.partitionPages.add(next);
      } else {
        return;
      }
View Full Code Here

    }
   

    @Override
    protected MemorySegment nextSegment(MemorySegment current, int bytesUsed) throws IOException {
      MemorySegment next = this.memSource.nextSegment();
      if(next == null) {
        throw new EOFException();
      }
      this.pages.add(next);
     
View Full Code Here

    final int posHashCode = hashCode % this.numBuckets;
   
    // get the bucket for the given hash code
    final int bucketArrayPos = posHashCode >>> this.bucketsPerSegmentBits;
    final int bucketInSegmentPos = (posHashCode & this.bucketsPerSegmentMask) << NUM_INTRA_BUCKET_BITS;
    final MemorySegment bucket = this.buckets[bucketArrayPos];
   
    // get the basic characteristics of the bucket
    final int partitionNumber = bucket.get(bucketInSegmentPos + HEADER_PARTITION_OFFSET);
    final InMemoryPartition<T> p = this.partitions.get(partitionNumber);
   
   
    long pointer;
    try {
View Full Code Here

  public void insertOrReplaceRecord(T record, T tempHolder) throws IOException {
    final int searchHashCode = hash(this.buildSideComparator.hash(record));
    final int posHashCode = searchHashCode % this.numBuckets;
   
    // get the bucket for the given hash code
    MemorySegment originalBucket = this.buckets[posHashCode >> this.bucketsPerSegmentBits];
    int originalBucketOffset = (posHashCode & this.bucketsPerSegmentMask) << NUM_INTRA_BUCKET_BITS;
    MemorySegment bucket = originalBucket;
    int bucketInSegmentOffset = originalBucketOffset;
   
    // get the basic characteristics of the bucket
    final int partitionNumber = bucket.get(bucketInSegmentOffset + HEADER_PARTITION_OFFSET);
    final InMemoryPartition<T> partition = this.partitions.get(partitionNumber);
    final MemorySegment[] overflowSegments = partition.overflowSegments;
   
    this.buildSideComparator.setReference(record);
   
    int countInSegment = bucket.getInt(bucketInSegmentOffset + HEADER_COUNT_OFFSET);
    int numInSegment = 0;
    int posInSegment = bucketInSegmentOffset + BUCKET_HEADER_LENGTH;
   
    long currentForwardPointer = BUCKET_FORWARD_POINTER_NOT_SET;

    // loop over all segments that are involved in the bucket (original bucket plus overflow buckets)
    while (true) {
     
      while (numInSegment < countInSegment) {
       
        final int thisCode = bucket.getInt(posInSegment);
        posInSegment += HASH_CODE_LEN;
         
        // check if the hash code matches
        if (thisCode == searchHashCode) {
          // get the pointer to the pair
          final int pointerOffset = bucketInSegmentOffset + BUCKET_POINTER_START_OFFSET + (numInSegment * POINTER_LEN);
          final long pointer = bucket.getLong(pointerOffset);
          numInSegment++;
         
          // deserialize the key to check whether it is really equal, or whether we had only a hash collision
          try {
            partition.readRecordAt(pointer, tempHolder);
            if (this.buildSideComparator.equalToReference(tempHolder)) {
              long newPointer = partition.appendRecord(record);
              bucket.putLong(pointerOffset, newPointer);
              partition.setCompaction(false);
              if((newPointer >> this.pageSizeInBits) > this.compactionMemory.getBlockCount()) {
                this.compactionMemory.allocateSegments((int)(newPointer >> this.pageSizeInBits));
              }
              return;
            }
          } catch (EOFException e) {
            // system is out of memory so we attempt to reclaim memory with a copy compact run
            long newPointer;
            try {
              compactPartition(partition.getPartitionNumber());
              // retry append
              newPointer = this.partitions.get(partitionNumber).appendRecord(record);
            } catch (EOFException ex) {
              throw new RuntimeException("Memory ran out. Compaction failed. numPartitions: " + this.partitions.size() +
                  " minPartition: " + getMinPartition() +
                  " maxPartition: " + getMaxPartition() +
                  " bucketSize: " + this.buckets.length +
                  " Message: " + ex.getMessage());
            } catch (IndexOutOfBoundsException ex) {
              throw new RuntimeException("Memory ran out. Compaction failed. numPartitions: " + this.partitions.size() +
                  " minPartition: " + getMinPartition() +
                  " maxPartition: " + getMaxPartition() +
                  " bucketSize: " + this.buckets.length +
                  " Message: " + ex.getMessage());
            }
            bucket.putLong(pointerOffset, newPointer);
            return;
          } catch (IndexOutOfBoundsException e) {
            // system is out of memory so we attempt to reclaim memory with a copy compact run
            long newPointer;
            try {
              compactPartition(partition.getPartitionNumber());
              // retry append
              newPointer = this.partitions.get(partitionNumber).appendRecord(record);
            } catch (EOFException ex) {
              throw new RuntimeException("Memory ran out. Compaction failed. numPartitions: " + this.partitions.size() +
                  " minPartition: " + getMinPartition() +
                  " maxPartition: " + getMaxPartition() +
                  " bucketSize: " + this.buckets.length +
                  " Message: " + ex.getMessage());
            } catch (IndexOutOfBoundsException ex) {
              throw new RuntimeException("Memory ran out. Compaction failed. numPartitions: " + this.partitions.size() +
                  " minPartition: " + getMinPartition() +
                  " maxPartition: " + getMaxPartition() +
                  " bucketSize: " + this.buckets.length +
                  " Message: " + ex.getMessage());
            }
            bucket.putLong(pointerOffset, newPointer);
            return;
          } catch (IOException e) {
            throw new RuntimeException("Error deserializing record from the hashtable: " + e.getMessage(), e);
          }
        }
        else {
          numInSegment++;
        }
      }
     
      // this segment is done. check if there is another chained bucket
      long newForwardPointer = bucket.getLong(bucketInSegmentOffset + HEADER_FORWARD_OFFSET);
      if (newForwardPointer == BUCKET_FORWARD_POINTER_NOT_SET) {
        // nothing found. append and insert
        long pointer = partition.appendRecord(record);
        insertBucketEntryFromSearch(partition, originalBucket, bucket, originalBucketOffset, bucketInSegmentOffset, countInSegment, currentForwardPointer, searchHashCode, pointer);
        if((pointer >> this.pageSizeInBits) > this.compactionMemory.getBlockCount()) {
          this.compactionMemory.allocateSegments((int)(pointer >> this.pageSizeInBits));
        }
        return;
      }
     
      final int overflowSegNum = (int) (newForwardPointer >>> 32);
      bucket = overflowSegments[overflowSegNum];
      bucketInSegmentOffset = (int) (newForwardPointer & 0xffffffff);
      countInSegment = bucket.getInt(bucketInSegmentOffset + HEADER_COUNT_OFFSET);
      posInSegment = bucketInSegmentOffset + BUCKET_HEADER_LENGTH;
      numInSegment = 0;
      currentForwardPointer = newForwardPointer;
    }
  }
View Full Code Here

      if (originalForwardPointer != BUCKET_FORWARD_POINTER_NOT_SET) {
       
        // forward pointer set
        final int overflowSegNum = (int) (originalForwardPointer >>> 32);
        final int segOffset = (int) (originalForwardPointer & 0xffffffff);
        final MemorySegment seg = p.overflowSegments[overflowSegNum];
       
        final int obCount = seg.getInt(segOffset + HEADER_COUNT_OFFSET);
       
        // check if there is space in this overflow bucket
        if (obCount < NUM_ENTRIES_PER_BUCKET) {
          // space in this bucket and we are done
          seg.putInt(segOffset + BUCKET_HEADER_LENGTH + (obCount * HASH_CODE_LEN), hashCode)// hash code
          seg.putLong(segOffset + BUCKET_POINTER_START_OFFSET + (obCount * POINTER_LEN), pointer); // pointer
          seg.putInt(segOffset + HEADER_COUNT_OFFSET, obCount + 1); // update count
          return;
        }
        else {
          // no space here, we need a new bucket. this current overflow bucket will be the
          // target of the new overflow bucket
          forwardForNewBucket = originalForwardPointer;
        }
      }
      else {
        // no overflow bucket yet, so we need a first one
        forwardForNewBucket = BUCKET_FORWARD_POINTER_NOT_SET;
      }
     
      // we need a new overflow bucket
      MemorySegment overflowSeg;
      final int overflowBucketNum;
      final int overflowBucketOffset;
     
      // first, see if there is space for an overflow bucket remaining in the last overflow segment
      if (p.nextOverflowBucket == 0) {
        // no space left in last bucket, or no bucket yet, so create an overflow segment
        overflowSeg = getNextBuffer();
        overflowBucketOffset = 0;
        overflowBucketNum = p.numOverflowSegments;
       
        // add the new overflow segment
        if (p.overflowSegments.length <= p.numOverflowSegments) {
          MemorySegment[] newSegsArray = new MemorySegment[p.overflowSegments.length * 2];
          System.arraycopy(p.overflowSegments, 0, newSegsArray, 0, p.overflowSegments.length);
          p.overflowSegments = newSegsArray;
        }
        p.overflowSegments[p.numOverflowSegments] = overflowSeg;
        p.numOverflowSegments++;
      }
      else {
        // there is space in the last overflow bucket
        overflowBucketNum = p.numOverflowSegments - 1;
        overflowSeg = p.overflowSegments[overflowBucketNum];
        overflowBucketOffset = p.nextOverflowBucket << NUM_INTRA_BUCKET_BITS;
      }
     
      // next overflow bucket is one ahead. if the segment is full, the next will be at the beginning
      // of a new segment
      p.nextOverflowBucket = (p.nextOverflowBucket == this.bucketsPerSegmentMask ? 0 : p.nextOverflowBucket + 1);
     
      // insert the new overflow bucket in the chain of buckets
      // 1) set the old forward pointer
      // 2) let the bucket in the main table point to this one
      overflowSeg.putLong(overflowBucketOffset + HEADER_FORWARD_OFFSET, forwardForNewBucket);
      final long pointerToNewBucket = (((long) overflowBucketNum) << 32) | ((long) overflowBucketOffset);
      bucket.putLong(bucketInSegmentPos + HEADER_FORWARD_OFFSET, pointerToNewBucket);
     
      // finally, insert the values into the overflow buckets
      overflowSeg.putInt(overflowBucketOffset + BUCKET_HEADER_LENGTH, hashCode)// hash code
      overflowSeg.putLong(overflowBucketOffset + BUCKET_POINTER_START_OFFSET, pointer); // pointer
     
      // set the count to one
      overflowSeg.putInt(overflowBucketOffset + HEADER_COUNT_OFFSET, 1);
    }
  }
View Full Code Here

      currentBucket.putLong(currentBucketOffset + BUCKET_POINTER_START_OFFSET + (countInCurrentBucket * POINTER_LEN), pointer); // pointer
      currentBucket.putInt(currentBucketOffset + HEADER_COUNT_OFFSET, countInCurrentBucket + 1); // update count
    }
    else {
      // we need a new overflow bucket
      MemorySegment overflowSeg;
      final int overflowBucketNum;
      final int overflowBucketOffset;
     
      // first, see if there is space for an overflow bucket remaining in the last overflow segment
      if (partition.nextOverflowBucket == 0) {
        // no space left in last bucket, or no bucket yet, so create an overflow segment
        overflowSeg = getNextBuffer();
        overflowBucketOffset = 0;
        overflowBucketNum = partition.numOverflowSegments;
       
        // add the new overflow segment
        if (partition.overflowSegments.length <= partition.numOverflowSegments) {
          MemorySegment[] newSegsArray = new MemorySegment[partition.overflowSegments.length * 2];
          System.arraycopy(partition.overflowSegments, 0, newSegsArray, 0, partition.overflowSegments.length);
          partition.overflowSegments = newSegsArray;
        }
        partition.overflowSegments[partition.numOverflowSegments] = overflowSeg;
        partition.numOverflowSegments++;
      }
      else {
        // there is space in the last overflow segment
        overflowBucketNum = partition.numOverflowSegments - 1;
        overflowSeg = partition.overflowSegments[overflowBucketNum];
        overflowBucketOffset = partition.nextOverflowBucket << NUM_INTRA_BUCKET_BITS;
      }
     
      // next overflow bucket is one ahead. if the segment is full, the next will be at the beginning
      // of a new segment
      partition.nextOverflowBucket = (partition.nextOverflowBucket == this.bucketsPerSegmentMask ? 0 : partition.nextOverflowBucket + 1);
     
      // insert the new overflow bucket in the chain of buckets
      // 1) set the old forward pointer
      // 2) let the bucket in the main table point to this one
      overflowSeg.putLong(overflowBucketOffset + HEADER_FORWARD_OFFSET, currentForwardPointer);
      final long pointerToNewBucket = (((long) overflowBucketNum) << 32) | ((long) overflowBucketOffset);
      originalBucket.putLong(originalBucketOffset + HEADER_FORWARD_OFFSET, pointerToNewBucket);
     
      // finally, insert the values into the overflow buckets
      overflowSeg.putInt(overflowBucketOffset + BUCKET_HEADER_LENGTH, hashCode)// hash code
      overflowSeg.putLong(overflowBucketOffset + BUCKET_POINTER_START_OFFSET, pointer); // pointer
     
      // set the count to one
      overflowSeg.putInt(overflowBucketOffset + HEADER_COUNT_OFFSET, 1);
    }
  }
View Full Code Here

TOP

Related Classes of eu.stratosphere.core.memory.MemorySegment

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.