Skip to content

Commit

Permalink
Fixing segmentOffset access (#100)
Browse files Browse the repository at this point in the history
* Fixing computation of segment offset

* clean up
  • Loading branch information
badrishc committed Feb 26, 2019
1 parent f970f4e commit 35e8732
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
32 changes: 16 additions & 16 deletions cs/src/core/Allocator/AllocatorBase.cs
Expand Up @@ -343,9 +343,8 @@ public unsafe abstract class AllocatorBase<Key, Value> : IDisposable
/// <summary>
/// Clear page
/// </summary>
/// <param name="page"></param>
/// <param name="pageZero"></param>
protected abstract void ClearPage(int page, bool pageZero);
/// <param name="page">Page number to be cleared</param>
protected abstract void ClearPage(long page);
/// <summary>
/// Write page (async)
/// </summary>
Expand Down Expand Up @@ -378,6 +377,16 @@ public unsafe abstract class AllocatorBase<Key, Value> : IDisposable
/// </summary>
/// <returns></returns>
public abstract long[] GetSegmentOffsets();

/// <summary>
/// Pull-based scan interface for HLOG
/// </summary>
/// <param name="beginAddress"></param>
/// <param name="endAddress"></param>
/// <param name="scanBufferingMode"></param>
/// <returns></returns>
public abstract IFasterScanIterator<Key, Value> Scan(long beginAddress, long endAddress, ScanBufferingMode scanBufferingMode = ScanBufferingMode.DoublePageBuffering);

#endregion

/// <summary>
Expand Down Expand Up @@ -850,11 +859,11 @@ public void OnPagesClosed(long newSafeHeadAddress)
var oldStatus = PageStatusIndicator[closePage].PageFlushCloseStatus;
if (oldStatus.PageFlushStatus == PMMFlushStatus.Flushed)
{
ClearPage(closePage, (closePageAddress >> LogPageSizeBits) == 0);
ClearPage(closePageAddress >> LogPageSizeBits);
}
else
{
throw new Exception("Impossible");
throw new Exception("Error: page should already be flushed at this point");
}

var newStatus = oldStatus;
Expand Down Expand Up @@ -1161,7 +1170,7 @@ internal void AsyncReadRecordToMemory(long fromLogical, int numBytes, IOCompleti
}
else
{
ClearPage(pageIndex, readPage == 0);
ClearPage(readPage);
}
var asyncResult = new PageAsyncReadResult<TContext>()
{
Expand Down Expand Up @@ -1421,7 +1430,7 @@ private void AsyncFlushPageCallback(uint errorCode, uint numBytes, NativeOverlap
var oldStatus = PageStatusIndicator[result.page % BufferSize].PageFlushCloseStatus;
if (oldStatus.PageCloseStatus == PMMCloseStatus.Closed)
{
ClearPage((int)(result.page % BufferSize), result.page == 0);
throw new Exception("Error: page should not be closed at this point");
}
var newStatus = oldStatus;
newStatus.PageFlushStatus = PMMFlushStatus.Flushed;
Expand Down Expand Up @@ -1479,14 +1488,5 @@ public virtual void ShallowCopy(ref Value src, ref Value dst)
{
dst = src;
}

/// <summary>
/// Pull-based scan interface for HLOG
/// </summary>
/// <param name="beginAddress"></param>
/// <param name="endAddress"></param>
/// <param name="scanBufferingMode"></param>
/// <returns></returns>
public abstract IFasterScanIterator<Key, Value> Scan(long beginAddress, long endAddress, ScanBufferingMode scanBufferingMode = ScanBufferingMode.DoublePageBuffering);
}
}
4 changes: 2 additions & 2 deletions cs/src/core/Allocator/BlittableAllocator.cs
Expand Up @@ -241,9 +241,9 @@ public override long GetStartLogicalAddress(long page)
}


protected override void ClearPage(int page, bool pageZero)
protected override void ClearPage(long page)
{
Array.Clear(values[page], 0, values[page].Length);
Array.Clear(values[page % BufferSize], 0, values[page % BufferSize].Length);
}

private void WriteAsync<TContext>(IntPtr alignedSourceAddress, ulong alignedDestinationAddress, uint numBytesToWrite,
Expand Down
9 changes: 4 additions & 5 deletions cs/src/core/Allocator/GenericAllocator.cs
Expand Up @@ -232,18 +232,17 @@ protected override void WriteAsync<TContext>(long flushPage, IOCompletionCallbac



protected override void ClearPage(int page, bool pageZero)
protected override void ClearPage(long page)
{
Array.Clear(values[page], 0, values[page].Length);
Array.Clear(values[page % BufferSize], 0, values[page % BufferSize].Length);

// Close segments
var thisCloseSegment = page >> (LogSegmentSizeBits - LogPageSizeBits);
var nextClosePage = page + 1;
var nextCloseSegment = nextClosePage >> (LogSegmentSizeBits - LogPageSizeBits);
var nextCloseSegment = (page + 1) >> (LogSegmentSizeBits - LogPageSizeBits);

if (thisCloseSegment != nextCloseSegment)
{
// Last page in current segment
// We are clearing the last page in current segment
segmentOffsets[thisCloseSegment % SegmentBufferSize] = 0;
}
}
Expand Down

0 comments on commit 35e8732

Please sign in to comment.