Package eu.stratosphere.core.memory

Examples of eu.stratosphere.core.memory.MemorySegment


    this.numBuffers = numBuffers;
    this.bufferSize = bufferSize;

    this.buffers = new ArrayBlockingQueue<MemorySegment>(this.numBuffers);
    for (int i = 0; i < this.numBuffers; i++) {
      this.buffers.add(new MemorySegment(new byte[this.bufferSize]));
    }

    LOG.info(String.format("Initialized global buffer pool with %d buffers (%d bytes each).",
        this.numBuffers, this.bufferSize));
  }
View Full Code Here


      boolean isAsyncRequest = false;

      synchronized (this.buffers) {
        // Return excess buffers to global buffer pool
        while (this.numRequestedBuffers > this.numDesignatedBuffers) {
          final MemorySegment buffer = this.buffers.poll();
          if (buffer == null) {
            break;
          }

          this.globalBufferPool.returnBuffer(buffer);
          this.numRequestedBuffers--;
        }

        // Request buffers from global buffer pool
        while (this.buffers.isEmpty()) {
          if (this.numRequestedBuffers < this.numDesignatedBuffers) {
            final MemorySegment buffer = this.globalBufferPool.requestBuffer();

            if (buffer != null) {
              this.buffers.add(buffer);

              this.numRequestedBuffers++;
View Full Code Here

    @Override
    protected MemorySegment nextSegment(MemorySegment current, int bytesUsed) throws IOException
    {
      finalizeSegment(current, bytesUsed);
     
      final MemorySegment next;
      if (this.writer == null) {
        this.targetList.add(current);
        next = this.memSource.nextSegment();
      } else {
        this.writer.writeBlock(current);
View Full Code Here

      return numSegments;
    }
   
    MemorySegment[] close() throws IOException
    {
      final MemorySegment current = getCurrentSegment();
      if (current == null) {
        throw new IllegalStateException("Illegal State in HashPartition: No current buffer when finilizing build side.");
      }
      finalizeSegment(current, getCurrentPositionInSegment());
      clear();
View Full Code Here

            final int posHashCode = hashCode % initialBucketCount;
            final long pointer = pIter.getPointer();
            // 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];
            insertBucketEntry(part, bucket, bucketInSegmentPos, hashCode, pointer);
          }
        } else {
          this.writeBehindBuffersAvailable--; // we are not in-memory, thus the probe side buffer will grab one wbb.
          if (this.writeBehindBuffers.size() == 0) { // prepareProbePhase always requires one buffer in the writeBehindBuffers-Queue.
View Full Code Here

      final int posHashCode = hash % this.numBuckets;
     
      // get the bucket for the given hash code
      final int bucketArrayPos = posHashCode >> this.bucketsPerSegmentBits;
      final int bucketInSegmentOffset = (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(bucketInSegmentOffset + HEADER_PARTITION_OFFSET);
      final HashPartition<BT, PT> p = this.partitionsBeingBuilt.get(partitionNumber);
     
      // for an in-memory partition, process set the return iterators, else spill the probe records
      if (p.isInMemory()) {
        this.recordComparator.setReference(next);
View Full Code Here

    final int posHashCode = hash % this.numBuckets;
   
    // get the bucket for the given hash code
    final int bucketArrayPos = posHashCode >> this.bucketsPerSegmentBits;
    final int bucketInSegmentOffset = (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(bucketInSegmentOffset + HEADER_PARTITION_OFFSET);
    final HashPartition<BT, PT> p = this.partitionsBeingBuilt.get(partitionNumber);
   
    // for an in-memory partition, process set the return iterators, else spill the probe records
    if (p.isInMemory()) {
      this.recordComparator.setReference(record);
View Full Code Here

        final long pointer = pIter.getPointer();
       
        // 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];
       
        insertBucketEntry(newPart, bucket, bucketInSegmentPos, hashCode, pointer);
      }
    }
    else {
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);
   
    // get the partition descriptor for the bucket
    if (partitionNumber < 0 || partitionNumber >= this.partitionsBeingBuilt.size()) {
      throw new RuntimeException("Error: Hash structures in Hash-Join are corrupt. Invalid partition number for bucket.");
    }
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 short obCount = seg.getShort(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.putShort(segOffset + HEADER_COUNT_OFFSET, (short) (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();
        if (overflowSeg == null) {
          // no memory available to create overflow bucket. we need to spill a partition
          final int spilledPart = spillPartition();
          if (spilledPart == p.getPartitionNumber()) {
            // this bucket is no longer in-memory
            return;
          }
          overflowSeg = getNextBuffer();
          if (overflowSeg == null) {
            throw new RuntimeException("Bug in HybridHashJoin: No memory became available after spilling a partition.");
          }
        }
        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.putShort(overflowBucketOffset + HEADER_COUNT_OFFSET, (short) 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.