public async Task SendAsync(IOperation operation, SessionInfo sessionInfo = null, CancellationToken token = default) { using (GetContext(out JsonOperationContext context)) { var command = operation.GetCommand(_store, _requestExecutor.Conventions, context, _requestExecutor.Cache); await _requestExecutor.ExecuteAsync(command, context, sessionInfo, token).ConfigureAwait(false); } }
public Task SendAsync(IOperation operation, CancellationToken token = default(CancellationToken), SessionInfo sessionInfo = null, bool isServerOperation = false) { using (GetContext(out JsonOperationContext context)) { var command = operation.GetCommand(_store, _requestExecutor.Conventions, context, _requestExecutor.Cache); return(_requestExecutor.ExecuteAsync(command, context, token, sessionInfo)); } }
private async Task WaitForId() { if (_operationId != -1) { return; } var bulkInsertGetIdRequest = new GetNextOperationIdCommand(); await _requestExecutor.ExecuteAsync(bulkInsertGetIdRequest, _context, sessionInfo : null, token : _token).ConfigureAwait(false); _operationId = bulkInsertGetIdRequest.Result; }
/// <summary> /// Since operation might complete before we subscribe to it, /// fetch operation status but only once to avoid race condition /// If we receive notification using changes API meanwhile, ignore fetched status /// to avoid issues with non monotonic increasing progress /// </summary> protected async Task FetchOperationStatus() { await _lock.WaitAsync().ConfigureAwait(false); OperationState state; try { if (_result.Task.IsCompleted) { return; } var command = GetOperationStateCommand(_conventions, _id); await _requestExecutor.ExecuteAsync(command, _context, sessionInfo : null, token : CancellationToken.None).ConfigureAwait(false); state = command.Result; } finally { _lock.Release(); } OnNext(new OperationStatusChange { OperationId = _id, State = state }); }
private async Task <bool> ExecuteLazyOperationsSingleStep(ResponseTimeInformation responseTimeInformation, List <GetRequest> requests, CancellationToken token = default) { var multiGetOperation = new MultiGetOperation(this); var multiGetCommand = multiGetOperation.CreateRequest(requests); await RequestExecutor.ExecuteAsync(multiGetCommand, Context, sessionInfo : SessionInfo, token : token).ConfigureAwait(false); var responses = multiGetCommand.Result; for (var i = 0; i < PendingLazyOperations.Count; i++) { var response = responses[i]; response.Headers.TryGetValue(Constants.Headers.RequestTime, out string tempReqTime); long.TryParse(tempReqTime, out long totalTime); responseTimeInformation.DurationBreakdown.Add(new ResponseTimeItem { Url = requests[i].UrlAndQuery, Duration = TimeSpan.FromMilliseconds(totalTime) }); if (response.RequestHasErrors()) { throw new InvalidOperationException("Got an error from server, status code: " + (int)response.StatusCode + Environment.NewLine + response.Result); } PendingLazyOperations[i].HandleResponse(response); if (PendingLazyOperations[i].RequiresRetry) { return(true); } } return(false); }
public async Task <bool> ExistsAsync(string documentId, string name) { var command = new HeadAttachmentCommand(documentId, name, null); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo).ConfigureAwait(false); return(command.Result != null); }
private async Task <Stream> GetDebugInfoFromNodeAsync( JsonOperationContext context, RequestExecutor requestExecutor, IEnumerable <string> databaseNames) { var bodyJson = new DynamicJsonValue { [nameof(NodeDebugInfoRequestHeader.FromUrl)] = ServerStore.GetNodeHttpServerUrl(), [nameof(NodeDebugInfoRequestHeader.DatabaseNames)] = databaseNames }; using (var ms = new MemoryStream()) using (var writer = new BlittableJsonTextWriter(context, ms)) { context.Write(writer, bodyJson); writer.Flush(); ms.Flush(); var rawStreamCommand = new GetRawStreamResultCommand($"admin/debug/remote-cluster-info-package", ms); await requestExecutor.ExecuteAsync(rawStreamCommand, context); rawStreamCommand.Result.Position = 0; return(rawStreamCommand.Result); } }
/// <summary> /// Begins the async save changes operation /// </summary> /// <returns></returns> public async Task SaveChangesAsync(CancellationToken token = default(CancellationToken)) { using (AsyncTaskHolder()) { if (_asyncDocumentIdGeneration != null) { await _asyncDocumentIdGeneration.GenerateDocumentIdsForSaveChanges().WithCancellation(token).ConfigureAwait(false); } var saveChangesOperation = new BatchOperation(this); using (var command = saveChangesOperation.CreateRequest()) { if (command == null) { return; } if (NoTracking) { throw new InvalidOperationException($"Cannot execute '{nameof(SaveChangesAsync)}' when entity tracking is disabled in session."); } await RequestExecutor.ExecuteAsync(command, Context, _sessionInfo, token).ConfigureAwait(false); UpdateSessionAfterSaveChanges(command.Result); saveChangesOperation.SetResult(command.Result); } } }
public async Task <bool> ExistsAsync(string id, CancellationToken token = default) { using (AsyncTaskHolder()) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (_knownMissingIds.Contains(id)) { return(false); } if (DocumentsById.TryGetValue(id, out _)) { return(true); } var command = new HeadDocumentCommand(id, null); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : _sessionInfo, token : token).ConfigureAwait(false); return(command.Result != null); } }
protected override int LoadInternal(IEnumerable <ICommandData> items, DocumentsOperationContext context, EtlStatsScope scope) { var commands = items as List <ICommandData>; Debug.Assert(commands != null); if (commands.Count == 0) { return(0); } if (ShouldTrackTimeSeries()) { foreach (var command in commands) { if (command is TimeSeriesBatchCommandData tsbc) { if (TimeSeriesHandler.CheckIfIncrementalTs(tsbc.Name)) { throw new NotSupportedException($"Load isn't support for incremental time series '{tsbc.Name}' at document '{tsbc.Id}'"); } } } } BatchOptions options = null; if (Configuration.LoadRequestTimeoutInSec != null) { options = new BatchOptions { RequestTimeout = TimeSpan.FromSeconds(Configuration.LoadRequestTimeoutInSec.Value) }; } using (var batchCommand = new SingleNodeBatchCommand(DocumentConventions.DefaultForServer, context, commands, options)) { var duration = Stopwatch.StartNew(); try { BeforeActualLoad?.Invoke(this); AsyncHelpers.RunSync(() => _requestExecutor.ExecuteAsync(batchCommand, context, token: CancellationToken)); _recentUrl = _requestExecutor.Url; return(commands.Count); } catch (OperationCanceledException e) { if (CancellationToken.IsCancellationRequested == false) { ThrowTimeoutException(commands.Count, duration.Elapsed, e); } throw; } } }
public static void ExecuteWithCancellationToken <TResult>( this RequestExecutor requestExecutor, RavenCommand <TResult> command, JsonOperationContext context, CancellationToken token) { AsyncHelpers.RunSync(() => requestExecutor.ExecuteAsync(command, context, sessionInfo: null, token)); }
public async Task <T> GetAsync <T>(string changeVector) { var operation = new GetRevisionOperation(Session, changeVector); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo).ConfigureAwait(false); operation.SetResult(command.Result); return(operation.GetRevision <T>()); }
public async Task <List <T> > GetForAsync <T>(string id, int start = 0, int pageSize = 25) { var operation = new GetRevisionOperation(Session, id, start, pageSize); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo).ConfigureAwait(false); operation.SetResult(command.Result); return(operation.GetRevisionsFor <T>()); }
public async Task <T> GetAsync <T>(string id, DateTime date, CancellationToken token = default) { var operation = new GetRevisionOperation(Session, id, date); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo, token : token).ConfigureAwait(false); operation.SetResult(command.Result); return(operation.GetRevisionsFor <T>().FirstOrDefault()); }
public async Task <Dictionary <string, T> > GetAsync <T>(IEnumerable <string> changeVectors, CancellationToken token = default) { var operation = new GetRevisionOperation(Session, changeVectors); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo, token).ConfigureAwait(false); operation.SetResult(command.Result); return(operation.GetRevisions <T>()); }
public async Task <List <MetadataAsDictionary> > GetMetadataForAsync(string id, int start = 0, int pageSize = 25, CancellationToken token = default) { var operation = new GetRevisionOperation(Session, id, start, pageSize, true); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo, token : token).ConfigureAwait(false); operation.SetResult(command.Result); return(operation.GetRevisionsMetadataFor()); }
private async Task ExecuteAsync <TResult>( RavenCommand <TResult> command, CancellationToken token = default) { using (_requestExecutor.ContextPool.AllocateOperationContext(out var context)) { await _requestExecutor.ExecuteAsync(command, context, token : token).ConfigureAwait(false); } }
public async Task <bool> ExistsAsync(string documentId, string name, CancellationToken token = default) { using (Session.AsyncTaskHolder()) { var command = new HeadAttachmentCommand(documentId, name, null); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo, token).ConfigureAwait(false); return(command.Result != null); } }
private async Task <long> GetOperationId() { using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out JsonOperationContext context)) { var getNextOperationIdRequest = new GetNextOperationIdCommand(); await _requestExecutor.ExecuteAsync(getNextOperationIdRequest, context, CancelToken.Token); return(getNextOperationIdRequest.Result); } }
private async Task <Stream> GetDebugInfoFromNodeAsync( JsonOperationContext context, RequestExecutor requestExecutor) { var rawStreamCommand = new GetRawStreamResultCommand($"/admin/debug/info-package"); await requestExecutor.ExecuteAsync(rawStreamCommand, context); rawStreamCommand.Result.Position = 0; return(rawStreamCommand.Result); }
public async Task <long> GetCountForAsync(string id, CancellationToken token = default) { using (Session.AsyncTaskHolder()) { var operation = new GetRevisionsCountOperation(id); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo, token : token).ConfigureAwait(false); return(command.Result); } }
public async Task <Operation> SendAsync(IMaintenanceOperation <OperationIdResult> operation, CancellationToken token = default(CancellationToken)) { using (RequestExecutor.ContextPool.AllocateOperationContext(out var context)) { var command = operation.GetCommand(_requestExecutor.Conventions, context); await _requestExecutor.ExecuteAsync(command, context, token).ConfigureAwait(false); return(new Operation(_requestExecutor, () => _store.Changes(_databaseName), _requestExecutor.Conventions, command.Result.OperationId)); } }
public async Task <IAsyncEnumerator <StreamResult <T> > > StreamAsync <T>(string startsWith, string matches = null, int start = 0, int pageSize = int.MaxValue, string startAfter = null, CancellationToken token = default) { var streamOperation = new StreamOperation(this); var command = streamOperation.CreateRequest(startsWith, matches, start, pageSize, null, startAfter); await RequestExecutor.ExecuteAsync(command, Context, SessionInfo, token).ConfigureAwait(false); var result = streamOperation.SetResultAsync(command.Result); return(new YieldStream <T>(this, null, null, result, token)); }
/// <summary> /// Since operation might complete before we subscribe to it, /// fetch operation status but only once to avoid race condition /// If we receive notification using changes API meanwhile, ignore fetched status /// to avoid issues with non monotonic increasing progress /// </summary> protected async Task FetchOperationStatus() { var command = GetOperationStateCommand(_conventions, _id); await _requestExecutor.ExecuteAsync(command, _context).ConfigureAwait(false); OnNext(new OperationStatusChange { OperationId = _id, State = command.Result }); }
public async Task <List <T> > GetForAsync <T>(string id, int start = 0, int pageSize = 25, CancellationToken token = default) { using (Session.AsyncTaskHolder()) { var operation = new GetRevisionOperation(Session, id, start, pageSize); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, SessionInfo, token).ConfigureAwait(false); operation.SetResult(command.Result); return(operation.GetRevisionsFor <T>()); } }
public async Task <T> GetAsync <T>(string changeVector, CancellationToken token = default) { using (Session.AsyncTaskHolder()) { var operation = new GetRevisionOperation(Session, changeVector); var command = operation.CreateRequest(); await RequestExecutor.ExecuteAsync(command, Context, sessionInfo : SessionInfo, token).ConfigureAwait(false); operation.SetResult(command.Result); return(operation.GetRevision <T>()); } }
public async Task StreamIntoAsync <T>(IAsyncDocumentQuery <T> query, Stream output, CancellationToken token = default) { var streamOperation = new StreamOperation(this); var command = streamOperation.CreateRequest(query.GetIndexQuery()); await RequestExecutor.ExecuteAsync(command, Context, SessionInfo, token).ConfigureAwait(false); using (command.Result.Response) using (command.Result.Stream) { await command.Result.Stream.CopyToAsync(output, 16 * 1024, token).ConfigureAwait(false); } }
/// <summary> /// Since operation might complete before we subscribe to it, /// fetch operation status but only once to avoid race condition /// If we receive notification using changes API meanwhile, ignore fetched status /// to avoid issues with non monotonic increasing progress /// </summary> protected async Task FetchOperationStatus() { await _lock.WaitAsync().ConfigureAwait(false); OperationState state = null; try { for (var i = 0; i < 10; i++) { if (_result.Task.IsCompleted) { return; } var command = GetOperationStateCommand(_conventions, _id); await _requestExecutor.ExecuteAsync(command, _context, sessionInfo : null, token : CancellationToken.None).ConfigureAwait(false); state = command.Result; // in most of the cases this will only perform one loop // but for operations like smuggler-ones there is a race probability // between sending the request to perform the operation // and registering it // this is why we are trying to get the state few times if (state != null) { break; } await Task.Delay(500).ConfigureAwait(false); } } finally { _lock.Release(); } if (state == null) { throw new InvalidOperationException($"Could not fetch state of operation '{_id}'."); } OnNext(new OperationStatusChange { OperationId = _id, State = state }); }
public async Task RefreshAsync <T>(T entity, CancellationToken token = default(CancellationToken)) { DocumentInfo documentInfo; if (DocumentsByEntity.TryGetValue(entity, out documentInfo) == false) { throw new InvalidOperationException("Cannot refresh a transient instance"); } IncrementRequestCount(); var command = new GetDocumentsCommand(new[] { documentInfo.Id }, includes: null, metadataOnly: false); await RequestExecutor.ExecuteAsync(command, Context, SessionInfo, token).ConfigureAwait(false); RefreshInternal(entity, command, documentInfo); }
private async Task <IAsyncEnumerator <StreamResult <T> > > PerformQueryStreamOperation <T>(IAsyncDocumentQuery <T> query, StreamQueryStatistics streamQueryStats, CancellationToken token) { var documentQuery = (AsyncDocumentQuery <T>)query; var fieldsToFetch = documentQuery.FieldsToFetchToken; var indexQuery = query.GetIndexQuery(); var streamOperation = new StreamOperation(this, streamQueryStats); var command = streamOperation.CreateRequest(indexQuery); await RequestExecutor.ExecuteAsync(command, Context, SessionInfo, token).ConfigureAwait(false); var result = streamOperation.SetResultAsync(command.Result); var queryOperation = ((AsyncDocumentQuery <T>)query).InitializeQueryOperation(); queryOperation.NoTracking = true; return(new YieldStream <T>(this, query, fieldsToFetch, result, token)); }