-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add terse cancellation logging mode; #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version: "3" | ||
services: | ||
memcached-1: | ||
image: memcached:latest | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,10 @@ public async Task<MemcachedClientResult> StoreAsync<T>( | |
.WithSyncSuccess(syncSuccess); | ||
} | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first thing that comes to mind is to extract error handling logic if it starts to extend. It may be a good idea in such scenarios, what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say we take a note of it and next time a need for another exception handling extension arises - implement it in a separate class |
||
{ | ||
return MemcachedClientResult.Cancelled(nameof(StoreAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientResult.Unsuccessful( | ||
|
@@ -163,6 +167,10 @@ public async Task<MemcachedClientResult> MultiStoreAsync<T>( | |
|
||
return MemcachedClientResult.Successful.WithSyncSuccess(syncSuccess); | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientResult.Cancelled(nameof(MultiStoreAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientResult.Unsuccessful( | ||
|
@@ -219,6 +227,10 @@ public async Task<MemcachedClientResult> MultiStoreAsync<T>( | |
|
||
return MemcachedClientResult.Successful.WithSyncSuccess(syncSuccess); | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientResult.Cancelled(nameof(MultiStoreAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientResult.Unsuccessful( | ||
|
@@ -268,6 +280,10 @@ public async Task<MemcachedClientValueResult<T>> GetAsync<T>(string key, Cancell | |
} | ||
} | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientValueResult<T>.Cancelled(nameof(GetAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientValueResult<T>.Unsuccessful( | ||
|
@@ -290,6 +306,13 @@ public async Task<MemcachedClientValueResult<IDictionary<string, T>>> MultiGetSa | |
getKeysResult, | ||
isResultEmpty: getKeysResult is null or {Count: 0}); | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientValueResult<IDictionary<string, T>>.Cancelled( | ||
nameof(MultiGetSafeAsync), | ||
defaultResultValue: new Dictionary<string, T>() | ||
); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientValueResult<IDictionary<string, T>>.Unsuccessful( | ||
|
@@ -306,6 +329,7 @@ public async Task<IDictionary<string, T>> MultiGetAsync<T>( | |
BatchingOptions batchingOptions = null, | ||
uint replicationFactor = 0) | ||
{ | ||
|
||
var nodes = _nodeLocator.GetNodes(keys, replicationFactor); | ||
if (nodes.Keys.Count == 0) | ||
{ | ||
|
@@ -344,7 +368,7 @@ public async Task<IDictionary<string, T>> MultiGetAsync<T>( | |
|
||
var command = taskResult.GetCommandAs<MultiGetCommand>(); | ||
|
||
if (command.Result is null or { Count: 0 }) | ||
if (command.Result is null or {Count: 0}) | ||
{ | ||
// skip results that are empty | ||
continue; | ||
|
@@ -404,6 +428,10 @@ public async Task<MemcachedClientResult> DeleteAsync( | |
.WithSyncSuccess(syncSuccess); | ||
} | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientResult.Cancelled(nameof(DeleteAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientResult.Unsuccessful( | ||
|
@@ -464,6 +492,10 @@ public async Task<MemcachedClientResult> MultiDeleteAsync( | |
|
||
return MemcachedClientResult.Successful.WithSyncSuccess(syncSuccess); | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientResult.Cancelled(nameof(MultiDeleteAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientResult.Unsuccessful( | ||
|
@@ -509,6 +541,10 @@ public async Task<MemcachedClientValueResult<ulong>> IncrAsync( | |
); | ||
} | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientValueResult<ulong>.Cancelled(nameof(IncrAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientValueResult<ulong>.Unsuccessful( | ||
|
@@ -553,6 +589,10 @@ public async Task<MemcachedClientValueResult<ulong>> DecrAsync( | |
); | ||
} | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientValueResult<ulong>.Cancelled(nameof(DecrAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientValueResult<ulong>.Unsuccessful( | ||
|
@@ -592,6 +632,10 @@ public async Task<MemcachedClientResult> FlushAsync(CancellationToken token) | |
|
||
return MemcachedClientResult.Successful; | ||
} | ||
catch (OperationCanceledException) when (_memcachedConfiguration.IsTerseCancellationLogging) | ||
{ | ||
return MemcachedClientResult.Cancelled(nameof(FlushAsync)); | ||
} | ||
catch (Exception e) | ||
{ | ||
return MemcachedClientResult.Unsuccessful( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't LogErrorIfAny methods be in tests project if they are used only in test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are actually public helper methods which are extensively used in our projects 😎