internal override async Task SendAsync(IOperation op, CancellationToken token = default, TimeSpan?timeout = null) { if (KeyMapper == null) { throw new InvalidOperationException($"Bucket {Name} is not bootstrapped."); } var vBucket = (VBucket)KeyMapper.MapKey(op.Key); var endPoint = op.VBucketId.HasValue ? vBucket.LocateReplica(op.VBucketId.Value) : vBucket.LocatePrimary(); op.VBucketId = vBucket.Index; if (Nodes.TryGet(endPoint !, out var clusterNode)) { try { await clusterNode.SendAsync(op, token, timeout).ConfigureAwait(false); } catch (Exception e) { if (e is CollectionOutdatedException) { Logger.LogInformation("Updating stale manifest for collection and retrying.", e); await RefreshCollectionId(op, clusterNode).ConfigureAwait(false); await clusterNode.SendAsync(op, token, timeout).ConfigureAwait(false); } else { throw;//propagate up } } }
internal override async Task Send(IOperation op, TaskCompletionSource <IMemoryOwner <byte> > tcs) { var bucket = KeyMapper.MapKey(op.Key); var endPoint = bucket.LocatePrimary(); var clusterNode = BucketNodes[endPoint]; await CheckConnection(clusterNode).ConfigureAwait(false); await op.SendAsync(clusterNode.Connection).ConfigureAwait(false); }
internal override async Task SendAsync(IOperation op, CancellationToken token = default, TimeSpan?timeout = null) { var bucket = KeyMapper.MapKey(op.Key); var endPoint = bucket.LocatePrimary(); if (Context.TryGetNode(endPoint, out var clusterNode)) { await clusterNode.ExecuteOp(op, token, timeout); } else { //raise exceptin that node is not found } }
internal override async Task SendAsync(IOperation op, CancellationTokenPair tokenPair = default) { if (KeyMapper == null) { ThrowHelper.ThrowInvalidOperationException($"Bucket {Name} is not bootstrapped."); } if (op.RequiresVBucketId) { var vBucket = (VBucket)KeyMapper.MapKey(op.Key, op.WasNmvb()); var endPoint = op.ReplicaIdx != null && op.ReplicaIdx > -1 ? vBucket.LocateReplica(op.ReplicaIdx.GetValueOrDefault()) : vBucket.LocatePrimary(); op.VBucketId = vBucket.Index; try { if (Nodes.TryGet(endPoint.GetValueOrDefault(), out var clusterNode)) { await clusterNode.SendAsync(op, tokenPair).ConfigureAwait(false); return; } } catch (ArgumentNullException) { //We could not find a candidate node to send so put into the retry queue //its likely were between cluster map updates and we'll try again later throw new NodeNotAvailableException( $"Cannot find a Couchbase Server node for {endPoint}."); } } //Make sure we use a node with the data service var node = Nodes.GetRandom(x => x.HasKv); if (node == null) { throw new NodeNotAvailableException( $"Cannot find a Couchbase Server node for executing {op.GetType()}."); } await node.SendAsync(op, tokenPair).ConfigureAwait(false); }
internal override Task SendAsync(IOperation op, CancellationTokenPair tokenPair = default) { if (KeyMapper == null) { throw new InvalidOperationException("Bucket is not bootstrapped."); } var bucket = KeyMapper.MapKey(op.Key); var endPoint = bucket.LocatePrimary(); if (Nodes.TryGet(endPoint, out var clusterNode)) { return(clusterNode.ExecuteOp(op, tokenPair)); } //raise exception that node is not found return(Task.CompletedTask); }
internal override async Task SendAsync(IOperation op, CancellationToken token = default, TimeSpan?timeout = null) { var vBucket = (VBucket)KeyMapper.MapKey(op.Key); var endPoint = op.VBucketId.HasValue ? vBucket.LocateReplica(op.VBucketId.Value) : vBucket.LocatePrimary(); op.VBucketId = vBucket.Index; if (Context.TryGetNode(endPoint, out var clusterNode)) { await clusterNode.ExecuteOp(op, token, timeout); } else { throw new NodeNotAvailableException($"Cannot find a Couchbase Server node for {endPoint}."); } }
internal override async Task SendAsync(IOperation op, CancellationToken token = default) { if (KeyMapper == null) { throw new InvalidOperationException("Bucket is not bootstrapped."); } var bucket = KeyMapper.MapKey(op.Key); var endPoint = bucket.LocatePrimary(); if (Nodes.TryGet(endPoint, out var clusterNode)) { await clusterNode.ExecuteOp(op, token).ConfigureAwait(false); } else { //raise exception that node is not found } }
internal override async Task SendAsync(IOperation op, CancellationTokenPair tokenPair = default) { if (KeyMapper == null) { ThrowHelper.ThrowInvalidOperationException($"Bucket {Name} is not bootstrapped."); } if (op.RequiresVBucketId) { var vBucket = (VBucket)KeyMapper.MapKey(op.Key); var endPoint = op.ReplicaIdx != null ? vBucket.LocateReplica(op.ReplicaIdx.GetValueOrDefault()) : vBucket.LocatePrimary(); op.VBucketId = vBucket.Index; if (Nodes.TryGet(endPoint !, out var clusterNode)) { await clusterNode.SendAsync(op, tokenPair); return; } throw new NodeNotAvailableException( $"Cannot find a Couchbase Server node for {endPoint}."); } var node = Nodes.GetRandom(); if (node == null) { throw new NodeNotAvailableException( $"Cannot find a Couchbase Server node for executing {op.GetType()}."); } await node.SendAsync(op, tokenPair); }
public void SetShortcut(ModifierKey modifier, Key key) { hasShortcut = true; shortcutModifierKey = KeyMapper.MapModifier(modifier); shortcutKey = KeyMapper.MapKey(key); }
protected virtual void IndexLoadedData(IEnumerable <TValue> all) { CacheData = new ConcurrentDictionary <TKey, TValue>(all.ToDictionary(item => KeyMapper.MapKey(item))); }