Ejemplo n.º 1
0
 public ExecutingQueryInfo(DateTime startTime, IIndexQuery queryInfo, long queryId, OperationCancelToken token)
 {
     StartTime  = startTime;
     QueryInfo  = queryInfo;
     QueryId    = queryId;
     _stopwatch = Stopwatch.StartNew();
     Token      = token;
 }
Ejemplo n.º 2
0
        public async Task ImportFromCsv()
        {
            using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                if (HttpContext.Request.HasFormContentType == false)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        context.Write(writer, new DynamicJsonValue
                        {
                            ["Type"] = "Error",
                            ["Error"] = "Import from csv requires form content type"
                        });
                        return;
                    }
                }
                var token = new OperationCancelToken(Database.DatabaseShutdown);
                var result = new SmugglerResult();
                var operationId = GetLongQueryString("operationId", false) ?? Database.Operations.GetNextOperationId();
                var collection = GetStringQueryString("collection", false);
                var operationDescription = collection != null ? "Import collection: " + collection : "Import collection from CSV";
                await Database.Operations.AddOperation(Database, operationDescription, Raven.Server.Documents.Operations.Operations.OperationType.CollectionImportFromCsv,
                    onProgress =>
                    {
                        return Task.Run(async () =>
                        {
                            try
                            {
                                var reader = new MultipartReader(MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(HttpContext.Request.ContentType),
                                    MultipartRequestHelper.MultipartBoundaryLengthLimit), HttpContext.Request.Body);
                                while (true)
                                {
                                    var section = await reader.ReadNextSectionAsync().ConfigureAwait(false);
                                    if (section == null)
                                        break;

                                    if (ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out ContentDispositionHeaderValue contentDisposition) == false)
                                        continue;

                                    if (MultipartRequestHelper.HasFileContentDisposition(contentDisposition))
                                    {
                                        if (ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out contentDisposition) == false)
                                            continue;

                                        if (string.IsNullOrEmpty(collection))
                                        {
                                            var fileName = contentDisposition.FileName.ToString().Trim('\"');
                                            collection = Inflector.Pluralize(CSharpClassName.ConvertToValidClassName(Path.GetFileNameWithoutExtension(fileName)));
                                        }
                                        
                                        var options = new DatabaseSmugglerOptionsServerSide();
                                        if (section.Headers.ContainsKey("Content-Encoding") && section.Headers["Content-Encoding"] == "gzip")
                                        {
                                            using (var gzipStream = new GZipStream(section.Body, CompressionMode.Decompress))
                                            {
                                                ImportDocumentsFromCsvStream(gzipStream, context, collection, options, result, onProgress, token);
                                            }
                                        }
                                        else
                                        {
                                            ImportDocumentsFromCsvStream(section.Body, context, collection, options, result, onProgress, token);
                                        }
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                result.AddError($"Error occurred during csv import. Exception: {e.Message}");
                                throw;
                            }
                            return (IOperationResult)result;
                        });
                    }, operationId, token);
                
                WriteImportResult(context, result, ResponseBodyStream());
            }
        }
Ejemplo n.º 3
0
        private void DoImportInternal(DocumentsOperationContext context, Stream stream, DatabaseSmugglerOptionsServerSide options, SmugglerResult result, Action<IOperationProgress> onProgress, OperationCancelToken token)
        {
            using (stream)
            using (token)
            using (var source = new StreamSource(stream, context, Database))
            {
                var destination = new DatabaseDestination(Database);
                var smuggler = new DatabaseSmuggler(Database, source, destination, Database.Time, options, result, onProgress, token.Token);

                smuggler.Execute();
            }
        }
Ejemplo n.º 4
0
        public async Task <FacetedQueryResult> ExecuteFacetedQuery(IndexQueryServerSide query, long?existingResultEtag, QueryOperationContext queryContext, OperationCancelToken token)
        {
            if (query.Metadata.IsDynamic)
            {
                throw new InvalidQueryException("Facet query must be executed against static index.", query.Metadata.QueryText, query.QueryParameters);
            }

            var fq = FacetQuery.Create(queryContext.Documents, query);

            var index = GetIndex(query.Metadata.IndexName);

            queryContext.WithIndex(index);

            if (existingResultEtag.HasValue)
            {
                var etag = index.GetIndexEtag(queryContext, query.Metadata) ^ fq.FacetsEtag;
                if (etag == existingResultEtag)
                {
                    return(FacetedQueryResult.NotModifiedResult);
                }
            }

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await index.FacetedQuery(fq, queryContext, token));
            }
        }
Ejemplo n.º 5
0
 public RestoreFromAzure(ServerStore serverStore, RestoreFromAzureConfiguration restoreFromConfiguration, string nodeTag, OperationCancelToken operationCancelToken) : base(serverStore, restoreFromConfiguration, nodeTag, operationCancelToken)
 {
     _client           = new RavenAzureClient(restoreFromConfiguration.Settings);
     _remoteFolderName = restoreFromConfiguration.Settings.RemoteFolderName;
 }
Ejemplo n.º 6
0
        public override async Task <IOperationResult> ExecutePatchQuery(IndexQueryServerSide query, QueryOperationOptions options, PatchRequest patch, BlittableJsonReaderObject patchArgs, QueryOperationContext queryContext, Action <IOperationProgress> onProgress, OperationCancelToken token)
        {
            var index = GetIndex(query.Metadata.IndexName);

            queryContext.WithIndex(index);

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await ExecutePatch(query, index, options, patch, patchArgs, queryContext, onProgress, token));
            }
        }
Ejemplo n.º 7
0
        public override async Task ExecuteStreamIndexEntriesQuery(IndexQueryServerSide query, QueryOperationContext queryContext, HttpResponse response, IStreamQueryResultWriter <BlittableJsonReaderObject> writer, OperationCancelToken token)
        {
            var index = GetIndex(query.Metadata.IndexName);

            queryContext.WithIndex(index);

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token, true))
            {
                await index.StreamIndexEntriesQuery(response, writer, query, queryContext, token);
            }
        }
Ejemplo n.º 8
0
        public override async Task <DocumentQueryResult> ExecuteQuery(IndexQueryServerSide query, DocumentsOperationContext documentsContext, long?existingResultEtag, OperationCancelToken token)
        {
            Index index;

            using (query.Timings?.For(nameof(QueryTimingsScope.Names.Optimizer)))
                index = await MatchIndex(query, true, null, documentsContext, token.Token);

            if (query.Metadata.HasOrderByRandom == false && existingResultEtag.HasValue)
            {
                var etag = index.GetIndexEtag(query.Metadata);
                if (etag == existingResultEtag)
                {
                    return(DocumentQueryResult.NotModifiedResult);
                }
            }

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await index.Query(query, documentsContext, token));
            }
        }
Ejemplo n.º 9
0
        public override async Task <IndexEntriesQueryResult> ExecuteIndexEntriesQuery(IndexQueryServerSide query, DocumentsOperationContext context, long?existingResultEtag, OperationCancelToken token)
        {
            var index = await MatchIndex(query, false, null, context, token.Token);

            if (index == null)
            {
                IndexDoesNotExistException.ThrowFor(query.Metadata.CollectionName);
            }

            if (existingResultEtag.HasValue)
            {
                var etag = index.GetIndexEtag(query.Metadata);
                if (etag == existingResultEtag)
                {
                    return(IndexEntriesQueryResult.NotModifiedResult);
                }
            }

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await index.IndexEntries(query, context, token));
            }
        }
Ejemplo n.º 10
0
        public override Task <IOperationResult> ExecutePatchQuery(IndexQueryServerSide query, QueryOperationOptions options, PatchRequest patch, BlittableJsonReaderObject patchArgs, DocumentsOperationContext context, Action <IOperationProgress> onProgress, OperationCancelToken token)
        {
            var runner = new CollectionRunner(Database, context, query);

            return(runner.ExecutePatch(query.Metadata.CollectionName, new CollectionOperationOptions
            {
                MaxOpsPerSecond = options.MaxOpsPerSecond
            }, patch, patchArgs, onProgress, token));
        }
Ejemplo n.º 11
0
        public override async Task <SuggestionQueryResult> ExecuteSuggestionQuery(IndexQueryServerSide query, DocumentsOperationContext documentsContext, long?existingResultEtag, OperationCancelToken token)
        {
            var index = await MatchIndex(query, true, null, documentsContext, token.Token);

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await ExecuteSuggestion(query, index, documentsContext, existingResultEtag, token));
            }
        }
Ejemplo n.º 12
0
        public override Task <IOperationResult> ExecuteDeleteQuery(IndexQueryServerSide query, QueryOperationOptions options, DocumentsOperationContext context, Action <IOperationProgress> onProgress, OperationCancelToken token)
        {
            var runner = new CollectionRunner(Database, context, query);

            return(runner.ExecuteDelete(query.Metadata.CollectionName, new CollectionOperationOptions
            {
                MaxOpsPerSecond = options.MaxOpsPerSecond
            }, onProgress, token));
        }
Ejemplo n.º 13
0
 public override Task <IndexEntriesQueryResult> ExecuteIndexEntriesQuery(IndexQueryServerSide query, DocumentsOperationContext context, long?existingResultEtag, OperationCancelToken token)
 {
     throw new NotSupportedException("Collection query is handled directly by documents storage so index entries aren't created underneath");
 }
Ejemplo n.º 14
0
        public override Task <DocumentQueryResult> ExecuteQuery(IndexQueryServerSide query, DocumentsOperationContext documentsContext, long?existingResultEtag, OperationCancelToken token)
        {
            var result = new DocumentQueryResult();

            documentsContext.OpenReadTransaction();

            FillCountOfResultsAndIndexEtag(result, query.Metadata, documentsContext);

            if (query.Metadata.HasOrderByRandom == false && existingResultEtag.HasValue)
            {
                if (result.ResultEtag == existingResultEtag)
                {
                    return(Task.FromResult(DocumentQueryResult.NotModifiedResult));
                }
            }

            ExecuteCollectionQuery(result, query, query.Metadata.CollectionName, documentsContext, token.Token);

            return(Task.FromResult(result));
        }
Ejemplo n.º 15
0
        private async Task FacetedQuery(IndexQueryServerSide indexQuery, QueryOperationContext queryContext, OperationCancelToken token)
        {
            var existingResultEtag = GetLongFromHeaders("If-None-Match");

            var result = await Database.QueryRunner.ExecuteFacetedQuery(indexQuery, existingResultEtag, queryContext, token);

            if (result.NotModified)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified;
                return;
            }

            HttpContext.Response.Headers[Constants.Headers.Etag] = CharExtensions.ToInvariantString(result.ResultEtag);

            long numberOfResults;

            using (var writer = new BlittableJsonTextWriter(queryContext.Documents, ResponseBodyStream()))
            {
                writer.WriteFacetedQueryResult(queryContext.Documents, result, numberOfResults: out numberOfResults);
            }

            Database.QueryMetadataCache.MaybeAddToCache(indexQuery.Metadata, result.IndexName);
            AddPagingPerformanceHint(PagingOperationType.Queries, $"{nameof(FacetedQuery)} ({result.IndexName})", indexQuery.Query, numberOfResults, indexQuery.PageSize, result.DurationInMs);
        }
Ejemplo n.º 16
0
 public override Task ExecuteStreamIndexEntriesQuery(IndexQueryServerSide query, DocumentsOperationContext documentsContext, HttpResponse response,
                                                     IStreamQueryResultWriter <BlittableJsonReaderObject> writer, OperationCancelToken token)
 {
     throw new NotSupportedException("Collection query is handled directly by documents storage so index entries aren't created underneath");
 }
Ejemplo n.º 17
0
        public override async Task <IOperationResult> ExecuteDeleteQuery(IndexQueryServerSide query, QueryOperationOptions options, QueryOperationContext queryContext, Action <IOperationProgress> onProgress, OperationCancelToken token)
        {
            var index = GetIndex(query.Metadata.IndexName);

            queryContext.WithIndex(index);

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await ExecuteDelete(query, index, options, queryContext, onProgress, token));
            }
        }
Ejemplo n.º 18
0
        public override async Task <IOperationResult> ExecuteDeleteQuery(IndexQueryServerSide query, QueryOperationOptions options, DocumentsOperationContext context, Action <IOperationProgress> onProgress, OperationCancelToken token)
        {
            var index = await MatchIndex(query, true, null, context, token.Token);

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await ExecuteDelete(query, index, options, context, onProgress, token));
            }
        }
Ejemplo n.º 19
0
        public override async Task <SuggestionQueryResult> ExecuteSuggestionQuery(IndexQueryServerSide query, QueryOperationContext queryContext, long?existingResultEtag, OperationCancelToken token)
        {
            var index = GetIndex(query.Metadata.IndexName);

            queryContext.WithIndex(index);

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await ExecuteSuggestion(query, index, queryContext, existingResultEtag, token));
            }
        }
Ejemplo n.º 20
0
        public async Task StripRevisionFlagFromTombstoneWithExternalReplication()
        {
            using (var store1 = GetDocumentStore(new Options
            {
                ModifyDatabaseName = s => $"{s}_FooBar-1"
            }))
                using (var store2 = GetDocumentStore(new Options
                {
                    ModifyDatabaseName = s => $"{s}_FooBar-2"
                }))
                {
                    await SetupReplicationAsync(store1, store2);

                    await RevisionsHelper.SetupRevisions(store1, Server.ServerStore, new RevisionsConfiguration()
                    {
                        Default = new RevisionsCollectionConfiguration()
                        {
                            Disabled = false
                        }
                    });

                    var user = new User()
                    {
                        Name = "Toli"
                    };
                    using (var session = store1.OpenAsyncSession())
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            user.Age = i;
                            await session.StoreAsync(user, "users/1");

                            await session.SaveChangesAsync();
                        }
                        session.Delete("users/1");
                        await session.SaveChangesAsync();
                    }
                    var db = await GetDocumentDatabaseInstanceFor(store2, store2.Database);

                    var val2 = await WaitForValueAsync(() =>
                    {
                        using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext ctx))
                            using (ctx.OpenReadTransaction())
                            {
                                var rev = db.DocumentsStorage.RevisionsStorage.GetRevisions(ctx, "users/1", 0, 1);
                                return(rev.Count);
                            }
                    }, 1
                                                       );

                    Assert.Equal(1, val2);
                    await RevisionsHelper.SetupRevisions(store1, Server.ServerStore, new RevisionsConfiguration());

                    db = await GetDocumentDatabaseInstanceFor(store1, store1.Database);

                    using (var token = new OperationCancelToken(db.Configuration.Databases.OperationTimeout.AsTimeSpan, db.DatabaseShutdown, CancellationToken.None))
                        await db.DocumentsStorage.RevisionsStorage.EnforceConfiguration(_ => { }, token);
                    var val = await WaitForValueAsync(() =>
                    {
                        using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext ctx))
                            using (ctx.OpenReadTransaction())
                            {
                                var tombstone = db.DocumentsStorage.GetDocumentOrTombstone(ctx, "users/1");
                                return(tombstone.Tombstone.Flags.Contain(DocumentFlags.HasRevisions));
                            }
                    }, false
                                                      );

                    Assert.False(val);

                    using (var session = store1.OpenAsyncSession())
                    {
                        await session.StoreAsync(user, "marker");

                        await session.SaveChangesAsync();
                    }

                    var res = WaitForDocument(store2, "marker");
                    Assert.True(res);

                    db = await GetDocumentDatabaseInstanceFor(store2, store2.Database);

                    val2 = await WaitForValueAsync(() =>
                    {
                        using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext ctx))
                            using (ctx.OpenReadTransaction())
                            {
                                var rev = db.DocumentsStorage.RevisionsStorage.GetRevisions(ctx, "users/1", 0, 1);
                                return(rev.Count);
                            }
                    }, 0
                                                   );

                    Assert.Equal(0, val2);

                    val = await WaitForValueAsync(() =>
                    {
                        using (db.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext ctx))
                            using (ctx.OpenReadTransaction())
                            {
                                var tombstone = db.DocumentsStorage.GetDocumentOrTombstone(ctx, "users/1");
                                return(tombstone.Tombstone.Flags.Contain(DocumentFlags.HasRevisions));
                            }
                    }, false
                                                  );

                    Assert.False(val);
                }
        }
Ejemplo n.º 21
0
        public override async Task <IndexEntriesQueryResult> ExecuteIndexEntriesQuery(IndexQueryServerSide query, QueryOperationContext queryContext, long?existingResultEtag, OperationCancelToken token)
        {
            var index = GetIndex(query.Metadata.IndexName);

            queryContext.WithIndex(index);

            if (existingResultEtag.HasValue)
            {
                var etag = index.GetIndexEtag(queryContext, query.Metadata);
                if (etag == existingResultEtag)
                {
                    return(IndexEntriesQueryResult.NotModifiedResult);
                }
            }

            using (QueryRunner.MarkQueryAsRunning(index.Name, query, token))
            {
                return(await index.IndexEntries(query, queryContext, token));
            }
        }
Ejemplo n.º 22
0
        public Task <IOperationResult> AddOperation(string description, PendingOperationType opererationType, Func <Action <IOperationProgress>, Task <IOperationResult> > taskFactory,
                                                    long id, OperationCancelToken token = null)
        {
            var operationState = new OperationState
            {
                Status = OperationStatus.InProgress
            };

            var notification = new OperationStatusChangeNotification
            {
                OperationId = id,
                State       = operationState
            };

            Action <IOperationProgress> action = progress =>
            {
                notification.State.Progress = progress;
                RaiseNotifications(notification);
            };
            var task = taskFactory(action);

            var operationDescription = new PendingOperationDescription
            {
                Description = description,
                TaskType    = opererationType,
                StartTime   = SystemTime.UtcNow
            };

            var pendingOperation = new PendingOperation
            {
                Id          = id,
                Task        = task,
                Description = operationDescription,
                Token       = token,
                State       = operationState
            };

            task.ContinueWith(taskResult =>
            {
                operationDescription.EndTime = SystemTime.UtcNow;
                operationState.Progress      = null;
                if (taskResult.IsCanceled)
                {
                    operationState.Result = null;
                    operationState.Status = OperationStatus.Canceled;
                }
                else if (taskResult.IsFaulted)
                {
                    var innerException = taskResult.Exception.ExtractSingleInnerException();

                    var documentConflictException = innerException as DocumentConflictException;
                    var status            = documentConflictException != null ? 409 : 500;
                    operationState.Result = new OperationExceptionResult(innerException, status);
                    operationState.Status = OperationStatus.Faulted;
                }
                else
                {
                    operationState.Result = taskResult.Result;
                    operationState.Status = OperationStatus.Completed;
                }

                RaiseNotifications(notification);
            });

            _pendingOperations.TryAdd(id, pendingOperation);
            return(task);
        }
Ejemplo n.º 23
0
 public DynamicQueryRunner(IndexStore indexStore, TransformerStore transformerStore, DocumentsStorage documents, DocumentsOperationContext context, OperationCancelToken token)
 {
     _indexStore       = indexStore;
     _transformerStore = transformerStore;
     _context          = context;
     _token            = token;
     _documents        = documents;
 }
Ejemplo n.º 24
0
        public EdgeQueryStep(IGraphQueryStep left, IGraphQueryStep right, WithEdgesExpression edgesExpression, MatchPath edgePath, BlittableJsonReaderObject queryParameters, OperationCancelToken token)
        {
            _left  = left;
            _right = right;

            _aliases = new HashSet <string>();

            _aliases.UnionWith(_left.GetAllAliases());
            _aliases.UnionWith(_right.GetAllAliases());
            _aliases.Add(edgePath.Alias.Value);

            _edgePath        = edgePath;
            _queryParameters = queryParameters;
            _edgesExpression = edgesExpression;

            _outputAlias = _right.GetOutputAlias();
            _token       = token;
        }
Ejemplo n.º 25
0
        protected RestoreBackupTaskBase(ServerStore serverStore,
                                        RestoreBackupConfigurationBase restoreFromConfiguration,
                                        string nodeTag,
                                        OperationCancelToken operationCancelToken)
        {
            _serverStore             = serverStore;
            RestoreFromConfiguration = restoreFromConfiguration;
            _nodeTag = nodeTag;
            _operationCancelToken = operationCancelToken;

            var dataDirectoryThatWillBeUsed = string.IsNullOrWhiteSpace(RestoreFromConfiguration.DataDirectory) ?
                                              _serverStore.Configuration.Core.DataDirectory.FullPath :
                                              new PathSetting(RestoreFromConfiguration.DataDirectory, _serverStore.Configuration.Core.DataDirectory.FullPath).FullPath;

            if (ResourceNameValidator.IsValidResourceName(RestoreFromConfiguration.DatabaseName, dataDirectoryThatWillBeUsed, out string errorMessage) == false)
            {
                throw new InvalidOperationException(errorMessage);
            }

            _serverStore.EnsureNotPassive();

            ClusterTopology clusterTopology;

            using (_serverStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context))
                using (context.OpenReadTransaction())
                {
                    if (_serverStore.Cluster.DatabaseExists(context, RestoreFromConfiguration.DatabaseName))
                    {
                        throw new ArgumentException($"Cannot restore data to an existing database named {RestoreFromConfiguration.DatabaseName}");
                    }

                    clusterTopology = _serverStore.GetClusterTopology(context);
                }

            _hasEncryptionKey = string.IsNullOrWhiteSpace(RestoreFromConfiguration.EncryptionKey) == false;
            if (_hasEncryptionKey)
            {
                var key = Convert.FromBase64String(RestoreFromConfiguration.EncryptionKey);
                if (key.Length != 256 / 8)
                {
                    throw new InvalidOperationException($"The size of the key must be 256 bits, but was {key.Length * 8} bits.");
                }

                if (AdminDatabasesHandler.NotUsingHttps(clusterTopology.GetUrlFromTag(_serverStore.NodeTag)))
                {
                    throw new InvalidOperationException("Cannot restore an encrypted database to a node which doesn't support SSL!");
                }
            }

            var backupEncryptionSettings = RestoreFromConfiguration.BackupEncryptionSettings;

            if (backupEncryptionSettings != null)
            {
                if (backupEncryptionSettings.EncryptionMode == EncryptionMode.UseProvidedKey &&
                    backupEncryptionSettings.Key == null)
                {
                    throw new InvalidOperationException($"{nameof(BackupEncryptionSettings.EncryptionMode)} is set to {nameof(EncryptionMode.UseProvidedKey)} but an encryption key wasn't provided");
                }


                if (backupEncryptionSettings.EncryptionMode != EncryptionMode.UseProvidedKey &&
                    backupEncryptionSettings.Key != null)
                {
                    throw new InvalidOperationException($"{nameof(BackupEncryptionSettings.EncryptionMode)} is set to {backupEncryptionSettings.EncryptionMode} but an encryption key was provided");
                }
            }

            var hasRestoreDataDirectory = string.IsNullOrWhiteSpace(RestoreFromConfiguration.DataDirectory) == false;

            if (hasRestoreDataDirectory &&
                HasFilesOrDirectories(dataDirectoryThatWillBeUsed))
            {
                throw new ArgumentException("New data directory must be empty of any files or folders, " +
                                            $"path: {dataDirectoryThatWillBeUsed}");
            }

            if (hasRestoreDataDirectory == false)
            {
                RestoreFromConfiguration.DataDirectory = GetDataDirectory();
            }

            _restoringToDefaultDataDirectory = IsDefaultDataDirectory(RestoreFromConfiguration.DataDirectory, RestoreFromConfiguration.DatabaseName);
        }
Ejemplo n.º 26
0
        public EdgeQueryStep(IGraphQueryStep left, IGraphQueryStep right, EdgeQueryStep eqs, OperationCancelToken token)
        {
            _left    = left;
            _right   = right;
            _aliases = new HashSet <string>();

            _aliases.UnionWith(_left.GetAllAliases());
            _aliases.UnionWith(_right.GetAllAliases());
            _aliases.Add(eqs._edgePath.Alias.Value);

            _edgePath        = eqs._edgePath;
            _queryParameters = eqs._queryParameters;
            _edgesExpression = eqs._edgesExpression;


            _outputAlias = _right.GetOutputAlias();
            _token       = token;
        }
Ejemplo n.º 27
0
        private void ImportDocumentsFromCsvStream(Stream stream, DocumentsOperationContext context, string entity, DatabaseSmugglerOptionsServerSide options, SmugglerResult result, Action<IOperationProgress> onProgress, OperationCancelToken token)
        {
            if (string.IsNullOrEmpty(entity) == false && char.IsLower(entity[0]))
                entity = char.ToUpper(entity[0]) + entity.Substring(1);

            result.AddInfo($"Import collection: {entity}");
            using (var source = new CsvStreamSource(Database, stream, context, entity))
            {
                var destination = new DatabaseDestination(Database);
                var smuggler = new DatabaseSmuggler(Database, source, destination, Database.Time, options, result, onProgress, token.Token);
                smuggler.Execute();
            }
        }
Ejemplo n.º 28
0
        private async Task Query(QueryOperationContext queryContext, OperationCancelToken token, RequestTimeTracker tracker, HttpMethod method, bool diagnostics)
        {
            var indexQuery = await GetIndexQuery(queryContext.Documents, method, tracker);

            indexQuery.Diagnostics        = diagnostics ? new List <string>() : null;
            indexQuery.AddTimeSeriesNames = GetBoolValueQueryString("addTimeSeriesNames", false) ?? false;

            queryContext.WithQuery(indexQuery.Metadata);

            if (TrafficWatchManager.HasRegisteredClients)
            {
                TrafficWatchQuery(indexQuery);
            }

            var existingResultEtag = GetLongFromHeaders("If-None-Match");

            if (indexQuery.Metadata.HasFacet)
            {
                await FacetedQuery(indexQuery, queryContext, token);

                return;
            }

            if (indexQuery.Metadata.HasSuggest)
            {
                await SuggestQuery(indexQuery, queryContext, token);

                return;
            }

            var metadataOnly = GetBoolValueQueryString("metadataOnly", required: false) ?? false;
            var shouldReturnServerSideQuery = GetBoolValueQueryString("includeServerSideQuery", required: false) ?? false;

            DocumentQueryResult result;

            try
            {
                result = await Database.QueryRunner.ExecuteQuery(indexQuery, queryContext, existingResultEtag, token).ConfigureAwait(false);
            }
            catch (IndexDoesNotExistException)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            if (result.NotModified)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified;
                return;
            }

            HttpContext.Response.Headers[Constants.Headers.Etag] = CharExtensions.ToInvariantString(result.ResultEtag);

            int numberOfResults;

            using (var writer = new AsyncBlittableJsonTextWriter(queryContext.Documents, ResponseBodyStream(), Database.DatabaseShutdown))
            {
                result.Timings  = indexQuery.Timings?.ToTimings();
                numberOfResults = await writer.WriteDocumentQueryResultAsync(queryContext.Documents, result, metadataOnly, WriteAdditionalData(indexQuery, shouldReturnServerSideQuery));

                await writer.OuterFlushAsync();
            }

            Database.QueryMetadataCache.MaybeAddToCache(indexQuery.Metadata, result.IndexName);
            AddPagingPerformanceHint(PagingOperationType.Queries, $"{nameof(Query)} ({result.IndexName})", indexQuery.Query, numberOfResults, indexQuery.PageSize, result.DurationInMs);
        }
Ejemplo n.º 29
0
        public async Task EnforceRevisionConfigurationWithConflict()
        {
            using (var store1 = GetDocumentStore(new Options
            {
                ModifyDatabaseName = s => $"{s}_foo1",
                ModifyDatabaseRecord = record =>
                {
                    record.ConflictSolverConfig = new ConflictSolver
                    {
                        ResolveToLatest = false,
                        ResolveByCollection = new Dictionary <string, ScriptResolver>()
                    };
                }
            }))
                using (var store2 = GetDocumentStore(new Options
                {
                    ModifyDatabaseName = s => $"{s}_foo2",
                    ModifyDatabaseRecord = record =>
                    {
                        record.ConflictSolverConfig = new ConflictSolver
                        {
                            ResolveToLatest = false,
                            ResolveByCollection = new Dictionary <string, ScriptResolver>()
                        };
                    }
                }))
                {
                    await RevisionsHelper.SetupRevisions(store1, Server.ServerStore, new RevisionsConfiguration()
                    {
                        Default = new RevisionsCollectionConfiguration()
                        {
                            Disabled = false
                        }
                    });

                    WaitForUserToContinueTheTest(store1);
                    using (var s1 = store1.OpenSession())
                    {
                        s1.Store(new User {
                            Name = "test"
                        }, "users/1");
                        s1.SaveChanges();
                    }

                    using (var s2 = store2.OpenSession())
                    {
                        s2.Store(new User {
                            Name = "test3"
                        }, "users/1");
                        s2.SaveChanges();
                    }

                    await SetupReplicationAsync(store2, store1);

                    var conflicts = WaitUntilHasConflict(store1, "users/1");
                    await RevisionsHelper.SetupRevisions(store1, Server.ServerStore, new RevisionsConfiguration());

                    var db = await Databases.GetDocumentDatabaseInstanceFor(store1, store1.Database);

                    using (var token = new OperationCancelToken(db.Configuration.Databases.OperationTimeout.AsTimeSpan, db.DatabaseShutdown, CancellationToken.None))
                        await db.DocumentsStorage.RevisionsStorage.EnforceConfiguration(_ => { }, token);

                    await UpdateConflictResolver(store1, resolveToLatest : true);

                    WaitForValue(() => store1.Commands().GetConflictsFor("users/1").Length, 0);

                    using (var session = store1.OpenAsyncSession())
                    {
                        var revision = await session.Advanced.Revisions.GetForAsync <User>("users/1");

                        Assert.Equal(3, revision.Count);
                    }
                }
        }
Ejemplo n.º 30
0
        public BackupUploader(BackupUploaderSettings backupUploaderSettings, RetentionPolicyBaseParameters retentionPolicyParameters, Logger logger, BackupResult backupResult, Action <IOperationProgress> onProgress, OperationCancelToken taskCancelToken)
        {
            _backupUploaderSettings = backupUploaderSettings;
            _threads    = new List <PoolOfThreads.LongRunningWork>();
            _exceptions = new ConcurrentSet <Exception>();

            _retentionPolicyParameters = retentionPolicyParameters;
            _isFullBackup = retentionPolicyParameters.IsFullBackup;

            TaskCancelToken = taskCancelToken;
            _logger         = logger;
            _backupResult   = backupResult;
            _onProgress     = onProgress;
        }