internal void Populate(RpbGetReq request) { request.r = R.IsLeft ? R.Left : R.Right.ToRpbOption(); request.pr = Pr.IsLeft ? Pr.Left : Pr.Right.ToRpbOption(); if (BasicQuorum.HasValue) { request.basic_quorum = BasicQuorum.Value; } if (NotFoundOk.HasValue) { request.notfound_ok = NotFoundOk.Value; } if (Head.HasValue) { request.head = Head.Value; } if (DeletedVclock.HasValue) { request.deletedvclock = DeletedVclock.Value; } if (IfModified != null) { request.if_modified = IfModified; } }
internal void Populate(RpbGetReq request) { request.r = R; request.pr = Pr; if (BasicQuorum.HasValue) { request.basic_quorum = BasicQuorum.Value; } if (NotFoundOk.HasValue) { request.notfound_ok = NotFoundOk.Value; } if (Head.HasValue) { request.head = Head.Value; } if (DeletedVclock.HasValue) { request.deletedvclock = DeletedVclock.Value; } if (IfModified != null) { request.if_modified = IfModified; } request.timeout = (uint)Timeout; }
/// <summary> /// get /// </summary> /// <param name="bucket"></param> /// <param name="key"></param> /// <param name="setOptions"></param> /// <param name="millisecondsReceiveTimeout"></param> /// <param name="asyncState"></param> /// <returns></returns> public Task <RiakObject> Get(string bucket, byte[] key, Action <GetOptions> setOptions = null, int millisecondsReceiveTimeout = 3000, object asyncState = null) { var source = new TaskCompletionSource <RiakObject>(asyncState); var request = new RpbGetReq { bucket = bucket.GetBytes(), key = key }; if (setOptions != null) { setOptions(new GetOptions(request)); } this._socket.Execute <RpbGetReq, RpbGetResp>(Codes.GetReq, Codes.GetResp, request, ex => source.TrySetException(ex), result => { if (result == null) { source.TrySetResult(null); } else { source.TrySetResult(new RiakObject(bucket, key, result.vclock, result.content)); } }, millisecondsReceiveTimeout); return(source.Task); }
/// <summary> /// Get the specified <paramref name="key"/> from the <paramref name="bucket"/>. /// Optionally can be read from rVal instances. By default, the server's /// r-value will be used, but can be overridden by rVal. /// </summary> /// <param name='bucket'> /// The name of the bucket containing the <paramref name="key"/> /// </param> /// <param name='key'> /// The key. /// </param> /// <param name='options'>The <see cref="CorrugatedIron.Models.RiakGetOptions" /> responsible for /// configuring the semantics of this single get request. These options will override any previously /// defined bucket configuration properties.</param> /// <remarks>If a node does not respond, that does not necessarily mean that the /// <paramref name="bucket"/>/<paramref name="key"/> combination is not available. It simply means /// that fewer than R/PR nodes responded to the read request. See <see cref="CorrugatedIron.Models.RiakGetOptions" /> /// for information on how different options change Riak's default behavior. /// </remarks> public RiakResult <RiakObject> Get(string bucket, string key, RiakGetOptions options = null) { if (!IsValidBucketOrKey(bucket)) { return(RiakResult <RiakObject> .Error(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false)); } if (!IsValidBucketOrKey(key)) { return(RiakResult <RiakObject> .Error(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false)); } var request = new RpbGetReq { bucket = bucket.ToRiakString(), key = key.ToRiakString() }; options = options ?? new RiakGetOptions(); options.Populate(request); var result = UseConnection(conn => conn.PbcWriteRead <RpbGetReq, RpbGetResp>(request)); if (!result.IsSuccess) { return(RiakResult <RiakObject> .Error(result.ResultCode, result.ErrorMessage, result.NodeOffline)); } if (result.Value.vclock == null) { return(RiakResult <RiakObject> .Error(ResultCode.NotFound, "Unable to find value in Riak", false)); } var o = new RiakObject(bucket, key, result.Value.content, result.Value.vclock); return(RiakResult <RiakObject> .Success(o)); }
/// <summary> /// Retrieve multiple objects from Riak. /// </summary> /// <param name='bucketKeyPairs'> /// An <see href="System.Collections.Generic.IEnumerable<T>"/> of <see cref="CorrugatedIron.Models.RiakObjectId"/> to be retrieved /// </param> /// <param name='options'>The <see cref="CorrugatedIron.Models.RiakGetOptions" /> responsible for /// configuring the semantics of this single get request. These options will override any previously /// defined bucket configuration properties.</param> /// <returns>An <see cref="System.Collections.Generic.IEnumerable{T}"/> of <see cref="RiakResult{T}"/> /// is returned. You should verify the success or failure of each result separately.</returns> /// <remarks>Riak does not support multi get behavior. CorrugatedIron's multi get functionality wraps multiple /// get requests and returns results as an IEnumerable{RiakResult{RiakObject}}. Callers should be aware that /// this may result in partial success - all results should be evaluated individually in the calling application. /// In addition, applications should plan for multiple failures or multiple cases of siblings being present.</remarks> public IEnumerable <RiakResult <RiakObject> > Get(IEnumerable <RiakObjectId> bucketKeyPairs, RiakGetOptions options = null) { bucketKeyPairs = bucketKeyPairs.ToList(); options = options ?? new RiakGetOptions(); var results = UseConnection(conn => { var responses = bucketKeyPairs.Select(bkp => { // modified closure FTW var bk = bkp; if (!IsValidBucketOrKey(bk.Bucket)) { return(RiakResult <RpbGetResp> .Error(ResultCode.InvalidRequest, InvalidBucketErrorMessage, false)); } if (!IsValidBucketOrKey(bk.Key)) { return(RiakResult <RpbGetResp> .Error(ResultCode.InvalidRequest, InvalidKeyErrorMessage, false)); } var req = new RpbGetReq { bucket = bk.Bucket.ToRiakString(), key = bk.Key.ToRiakString() }; options.Populate(req); return(conn.PbcWriteRead <RpbGetReq, RpbGetResp>(req)); }).ToList(); return(RiakResult <IEnumerable <RiakResult <RpbGetResp> > > .Success(responses)); }); return(results.Value.Zip(bucketKeyPairs, Tuple.Create).Select(result => { if (!result.Item1.IsSuccess) { return RiakResult <RiakObject> .Error(result.Item1.ResultCode, result.Item1.ErrorMessage, result.Item1.NodeOffline); } if (result.Item1.Value.vclock == null) { return RiakResult <RiakObject> .Error(ResultCode.NotFound, "Unable to find value in Riak", false); } var o = new RiakObject(result.Item2.Bucket, result.Item2.Key, result.Item1.Value.content.First(), result.Item1.Value.vclock); if (result.Item1.Value.content.Count > 1) { o.Siblings = result.Item1.Value.content.Select(c => new RiakObject(result.Item2.Bucket, result.Item2.Key, c, result.Item1.Value.vclock)).ToList(); } return RiakResult <RiakObject> .Success(o); })); }
/// <summary> /// Get the specified <paramref name="key"/> from the <paramref name="bucket"/>. /// Optionally can be read from <paramref name="rVal"/> instances. By default, the server's /// r-value will be used, but can be overridden by <paramref name="rVal"/>. /// </summary> /// <param name='bucket'> /// The name of the bucket containing the <paramref name="key"/> /// </param> /// <param name='key'> /// The key. /// </param> /// <param name='rVal'> /// The number of nodes required to successfully respond to the read before the read is considered a success. /// </param> /// <remarks>If a node does not respond, that does not necessarily mean that the /// <paramref name="bucket"/>/<paramref name="key"/> combination is not available. It simply means /// that less than <paramref name="rVal" /> nodes successfully responded to the read request. Unfortunatley, /// the Riak API does not allow us to distinguish between a 404 resulting from less than <paramref name="rVal"/> /// nodes successfully responding and a <paramref name="bucket"/>/<paramref name="key"/> combination /// not being found in Riak. /// </remarks> public RiakResult <RiakObject> Get(string bucket, string key, uint rVal = RiakConstants.Defaults.RVal) { var request = new RpbGetReq { Bucket = bucket.ToRiakString(), Key = key.ToRiakString(), R = rVal }; var result = UseConnection(conn => conn.PbcWriteRead <RpbGetReq, RpbGetResp>(request)); if (!result.IsSuccess) { return(RiakResult <RiakObject> .Error(result.ResultCode, result.ErrorMessage)); } if (result.Value.VectorClock == null) { return(RiakResult <RiakObject> .Error(ResultCode.NotFound)); } var o = new RiakObject(bucket, key, result.Value.Content, result.Value.VectorClock); return(RiakResult <RiakObject> .Success(o)); }
public async Task <Either <RiakException, RiakObject> > Get(string bucket, string key, RiakGetOptions options = null) { options = options ?? RiakClient.DefaultGetOptions(); if (!IsValidBucketOrKey(bucket)) { return(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.InvalidRequest, InvalidBucketErrorMessage, false))); } if (!IsValidBucketOrKey(key)) { return(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.InvalidRequest, InvalidKeyErrorMessage, false))); } var request = new RpbGetReq { bucket = bucket.ToRiakString(), key = key.ToRiakString() }; options = options ?? new RiakGetOptions(); options.Populate(request); try { var result = await _connection.PbcWriteRead <RpbGetReq, RpbGetResp>(_endPoint, request).ConfigureAwait(false); if (result.vclock == null) { return(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.NotFound, "Unable to find value in Riak", false))); } var riakObject = new RiakObject(bucket, key, result.content, result.vclock); return(new Either <RiakException, RiakObject>(riakObject)); } catch (RiakException riakException) { return(new Either <RiakException, RiakObject>(riakException)); } }
public IObservable <Either <RiakException, RiakObject> > Get(IEnumerable <RiakObjectId> bucketKeyPairs, RiakGetOptions options = null) { var observable = Observable.Create <Either <RiakException, RiakObject> >(async obs => { try { bucketKeyPairs = bucketKeyPairs.ToList(); options = options ?? new RiakGetOptions(); foreach (var bucketKeyPair in bucketKeyPairs) { // modified closure FTW var bk = bucketKeyPair; if (!IsValidBucketOrKey(bk.Bucket)) { obs.OnNext(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.InvalidRequest, InvalidBucketErrorMessage, false))); continue; } if (!IsValidBucketOrKey(bk.Key)) { obs.OnNext(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.InvalidRequest, InvalidKeyErrorMessage, false))); continue; } var req = new RpbGetReq { bucket = bk.Bucket.ToRiakString(), key = bk.Key.ToRiakString() }; options.Populate(req); try { var result = await _connection.PbcWriteRead <RpbGetReq, RpbGetResp>(_endPoint, req) .ConfigureAwait(false); if (result.vclock == null) { obs.OnNext(new Either <RiakException, RiakObject>(new RiakException((uint)ResultCode.NotFound, "Unable to find value in Riak", false))); continue; } var riakObject = new RiakObject(bk.Bucket, bk.Key, result.content.First(), result.vclock); if (result.content.Count > 1) { riakObject.Siblings = result.content .Select(c => new RiakObject(bk.Bucket, bk.Key, c, result.vclock)) .ToList(); } obs.OnNext(new Either <RiakException, RiakObject>(riakObject)); } catch (RiakException riakException) { obs.OnNext(new Either <RiakException, RiakObject>(riakException)); } } obs.OnCompleted(); } catch (Exception exception) { obs.OnError(exception); } return(Disposable.Empty); }); return(observable); }