Exemple #1
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void Reset()
 {
     // Create a new segment for the previously written records only if we
     // are not already in the reset mode
     if (!inReset)
     {
         if (fileCache.isActive)
         {
             fileCache.CreateInDiskSegment();
         }
         else
         {
             memCache.CreateInMemorySegment();
         }
     }
     inReset = true;
     // Reset the segments to the correct position from where the next read
     // should begin.
     for (int i = 0; i < segmentList.Count; i++)
     {
         Merger.Segment <K, V> s = segmentList[i];
         if (s.InMemory())
         {
             int offset = (i == 0) ? firstSegmentOffset : 0;
             s.GetReader().Reset(offset);
         }
         else
         {
             s.CloseReader();
             if (i == 0)
             {
                 s.ReinitReader(firstSegmentOffset);
                 s.GetReader().DisableChecksumValidation();
             }
         }
     }
     currentKVOffset  = firstSegmentOffset;
     nextKVOffset     = -1;
     readSegmentIndex = 0;
     hasMore          = false;
     lastSegmentEOF   = false;
     Log.Debug("Reset - First segment offset is " + firstSegmentOffset + " Segment List Size is "
               + segmentList.Count);
 }
Exemple #2
0
 /// <exception cref="System.IO.IOException"/>
 public virtual bool HasNext()
 {
     if (lastSegmentEOF)
     {
         return(false);
     }
     // We read the next KV from the cache to decide if there is any left.
     // Since hasNext can be called several times before the actual call to
     // next(), we use hasMore to avoid extra reads. hasMore is set to false
     // when the user actually consumes this record in next()
     if (hasMore)
     {
         return(true);
     }
     Merger.Segment <K, V> seg = segmentList[readSegmentIndex];
     // Mark the current position. This would be set to currentKVOffset
     // when the user consumes this record in next().
     nextKVOffset = (int)seg.GetActualPosition();
     if (seg.NextRawKey())
     {
         currentKey = seg.GetKey();
         seg.GetValue(currentValue);
         hasMore = true;
         return(true);
     }
     else
     {
         if (!seg.InMemory())
         {
             seg.CloseReader();
         }
     }
     // If this is the last segment, mark the lastSegmentEOF flag and return
     if (readSegmentIndex == segmentList.Count - 1)
     {
         nextKVOffset   = -1;
         lastSegmentEOF = true;
         return(false);
     }
     nextKVOffset = 0;
     readSegmentIndex++;
     Merger.Segment <K, V> nextSegment = segmentList[readSegmentIndex];
     // We possibly are moving from a memory segment to a disk segment.
     // Reset so that we do not corrupt the in-memory segment buffer.
     // See HADOOP-5494
     if (!nextSegment.InMemory())
     {
         currentValue.Reset(currentDiskValue.GetData(), currentDiskValue.GetLength());
         nextSegment.Init(null);
     }
     if (nextSegment.NextRawKey())
     {
         currentKey = nextSegment.GetKey();
         nextSegment.GetValue(currentValue);
         hasMore = true;
         return(true);
     }
     else
     {
         throw new IOException("New segment did not have even one K/V");
     }
 }