private Task <RiakResult <IEnumerable <RiakResult> > > Delete(IRiakConnection conn, IEnumerable <RiakObjectId> objectIds, RiakDeleteOptions options = null) { options = options ?? new RiakDeleteOptions(); return(AfterAll(objectIds.Select(id => { if (!IsValidBucketOrKey(id.Bucket)) { return RiakResult.ErrorTask(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false); } if (!IsValidBucketOrKey(id.Key)) { return RiakResult.ErrorTask(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false); } var req = new RpbDelReq { bucket = id.Bucket.ToRiakString(), key = id.Key.ToRiakString() }; options.Populate(req); return conn.PbcWriteRead(req, MessageCode.DelResp); })).ContinueWith((Task <IEnumerable <RiakResult> > finishedTask) => { return RiakResult <IEnumerable <RiakResult> > .Success(finishedTask.Result); })); }
private static RiakResult <IEnumerable <RiakResult> > Delete(IRiakConnection conn, IEnumerable <RiakObjectId> objectIds, RiakDeleteOptions options = null) { options = options ?? new RiakDeleteOptions(); var responses = objectIds.Select(id => { if (!IsValidBucketOrKey(id.Bucket)) { return(RiakResult.Error(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false)); } if (!IsValidBucketOrKey(id.Key)) { return(RiakResult.Error(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false)); } var req = new RpbDelReq { bucket = id.Bucket.ToRiakString(), key = id.Key.ToRiakString() }; options.Populate(req); return(conn.PbcWriteRead(req, MessageCode.DelResp)); }).ToList(); return(RiakResult <IEnumerable <RiakResult> > .Success(responses)); }
private static RiakResult <IEnumerable <string> > ListKeys(IRiakConnection conn, string bucket) { var lkReq = new RpbListKeysReq { Bucket = bucket.ToRiakString() }; var result = conn.PbcWriteRead <RpbListKeysReq, RpbListKeysResp>(lkReq, lkr => lkr.IsSuccess && !lkr.Value.Done); if (result.IsSuccess) { var keys = result.Value.Where(r => r.IsSuccess).SelectMany(r => r.Value.KeyNames).Distinct().ToList(); return(RiakResult <IEnumerable <string> > .Success(keys)); } return(RiakResult <IEnumerable <string> > .Error(result.ResultCode, result.ErrorMessage)); }
private static RiakResult <IEnumerable <string> > ListKeys(IRiakConnection conn, string bucket) { System.Diagnostics.Debug.Write(ListKeysWarning); System.Diagnostics.Trace.TraceWarning(ListKeysWarning); Console.WriteLine(ListKeysWarning); var lkReq = new RpbListKeysReq { bucket = bucket.ToRiakString() }; var result = conn.PbcWriteRead <RpbListKeysReq, RpbListKeysResp>(lkReq, lkr => lkr.IsSuccess && !lkr.Value.done); if (result.IsSuccess) { var keys = result.Value.Where(r => r.IsSuccess).SelectMany(r => r.Value.keys).Select(k => k.FromRiakString()).Distinct().ToList(); return(RiakResult <IEnumerable <string> > .Success(keys)); } return(RiakResult <IEnumerable <string> > .Error(result.ResultCode, result.ErrorMessage, result.NodeOffline)); }
private async void NodeMonitor() { while (!_disposing) { var deadNodes = new List <IRiakNode>(); IRiakNode node = null; while (_offlineNodes.TryDequeue(out node) && !_disposing) { try { var nodeToMonitor = node; await _riakConnection.PbcWriteRead(new RiakNodeEndpoint(nodeToMonitor), MessageCode.PingReq, MessageCode.PingResp).ConfigureAwait(false); _loadBalancer.AddNode(node); } catch (Exception) { try { node.ReleaseAll().ConfigureAwait(false).GetAwaiter().GetResult(); } finally { deadNodes.Add(node); } } } if (!_disposing) { foreach (var deadNode in deadNodes) { _offlineNodes.Enqueue(deadNode); } Thread.Sleep(_nodePollTime); } } }
public async Task <Pong> Ping() { var startTime = Stopwatch.StartNew(); await _connection.PbcWriteRead(_endPoint, MessageCode.PingReq, MessageCode.PingResp).ConfigureAwait(false); startTime.Stop(); var pong = new Pong { ResponseTime = startTime.Elapsed }; return(pong); }