Package eu.stratosphere.core.memory

Examples of eu.stratosphere.core.memory.MemorySegment


    this.writer.close();
   
    // re-collect all memory segments
    ArrayList<MemorySegment> list = new ArrayList<MemorySegment>(this.numSegments)
    for (int i = 0; i < this.numSegments; i++) {
      final MemorySegment m = queue.poll();
      if (m == null) {
        // we get null if the queue is empty. that should not be the case if the reader was properly closed.
        throw new RuntimeException("ChannelWriterOutputView: MemorySegments have been taken from return queue by different actor.");
      }
      list.add(m);
View Full Code Here


  {
    if (current != null) {
      writeSegment(current, posInSegment, false);
    }
   
    final MemorySegment next = this.writer.getNextReturnedSegment();
    this.blockCount++;
    return next;
  }
View Full Code Here

   */
  public MemorySegment getNextReturnedSegment() throws IOException
  {
    try {
      while (true) {
        final MemorySegment next = this.returnBuffers.poll(2000, TimeUnit.MILLISECONDS);
        if (next != null) {
          return next;
        } else {
          if (this.closed) {
            throw new IOException("The writer has been closed.");
View Full Code Here

    final int segmentOffsetI = (i % this.indexEntriesPerSegment) * this.indexEntrySize;
   
    final int bufferNumJ = j / this.indexEntriesPerSegment;
    final int segmentOffsetJ = (j % this.indexEntriesPerSegment) * this.indexEntrySize;
   
    final MemorySegment segI = this.sortIndex.get(bufferNumI);
    final MemorySegment segJ = this.sortIndex.get(bufferNumJ);
   
    int val = MemorySegment.compare(segI, segJ, segmentOffsetI + OFFSET_LEN, segmentOffsetJ + OFFSET_LEN, this.numKeyBytes);
   
    if (val != 0 || this.normalizedKeyFullyDetermines) {
      return this.useNormKeyUninverted ? val : -val;
    }
   
    final long pointerI = segI.getLong(segmentOffsetI);
    final long pointerJ = segJ.getLong(segmentOffsetJ);
   
    return compareRecords(pointerI, pointerJ);
  }
View Full Code Here

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

  public void writeToOutput(final ChannelWriterOutputView output) throws IOException {
    int recordsLeft = this.numRecords;
    int currentMemSeg = 0;
    while (recordsLeft > 0)
    {
      final MemorySegment currentIndexSegment = this.sortIndex.get(currentMemSeg++);
      int offset = 0;
      // check whether we have a full or partially full segment
      if (recordsLeft >= this.indexEntriesPerSegment) {
        // full segment
        for (;offset <= this.lastIndexEntryOffset; offset += this.indexEntrySize) {
          final long pointer = currentIndexSegment.getLong(offset);
          this.recordBuffer.setReadPosition(pointer);
          this.serializer.copy(this.recordBuffer, output);
         
        }
        recordsLeft -= this.indexEntriesPerSegment;
      } else {
        // partially filled segment
        for (; recordsLeft > 0; recordsLeft--, offset += this.indexEntrySize)
        {
          final long pointer = currentIndexSegment.getLong(offset);
          this.recordBuffer.setReadPosition(pointer);
          this.serializer.copy(this.recordBuffer, output);
        }
      }
    }
View Full Code Here

    int currentMemSeg = start / this.indexEntriesPerSegment;
    int offset = (start % this.indexEntriesPerSegment) * this.indexEntrySize;
   
    while (num > 0)
    {
      final MemorySegment currentIndexSegment = this.sortIndex.get(currentMemSeg++);
      // check whether we have a full or partially full segment
      if (num >= this.indexEntriesPerSegment && offset == 0) {
        // full segment
        for (;offset <= this.lastIndexEntryOffset; offset += this.indexEntrySize) {
          final long pointer = currentIndexSegment.getLong(offset);
          this.recordBuffer.setReadPosition(pointer);
          this.serializer.copy(this.recordBuffer, output);
        }
        num -= this.indexEntriesPerSegment;
      } else {
        // partially filled segment
        for (; num > 0 && offset <= this.lastIndexEntryOffset; num--, offset += this.indexEntrySize)
        {
          final long pointer = currentIndexSegment.getLong(offset);
          this.recordBuffer.setReadPosition(pointer);
          this.serializer.copy(this.recordBuffer, output);
        }
      }
      offset = 0;
View Full Code Here

      Set<DefaultMemorySegment> segsForOwner = null;

      // go over all segments
      while (segmentsIterator.hasNext()) {
       
        final MemorySegment seg = segmentsIterator.next();
        if (seg.isFreed()) {
          continue;
        }
       
        final DefaultMemorySegment defSeg = (DefaultMemorySegment) seg;
        final AbstractInvokable owner = defSeg.owner;
View Full Code Here

        readEnds.remove(i);
      }
    }

    // add the current memorySegment and reset this writer
    final MemorySegment current = getCurrentSegment();
    current.putInt(0, getCurrentPositionInSegment());
    fullBuffers.addLast(current);

    // create the reader
    final ReadEnd readEnd;
    if (numBuffersSpilled == 0 && emptyBuffers.size() >= minBuffersForWriteEnd) {
      // read completely from in-memory segments
      readEnd = new ReadEnd(fullBuffers.removeFirst(), emptyBuffers, fullBuffers, null, null, segmentSize, 0);
    } else {
      int toSpill = Math.min(minBuffersForSpilledReadEnd + minBuffersForWriteEnd - emptyBuffers.size(),
        fullBuffers.size());

      // reader reads also segments on disk
      // grab some empty buffers to re-read the first segment
      if (toSpill > 0) {
        // need to spill to make a buffers available
        if (currentWriter == null) {
          currentWriter = ioManager.createBlockChannelWriter(channelEnumerator.next(), emptyBuffers);
        }

        for (int i = 0; i < toSpill; i++) {
          currentWriter.writeBlock(fullBuffers.removeFirst());
        }
        numBuffersSpilled += toSpill;
      }

      // now close the writer and create the reader
      currentWriter.close();
      final BlockChannelReader reader = ioManager.createBlockChannelReader(currentWriter.getChannelID());

      // gather some memory segments to circulate while reading back the data
      final ArrayList<MemorySegment> readSegments = new ArrayList<MemorySegment>();
      try {
        while (readSegments.size() < minBuffersForSpilledReadEnd) {
          readSegments.add(emptyBuffers.take());
        }

        // read the first segment
        MemorySegment firstSeg = readSegments.remove(readSegments.size() - 1);
        reader.readBlock(firstSeg);
        firstSeg = reader.getReturnQueue().take();

        // create the read end reading one less buffer, because the first buffer is already read back
        readEnd = new ReadEnd(firstSeg, emptyBuffers, fullBuffers, reader, readSegments, segmentSize,
View Full Code Here

      return false;
    }

    private void forceDispose(List<MemorySegment> freeMemTarget) throws InterruptedException {
      // add the current segment
      final MemorySegment current = getCurrentSegment();
      clear();
      if (current != null) {
        freeMemTarget.add(current);
      }
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.