From 312a778b6cee6323ab4a3569e6f4480f5bd49df0 Mon Sep 17 00:00:00 2001 From: Badrish Chandramouli Date: Wed, 4 Dec 2019 09:49:32 -0800 Subject: [PATCH] FASTER now throws exceptions of type FasterException instead of Exception. (#217) --- cs/src/core/Allocator/AllocatorBase.cs | 8 ++--- cs/src/core/Allocator/AtomicOwner.cs | 2 +- cs/src/core/Allocator/BlittableAllocator.cs | 2 +- .../core/Allocator/BlittableScanIterator.cs | 4 +-- cs/src/core/Allocator/GenericAllocator.cs | 10 +++---- cs/src/core/Allocator/GenericScanIterator.cs | 4 +-- cs/src/core/Allocator/MallocFixedPageSize.cs | 4 +-- cs/src/core/Allocator/PendingFlushList.cs | 2 +- .../Allocator/VarLenBlittableAllocator.cs | 2 +- .../Allocator/VarLenBlittableScanIterator.cs | 4 +-- cs/src/core/Device/LocalStorageDevice.cs | 2 +- cs/src/core/Device/StorageDeviceBase.cs | 2 +- cs/src/core/Epochs/FastThreadLocal.cs | 2 +- cs/src/core/Epochs/LightEpoch.cs | 2 +- cs/src/core/Index/Common/AddressInfo.cs | 4 +-- cs/src/core/Index/Common/Contexts.cs | 4 +-- cs/src/core/Index/FASTER/FASTER.cs | 2 +- cs/src/core/Index/FASTER/FASTERBase.cs | 2 +- cs/src/core/Index/FASTER/FASTERImpl.cs | 6 ++-- cs/src/core/Index/FASTER/FASTERThread.cs | 6 ++-- .../Index/FasterLog/CommitFailureException.cs | 2 +- cs/src/core/Index/FasterLog/FasterLog.cs | 4 +-- .../core/Index/FasterLog/FasterLogIterator.cs | 10 +++---- .../Index/FasterLog/FasterLogRecoveryInfo.cs | 8 ++--- cs/src/core/Index/Recovery/Checkpoint.cs | 10 +++---- .../Index/Recovery/LocalCheckpointManager.cs | 4 +-- cs/src/core/Index/Recovery/Recovery.cs | 2 +- cs/src/core/Utilities/FasterException.cs | 30 +++++++++++++++++++ cs/src/core/Utilities/Native32.cs | 2 +- 29 files changed, 88 insertions(+), 58 deletions(-) create mode 100644 cs/src/core/Utilities/FasterException.cs diff --git a/cs/src/core/Allocator/AllocatorBase.cs b/cs/src/core/Allocator/AllocatorBase.cs index 5bc6e4c8d..c77f630d6 100644 --- a/cs/src/core/Allocator/AllocatorBase.cs +++ b/cs/src/core/Allocator/AllocatorBase.cs @@ -517,11 +517,11 @@ public AllocatorBase(LogSettings settings, IFasterEqualityComparer 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]; @@ -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); @@ -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}"); } } } diff --git a/cs/src/core/Allocator/AtomicOwner.cs b/cs/src/core/Allocator/AtomicOwner.cs index ad7de3824..6268349b4 100644 --- a/cs/src/core/Allocator/AtomicOwner.cs +++ b/cs/src/core/Allocator/AtomicOwner.cs @@ -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) diff --git a/cs/src/core/Allocator/BlittableAllocator.cs b/cs/src/core/Allocator/BlittableAllocator.cs index 45717ff8c..9094286c9 100644 --- a/cs/src/core/Allocator/BlittableAllocator.cs +++ b/cs/src/core/Allocator/BlittableAllocator.cs @@ -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); } diff --git a/cs/src/core/Allocator/BlittableScanIterator.cs b/cs/src/core/Allocator/BlittableScanIterator.cs index 05cb1ae32..2e1292e50 100644 --- a/cs/src/core/Allocator/BlittableScanIterator.cs +++ b/cs/src/core/Allocator/BlittableScanIterator.cs @@ -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; diff --git a/cs/src/core/Allocator/GenericAllocator.cs b/cs/src/core/Allocator/GenericAllocator.cs index 23b747b04..2dbabb8f0 100644 --- a/cs/src/core/Allocator/GenericAllocator.cs +++ b/cs/src/core/Allocator/GenericAllocator.cs @@ -48,12 +48,12 @@ public GenericAllocator(LogSettings settings, SerializerSettings 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[BufferSize][]; @@ -64,7 +64,7 @@ public GenericAllocator(LogSettings settings, SerializerSettings 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"); } } @@ -559,7 +559,7 @@ private void AsyncReadPageWithObjectsCallback(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); @@ -872,7 +872,7 @@ protected override bool RetrievedFullRecord(byte* record, ref AsyncIOContext 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; diff --git a/cs/src/core/Allocator/GenericScanIterator.cs b/cs/src/core/Allocator/GenericScanIterator.cs index 8cb7e1e1e..79f4aa1ee 100644 --- a/cs/src/core/Allocator/GenericScanIterator.cs +++ b/cs/src/core/Allocator/GenericScanIterator.cs @@ -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; diff --git a/cs/src/core/Allocator/MallocFixedPageSize.cs b/cs/src/core/Allocator/MallocFixedPageSize.cs index ef811e9cb..a1394c48a 100644 --- a/cs/src/core/Allocator/MallocFixedPageSize.cs +++ b/cs/src/core/Allocator/MallocFixedPageSize.cs @@ -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] @@ -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] diff --git a/cs/src/core/Allocator/PendingFlushList.cs b/cs/src/core/Allocator/PendingFlushList.cs index 0896481aa..3b607e15e 100644 --- a/cs/src/core/Allocator/PendingFlushList.cs +++ b/cs/src/core/Allocator/PendingFlushList.cs @@ -33,7 +33,7 @@ public void Add(PageAsyncFlushResult 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 request) diff --git a/cs/src/core/Allocator/VarLenBlittableAllocator.cs b/cs/src/core/Allocator/VarLenBlittableAllocator.cs index 1cecb248f..bed77fa06 100644 --- a/cs/src/core/Allocator/VarLenBlittableAllocator.cs +++ b/cs/src/core/Allocator/VarLenBlittableAllocator.cs @@ -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); } diff --git a/cs/src/core/Allocator/VarLenBlittableScanIterator.cs b/cs/src/core/Allocator/VarLenBlittableScanIterator.cs index bce1991bc..fe32d16f8 100644 --- a/cs/src/core/Allocator/VarLenBlittableScanIterator.cs +++ b/cs/src/core/Allocator/VarLenBlittableScanIterator.cs @@ -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; diff --git a/cs/src/core/Device/LocalStorageDevice.cs b/cs/src/core/Device/LocalStorageDevice.cs index 6927c1e4d..45182db98 100644 --- a/cs/src/core/Device/LocalStorageDevice.cs +++ b/cs/src/core/Device/LocalStorageDevice.cs @@ -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; } diff --git a/cs/src/core/Device/StorageDeviceBase.cs b/cs/src/core/Device/StorageDeviceBase.cs index 7ab14ab82..102ec49d3 100644 --- a/cs/src/core/Device/StorageDeviceBase.cs +++ b/cs/src/core/Device/StorageDeviceBase.cs @@ -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; } diff --git a/cs/src/core/Epochs/FastThreadLocal.cs b/cs/src/core/Epochs/FastThreadLocal.cs index 7bc2e2e30..74b909fdd 100644 --- a/cs/src/core/Epochs/FastThreadLocal.cs +++ b/cs/src/core/Epochs/FastThreadLocal.cs @@ -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() diff --git a/cs/src/core/Epochs/LightEpoch.cs b/cs/src/core/Epochs/LightEpoch.cs index 9e3628f41..8ae039627 100644 --- a/cs/src/core/Epochs/LightEpoch.cs +++ b/cs/src/core/Epochs/LightEpoch.cs @@ -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)"); } } } diff --git a/cs/src/core/Index/Common/AddressInfo.cs b/cs/src/core/Index/Common/AddressInfo.cs index a9a78a962..c617ed5b5 100644 --- a/cs/src/core/Index/Common/AddressInfo.cs +++ b/cs/src/core/Index/Common/AddressInfo.cs @@ -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; @@ -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" : "")); } } } diff --git a/cs/src/core/Index/Common/Contexts.cs b/cs/src/core/Index/Common/Contexts.cs index c304e09db..3384524bf 100644 --- a/cs/src/core/Index/Common/Contexts.cs +++ b/cs/src/core/Index/Common/Contexts.cs @@ -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))); } @@ -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))); } diff --git a/cs/src/core/Index/FASTER/FASTER.cs b/cs/src/core/Index/FASTER/FASTER.cs index e222a3585..a07451410 100644 --- a/cs/src/core/Index/FASTER/FASTER.cs +++ b/cs/src/core/Index/FASTER/FASTER.cs @@ -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 ?? ""); diff --git a/cs/src/core/Index/FASTER/FASTERBase.cs b/cs/src/core/Index/FASTER/FASTERBase.cs index 61f30f42a..fc818cffc 100644 --- a/cs/src/core/Index/FASTER/FASTERBase.cs +++ b/cs/src/core/Index/FASTER/FASTERBase.cs @@ -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; diff --git a/cs/src/core/Index/FASTER/FASTERImpl.cs b/cs/src/core/Index/FASTER/FASTERImpl.cs index 52a025375..565243a44 100644 --- a/cs/src/core/Index/FASTER/FASTERImpl.cs +++ b/cs/src/core/Index/FASTER/FASTERImpl.cs @@ -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; } @@ -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++) @@ -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++) { diff --git a/cs/src/core/Index/FASTER/FASTERThread.cs b/cs/src/core/Index/FASTER/FASTERThread.cs index eab6f94ee..14014e0ac 100644 --- a/cs/src/core/Index/FASTER/FASTERThread.cs +++ b/cs/src/core/Index/FASTER/FASTERThread.cs @@ -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); @@ -248,7 +248,7 @@ internal void InternalRetryRequestAndCallback( ref pendingContext); break; case OperationType.READ: - throw new Exception("Cannot happen!"); + throw new FasterException("Cannot happen!"); } @@ -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"); } } diff --git a/cs/src/core/Index/FasterLog/CommitFailureException.cs b/cs/src/core/Index/FasterLog/CommitFailureException.cs index c6374806f..5755643a0 100644 --- a/cs/src/core/Index/FasterLog/CommitFailureException.cs +++ b/cs/src/core/Index/FasterLog/CommitFailureException.cs @@ -11,7 +11,7 @@ namespace FASTER.core /// /// Exception thrown when commit fails /// - public class CommitFailureException : Exception + public class CommitFailureException : FasterException { /// /// Commit info and next commit task in chain diff --git a/cs/src/core/Index/FasterLog/FasterLog.cs b/cs/src/core/Index/FasterLog/FasterLog.cs index 89350911d..16bc5c646 100644 --- a/cs/src/core/Index/FasterLog/FasterLog.cs +++ b/cs/src/core/Index/FasterLog/FasterLog.cs @@ -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; @@ -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) diff --git a/cs/src/core/Index/FasterLog/FasterLogIterator.cs b/cs/src/core/Index/FasterLog/FasterLogIterator.cs index 43fb5b9fb..8efb1d3fd 100644 --- a/cs/src/core/Index/FasterLog/FasterLogIterator.cs +++ b/cs/src/core/Index/FasterLog/FasterLogIterator.cs @@ -193,7 +193,7 @@ public unsafe bool GetNext(out byte[] entry, out int entryLength, out long curre // Use user delegate to allocate memory entry = getMemory(entryLength); if (entry.Length < entryLength) - throw new Exception("Byte array provided has invalid length"); + throw new FasterException("Byte array provided has invalid length"); } else { @@ -336,7 +336,7 @@ private bool WaitForFrameLoad(long currentAddress, long currentFrame) loadedPage[currentFrame] = -1; loadedCancel[currentFrame] = new CancellationTokenSource(); Utility.MonotonicUpdate(ref NextAddress, (1 + (currentAddress >> allocator.LogPageSizeBits)) << allocator.LogPageSizeBits, out _); - throw new Exception("Page read from storage failed, skipping page. Inner exception: " + e.ToString()); + throw new FasterException("Page read from storage failed, skipping page. Inner exception: " + e.ToString()); } epoch.Resume(); return true; @@ -440,7 +440,7 @@ private unsafe bool GetNextInternal(out long physicalAddress, out int entryLengt { epoch.Suspend(); var curPage = currentAddress >> allocator.LogPageSizeBits; - throw new Exception("Invalid checksum found during scan, skipping page " + curPage); + throw new FasterException("Invalid checksum found during scan, skipping page " + curPage); } else continue; @@ -453,7 +453,7 @@ private unsafe bool GetNextInternal(out long physicalAddress, out int entryLengt if (Utility.MonotonicUpdate(ref NextAddress, currentAddress, out _)) { epoch.Suspend(); - throw new Exception("Invalid length of record found: " + entryLength + " at address " + currentAddress + ", skipping page"); + throw new FasterException("Invalid length of record found: " + entryLength + " at address " + currentAddress + ", skipping page"); } else continue; @@ -469,7 +469,7 @@ private unsafe bool GetNextInternal(out long physicalAddress, out int entryLengt if (Utility.MonotonicUpdate(ref NextAddress, currentAddress, out _)) { epoch.Suspend(); - throw new Exception("Invalid checksum found during scan, skipping page " + curPage); + throw new FasterException("Invalid checksum found during scan, skipping page " + curPage); } else continue; diff --git a/cs/src/core/Index/FasterLog/FasterLogRecoveryInfo.cs b/cs/src/core/Index/FasterLog/FasterLogRecoveryInfo.cs index c869fec95..829beece2 100644 --- a/cs/src/core/Index/FasterLog/FasterLogRecoveryInfo.cs +++ b/cs/src/core/Index/FasterLog/FasterLogRecoveryInfo.cs @@ -57,13 +57,13 @@ public void Initialize(BinaryReader reader) } catch (Exception e) { - throw new Exception("Unable to recover from previous commit. Inner exception: " + e.ToString()); + throw new FasterException("Unable to recover from previous commit. Inner exception: " + e.ToString()); } if (version != 0) - throw new Exception("Invalid version found during commit recovery"); + throw new FasterException("Invalid version found during commit recovery"); if (checkSum != (BeginAddress ^ FlushedUntilAddress)) - throw new Exception("Invalid checksum found during commit recovery"); + throw new FasterException("Invalid checksum found during commit recovery"); var count = 0; try @@ -91,7 +91,7 @@ internal void Recover(ILogCommitManager logCommitManager) { var metadata = logCommitManager.GetCommitMetadata(); if (metadata == null) - throw new Exception("Invalid log commit metadata during recovery"); + throw new FasterException("Invalid log commit metadata during recovery"); Initialize(new BinaryReader(new MemoryStream(metadata))); } diff --git a/cs/src/core/Index/Recovery/Checkpoint.cs b/cs/src/core/Index/Recovery/Checkpoint.cs index 2f07de319..7c3a1a48c 100644 --- a/cs/src/core/Index/Recovery/Checkpoint.cs +++ b/cs/src/core/Index/Recovery/Checkpoint.cs @@ -170,7 +170,7 @@ private bool GlobalMoveToNextState(SystemState currentState, SystemState nextSta break; } default: - throw new Exception(); + throw new FasterException(); } ObtainCurrentTailAddress(ref _indexCheckpoint.info.startLogicalAddress); @@ -182,7 +182,7 @@ private bool GlobalMoveToNextState(SystemState currentState, SystemState nextSta { if (UseReadCache && this.ReadCache.BeginAddress != this.ReadCache.TailAddress) { - throw new Exception("Index checkpoint with read cache is not supported"); + throw new FasterException("Index checkpoint with read cache is not supported"); } TakeIndexFuzzyCheckpoint(); @@ -205,13 +205,13 @@ private bool GlobalMoveToNextState(SystemState currentState, SystemState nextSta { if (UseReadCache && this.ReadCache.BeginAddress != this.ReadCache.TailAddress) { - throw new Exception("Index checkpoint with read cache is not supported"); + throw new FasterException("Index checkpoint with read cache is not supported"); } TakeIndexFuzzyCheckpoint(); break; } default: - throw new Exception(); + throw new FasterException(); } ObtainCurrentTailAddress(ref _hybridLogCheckpoint.info.startLogicalAddress); @@ -364,7 +364,7 @@ private bool GlobalMoveToNextState(SystemState currentState, SystemState nextSta case CheckpointType.NONE: break; default: - throw new Exception(); + throw new FasterException(); } _checkpointType = CheckpointType.NONE; diff --git a/cs/src/core/Index/Recovery/LocalCheckpointManager.cs b/cs/src/core/Index/Recovery/LocalCheckpointManager.cs index 9eb270d95..566eb7e40 100644 --- a/cs/src/core/Index/Recovery/LocalCheckpointManager.cs +++ b/cs/src/core/Index/Recovery/LocalCheckpointManager.cs @@ -181,7 +181,7 @@ public bool GetLatestCheckpoint(out Guid indexToken, out Guid logToken) var latestICFolder = indexCheckpointDir.GetDirectories().OrderByDescending(f => f.LastWriteTime).First(); if (latestICFolder == null || !Guid.TryParse(latestICFolder.Name, out indexToken)) { - throw new Exception("No valid index checkpoint to recover from"); + throw new FasterException("No valid index checkpoint to recover from"); } @@ -198,7 +198,7 @@ public bool GetLatestCheckpoint(out Guid indexToken, out Guid logToken) var latestHLCFolder = hlogCheckpointDir.GetDirectories().OrderByDescending(f => f.LastWriteTime).First(); if (latestHLCFolder == null || !Guid.TryParse(latestHLCFolder.Name, out logToken)) { - throw new Exception("No valid hybrid log checkpoint to recover from"); + throw new FasterException("No valid hybrid log checkpoint to recover from"); } return true; } diff --git a/cs/src/core/Index/Recovery/Recovery.cs b/cs/src/core/Index/Recovery/Recovery.cs index 4ae0388ac..0f6ca3078 100644 --- a/cs/src/core/Index/Recovery/Recovery.cs +++ b/cs/src/core/Index/Recovery/Recovery.cs @@ -91,7 +91,7 @@ private void InternalRecover(Guid indexToken, Guid hybridLogToken) // Check if the two checkpoints are compatible for recovery if (!IsCompatible(recoveredICInfo.info, recoveredHLCInfo.info)) { - throw new Exception("Cannot recover from (" + indexToken.ToString() + "," + hybridLogToken.ToString() + ") checkpoint pair!\n"); + throw new FasterException("Cannot recover from (" + indexToken.ToString() + "," + hybridLogToken.ToString() + ") checkpoint pair!\n"); } // Set new system state after recovery diff --git a/cs/src/core/Utilities/FasterException.cs b/cs/src/core/Utilities/FasterException.cs new file mode 100644 index 000000000..90a6a263a --- /dev/null +++ b/cs/src/core/Utilities/FasterException.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +using System; +using System.Runtime.Serialization; + +namespace FASTER.core +{ + /// + /// FASTER exception base type + /// + public class FasterException : Exception + { + internal FasterException() + { + } + + internal FasterException(string message) : base(message) + { + } + + internal FasterException(string message, Exception innerException) : base(message, innerException) + { + } + + internal FasterException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} \ No newline at end of file diff --git a/cs/src/core/Utilities/Native32.cs b/cs/src/core/Utilities/Native32.cs index 45972b631..98f8b5375 100644 --- a/cs/src/core/Utilities/Native32.cs +++ b/cs/src/core/Utilities/Native32.cs @@ -171,7 +171,7 @@ public static void AffinitizeThreadRoundRobin(uint threadIdx) if (SetThreadGroupAffinity(thread, ref groupAffinityThread, ref oldAffinityThread) == 0) { - throw new Exception("Unable to affinitize thread"); + throw new FasterException("Unable to affinitize thread"); } }