Skip to content

Commit

Permalink
FASTER now throws exceptions of type FasterException instead of Excep…
Browse files Browse the repository at this point in the history
…tion. (#217)
  • Loading branch information
badrishc authored Dec 4, 2019
1 parent e3bd096 commit 312a778
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 58 deletions.
8 changes: 4 additions & 4 deletions cs/src/core/Allocator/AllocatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@ public AllocatorBase(LogSettings settings, IFasterEqualityComparer<Key> comparer
SegmentBufferSize = 1 + (LogTotalSizeBytes / SegmentSize < 1 ? 1 : (int)(LogTotalSizeBytes / SegmentSize));

if (SegmentSize < PageSize)
throw new Exception("Segment must be at least of page size");
throw new FasterException("Segment must be at least of page size");

if (BufferSize < 1)
{
throw new Exception("Log buffer must be of size at least 1 page");
throw new FasterException("Log buffer must be of size at least 1 page");
}

PageStatusIndicator = new FullPageStatus[BufferSize];
Expand Down Expand Up @@ -706,7 +706,7 @@ public int GetDeviceSectorSize()
public long TryAllocate(int numSlots = 1)
{
if (numSlots > PageSize)
throw new Exception("Entry does not fit on page");
throw new FasterException("Entry does not fit on page");

PageOffset localTailPageOffset = default(PageOffset);

Expand Down Expand Up @@ -893,7 +893,7 @@ public void OnPagesClosed(long newSafeHeadAddress)
ShiftClosedUntilAddress();
if (ClosedUntilAddress > FlushedUntilAddress)
{
throw new Exception($"Closed address {ClosedUntilAddress} exceeds flushed address {FlushedUntilAddress}");
throw new FasterException($"Closed address {ClosedUntilAddress} exceeds flushed address {FlushedUntilAddress}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/AtomicOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public bool Release()
return false;

if (newer.owner == 0)
throw new Exception("Invalid release by non-owner thread");
throw new FasterException("Invalid release by non-owner thread");
newer.owner = 0;

if (Interlocked.CompareExchange(ref this.atomic, newer.atomic, older.atomic) == older.atomic)
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/BlittableAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public override long[] GetSegmentOffsets()

internal override void PopulatePage(byte* src, int required_bytes, long destinationPage)
{
throw new Exception("BlittableAllocator memory pages are sector aligned - use direct copy");
throw new FasterException("BlittableAllocator memory pages are sector aligned - use direct copy");
// Buffer.MemoryCopy(src, (void*)pointers[destinationPage % BufferSize], required_bytes, required_bytes);
}

Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Allocator/BlittableScanIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ public bool GetNext(out RecordInfo recordInfo)

if (currentAddress < hlog.BeginAddress)
{
throw new Exception("Iterator address is less than log BeginAddress " + hlog.BeginAddress);
throw new FasterException("Iterator address is less than log BeginAddress " + hlog.BeginAddress);
}

if (frameSize == 0 && currentAddress < hlog.HeadAddress)
{
throw new Exception("Iterator address is less than log HeadAddress in memory-scan mode");
throw new FasterException("Iterator address is less than log HeadAddress in memory-scan mode");
}

var currentPage = currentAddress >> hlog.LogPageSizeBits;
Expand Down
10 changes: 5 additions & 5 deletions cs/src/core/Allocator/GenericAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public GenericAllocator(LogSettings settings, SerializerSettings<Key, Value> ser

if ((!keyBlittable) && (settings.LogDevice as NullDevice == null) && ((SerializerSettings == null) || (SerializerSettings.keySerializer == null)))
{
throw new Exception("Key is not blittable, but no serializer specified via SerializerSettings");
throw new FasterException("Key is not blittable, but no serializer specified via SerializerSettings");
}

if ((!valueBlittable) && (settings.LogDevice as NullDevice == null) && ((SerializerSettings == null) || (SerializerSettings.valueSerializer == null)))
{
throw new Exception("Value is not blittable, but no serializer specified via SerializerSettings");
throw new FasterException("Value is not blittable, but no serializer specified via SerializerSettings");
}

values = new Record<Key, Value>[BufferSize][];
Expand All @@ -64,7 +64,7 @@ public GenericAllocator(LogSettings settings, SerializerSettings<Key, Value> ser
if ((settings.LogDevice as NullDevice == null) && (KeyHasObjects() || ValueHasObjects()))
{
if (objectLogDevice == null)
throw new Exception("Objects in key/value, but object log not provided during creation of FASTER instance");
throw new FasterException("Objects in key/value, but object log not provided during creation of FASTER instance");
}
}

Expand Down Expand Up @@ -559,7 +559,7 @@ private void AsyncReadPageWithObjectsCallback<TContext>(uint errorCode, uint num
Debug.Assert(startptr % sectorSize == 0);

if (size > int.MaxValue)
throw new Exception("Unable to read object page, total size greater than 2GB: " + size);
throw new FasterException("Unable to read object page, total size greater than 2GB: " + size);

var alignedLength = (size + (sectorSize - 1)) & ~(sectorSize - 1);
var objBuffer = bufferPool.Get((int)alignedLength);
Expand Down Expand Up @@ -872,7 +872,7 @@ protected override bool RetrievedFullRecord(byte* record, ref AsyncIOContext<Key

// We are limited to a 2GB size per key-value
if (endAddress-startAddress > int.MaxValue)
throw new Exception("Size of key-value exceeds max of 2GB: " + (endAddress - startAddress));
throw new FasterException("Size of key-value exceeds max of 2GB: " + (endAddress - startAddress));

AsyncGetFromDisk(startAddress, (int)(endAddress - startAddress), ctx, ctx.record);
return false;
Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Allocator/GenericScanIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public bool GetNext(out RecordInfo recordInfo)

if (currentAddress < hlog.BeginAddress)
{
throw new Exception("Iterator address is less than log BeginAddress " + hlog.BeginAddress);
throw new FasterException("Iterator address is less than log BeginAddress " + hlog.BeginAddress);
}

if (frameSize == 0 && currentAddress < hlog.HeadAddress)
{
throw new Exception("Iterator address is less than log HeadAddress in memory-scan mode");
throw new FasterException("Iterator address is less than log HeadAddress in memory-scan mode");
}

var currentPage = currentAddress >> hlog.LogPageSizeBits;
Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Allocator/MallocFixedPageSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public long GetPhysicalAddress(long address)
public ref T Get(long index)
{
if (this.ReturnPhysicalAddress)
throw new Exception("Physical pointer returned by allocator: de-reference pointer to get records instead of calling Get");
throw new FasterException("Physical pointer returned by allocator: de-reference pointer to get records instead of calling Get");

return ref values
[index >> PageSizeBits]
Expand All @@ -163,7 +163,7 @@ public ref T Get(long index)
public void Set(long index, ref T value)
{
if (this.ReturnPhysicalAddress)
throw new Exception("Physical pointer returned by allocator: de-reference pointer to set records instead of calling Set (otherwise, set ForceUnpinnedAllocation to true)");
throw new FasterException("Physical pointer returned by allocator: de-reference pointer to set records instead of calling Set (otherwise, set ForceUnpinnedAllocation to true)");

values
[index >> PageSizeBits]
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/PendingFlushList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Add(PageAsyncFlushResult<Empty> t)
}
}
} while (retries++ < maxRetries);
throw new Exception("Unable to add item to list");
throw new FasterException("Unable to add item to list");
}

public bool RemoveAdjacent(long address, out PageAsyncFlushResult<Empty> request)
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Allocator/VarLenBlittableAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public override long[] GetSegmentOffsets()

internal override void PopulatePage(byte* src, int required_bytes, long destinationPage)
{
throw new Exception("BlittableAllocator memory pages are sector aligned - use direct copy");
throw new FasterException("BlittableAllocator memory pages are sector aligned - use direct copy");
// Buffer.MemoryCopy(src, (void*)pointers[destinationPage % BufferSize], required_bytes, required_bytes);
}

Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Allocator/VarLenBlittableScanIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ public bool GetNext(out RecordInfo recordInfo)

if (currentAddress < hlog.BeginAddress)
{
throw new Exception("Iterator address is less than log BeginAddress " + hlog.BeginAddress);
throw new FasterException("Iterator address is less than log BeginAddress " + hlog.BeginAddress);
}

if (frameSize == 0 && currentAddress < hlog.HeadAddress)
{
throw new Exception("Iterator address is less than log HeadAddress in memory-scan mode");
throw new FasterException("Iterator address is less than log HeadAddress in memory-scan mode");
}

var currentPage = currentAddress >> hlog.LogPageSizeBits;
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Device/LocalStorageDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private SafeFileHandle CreateHandle(int segmentId)
}
catch (Exception e)
{
throw new Exception("Error binding log handle for " + GetSegmentName(segmentId) + ": " + e.ToString());
throw new FasterException("Error binding log handle for " + GetSegmentName(segmentId) + ": " + e.ToString());
}
return logHandle;
}
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Device/StorageDeviceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public virtual void Initialize(long segmentSize, LightEpoch epoch = null)
if (!Utility.IsPowerOfTwo(segmentSize))
{
if (segmentSize != -1)
throw new Exception("Invalid segment size: " + segmentSize);
throw new FasterException("Invalid segment size: " + segmentSize);
segmentSizeBits = 64;
segmentSizeMask = ~0UL;
}
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Epochs/FastThreadLocal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public FastThreadLocal()
return;
}
}
throw new Exception("Unsupported number of simultaneous instances");
throw new FasterException("Unsupported number of simultaneous instances");
}

public void InitializeThread()
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Epochs/LightEpoch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private static int ReserveEntry(int startIndex, int threadId)

if (current_iteration > (kTableSize * 10))
{
throw new Exception("Unable to reserve an epoch entry, try increasing the epoch table size (kTableSize)");
throw new FasterException("Unable to reserve an epoch entry, try increasing the epoch table size (kTableSize)");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Index/Common/AddressInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public long Size
multiplier = 1;
if (val >= (1 << kSizeBits))
{
throw new Exception("Unsupported object size: " + value);
throw new FasterException("Unsupported object size: " + value);
}
}
var _word = (long)word;
Expand All @@ -87,7 +87,7 @@ public long Address
word = (IntPtr)_word;
if (value != Address)
{
throw new Exception("Overflow in AddressInfo" + ((kAddressBits < 64) ? " - consider running the program in x64 mode for larger address space support" : ""));
throw new FasterException("Overflow in AddressInfo" + ((kAddressBits < 64) ? " - consider running the program in x64 mode for larger address space support" : ""));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Index/Common/Contexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ internal void Recover(Guid token, ICheckpointManager checkpointManager)
{
var metadata = checkpointManager.GetLogCommitMetadata(token);
if (metadata == null)
throw new Exception("Invalid log commit metadata for ID " + token.ToString());
throw new FasterException("Invalid log commit metadata for ID " + token.ToString());

Initialize(new StreamReader(new MemoryStream(metadata)));
}
Expand Down Expand Up @@ -410,7 +410,7 @@ public void Recover(Guid guid, ICheckpointManager checkpointManager)
{
var metadata = checkpointManager.GetIndexCommitMetadata(guid);
if (metadata == null)
throw new Exception("Invalid index commit metadata for ID " + guid.ToString());
throw new FasterException("Invalid index commit metadata for ID " + guid.ToString());
Initialize(new StreamReader(new MemoryStream(metadata)));
}

Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Index/FASTER/FASTER.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public FasterKV(long size, Functions functions, LogSettings logSettings, Checkpo
checkpointSettings = new CheckpointSettings();

if (checkpointSettings.CheckpointDir != null && checkpointSettings.CheckpointManager != null)
throw new Exception("Specify either CheckpointManager or CheckpointDir for CheckpointSettings, not both");
throw new FasterException("Specify either CheckpointManager or CheckpointDir for CheckpointSettings, not both");

checkpointManager = checkpointSettings.CheckpointManager ?? new LocalCheckpointManager(checkpointSettings.CheckpointDir ?? "");

Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Index/FASTER/FASTERBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ protected virtual string _DumpDistribution(int version)
var x = default(HashBucketEntry);
x.word = b.bucket_entries[bucket_entry];
if (tags.Contains(x.Tag) && !x.Tentative)
throw new Exception("Duplicate tag found in index");
throw new FasterException("Duplicate tag found in index");
tags.Add(x.Tag);
++cnt;
++total_record_count;
Expand Down
6 changes: 3 additions & 3 deletions cs/src/core/Index/FASTER/FASTERImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ ref hlog.GetValue(physicalAddress),
HashBucket.ReleaseExclusiveLatch(bucket);
break;
case LatchOperation.ReleaseShared:
throw new Exception("Should not release shared latch here!");
throw new FasterException("Should not release shared latch here!");
default:
break;
}
Expand Down Expand Up @@ -1952,7 +1952,7 @@ private void GarbageCollectBuckets(long hash, bool force = false)

if (!Utility.IsPowerOfTwo(numChunks))
{
throw new Exception("Invalid number of chunks: " + numChunks);
throw new FasterException("Invalid number of chunks: " + numChunks);
}

for (int i = offset; i < offset + numChunks; i++)
Expand Down Expand Up @@ -2021,7 +2021,7 @@ private void SplitBuckets(long hash)

if (!Utility.IsPowerOfTwo(numChunks))
{
throw new Exception("Invalid number of chunks: " + numChunks);
throw new FasterException("Invalid number of chunks: " + numChunks);
}
for (int i = offset; i < offset + numChunks; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions cs/src/core/Index/FASTER/FASTERThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal Guid InternalAcquire()
Phase phase = _systemState.phase;
if (phase != Phase.REST)
{
throw new Exception("Can acquire only in REST phase!");
throw new FasterException("Can acquire only in REST phase!");
}
Guid guid = Guid.NewGuid();
InitLocalContext(guid);
Expand Down Expand Up @@ -248,7 +248,7 @@ internal void InternalRetryRequestAndCallback(
ref pendingContext);
break;
case OperationType.READ:
throw new Exception("Cannot happen!");
throw new FasterException("Cannot happen!");
}


Expand Down Expand Up @@ -285,7 +285,7 @@ internal void InternalRetryRequestAndCallback(
pendingContext.userContext);
break;
default:
throw new Exception("Operation type not allowed for retry");
throw new FasterException("Operation type not allowed for retry");
}

}
Expand Down
2 changes: 1 addition & 1 deletion cs/src/core/Index/FasterLog/CommitFailureException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace FASTER.core
/// <summary>
/// Exception thrown when commit fails
/// </summary>
public class CommitFailureException : Exception
public class CommitFailureException : FasterException
{
/// <summary>
/// Commit info and next commit task in chain
Expand Down
4 changes: 2 additions & 2 deletions cs/src/core/Index/FasterLog/FasterLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ public FasterLogScanIterator Scan(long beginAddress, long endAddress, string nam
if (name != null)
{
if (name.Length > 20)
throw new Exception("Max length of iterator name is 20 characters");
throw new FasterException("Max length of iterator name is 20 characters");
if (PersistedIterators.ContainsKey(name))
Debug.WriteLine("Iterator name exists, overwriting");
PersistedIterators[name] = iter;
Expand Down Expand Up @@ -919,7 +919,7 @@ private unsafe void AsyncGetFromDiskCallback(uint errorCode, uint numBytes, Nati
length = GetLength(ptr);
if (!VerifyChecksum(ptr, length))
{
throw new Exception("Checksum failed for read");
throw new FasterException("Checksum failed for read");
}
result = getMemory != null ? getMemory(length) : new byte[length];
fixed (byte* bp = result)
Expand Down
Loading

0 comments on commit 312a778

Please sign in to comment.