コード例 #1
0
        public Task Compact()
        {
            var name = GetQueryStringValueAndAssertIfSingleAndNotEmpty("name");

            var index = Database.IndexStore.GetIndex(name);

            if (index == null)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Task.CompletedTask);
            }

            var token       = CreateOperationToken();
            var operationId = Database.Operations.GetNextOperationId();

            Database.Operations.AddOperation(
                "Compact index: " + index.Name,
                DatabaseOperations.PendingOperationType.IndexCompact,
                onProgress => Task.Factory.StartNew(() => index.Compact(onProgress), token.Token), operationId, token);

            JsonOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteOperationId(context, operationId);
                }

            return(Task.CompletedTask);
        }
コード例 #2
0
ファイル: SmugglerHandler.cs プロジェクト: otgoo0603/ravendb
        public async Task Migrate()
        {
            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                var migrationConfiguration = await context.ReadForMemoryAsync(RequestBodyStream(), "migration-configuration");

                var migrationConfigurationJson = JsonDeserializationServer.SingleDatabaseMigrationConfiguration(migrationConfiguration);

                if (string.IsNullOrWhiteSpace(migrationConfigurationJson.ServerUrl))
                {
                    throw new ArgumentException("Url cannot be null or empty");
                }

                if (string.IsNullOrWhiteSpace(migrationConfigurationJson.DatabaseName))
                {
                    throw new ArgumentException("Database name cannot be null or empty");
                }

                var migrator = new Migrator(migrationConfigurationJson, ServerStore, Database.DatabaseShutdown);
                await migrator.UpdateBuildInfoIfNeeded();

                var operationId = migrator.StartMigratingSingleDatabase(migrationConfigurationJson.DatabaseName, Database);

                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteOperationId(context, operationId);
                }
            }
        }
コード例 #3
0
        private void ExecuteQueryOperation(IndexQueryServerSide query,
                                           Func <QueryRunner,
                                                 QueryOperationOptions,
                                                 Action <IOperationProgress>, OperationCancelToken,
                                                 Task <IOperationResult> > operation,
                                           DocumentsOperationContext context,
                                           IDisposable returnContextToPool,
                                           Operations.Operations.OperationType operationType)
        {
            var options = GetQueryOperationOptions();
            var token   = CreateTimeLimitedOperationToken();

            var operationId = Database.Operations.GetNextOperationId();

            var task = Database.Operations.AddOperation(Database, query.Metadata.IndexName, operationType,
                                                        onProgress => operation(Database.QueryRunner, options, onProgress, token), operationId, token);

            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                writer.WriteOperationId(context, operationId);
            }

            task.ContinueWith(_ =>
            {
                using (returnContextToPool)
                    token.Dispose();
            });
        }
コード例 #4
0
ファイル: SetupHandler.cs プロジェクト: janmarques/ravendb
        public Task ForceRenew()
        {
            using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context))
                using (var setupInfoJson = context.ReadForDisk(RequestBodyStream(), "setup-lets-encrypt"))
                {
                    var setupInfo = JsonDeserializationServer.SetupInfo(setupInfoJson);

                    var operationCancelToken = new OperationCancelToken(ServerStore.ServerShutdown);
                    var operationId          = ServerStore.Operations.GetNextOperationId();

                    ServerStore.Operations.AddOperation(
                        null,
                        "Setting up RavenDB with a Let's Encrypt certificate",
                        Documents.Operations.Operations.OperationType.Setup,
                        progress => SetupManager.SetupLetsEncryptTask(progress, operationCancelToken.Token, setupInfo, ServerStore),
                        operationId, operationCancelToken);

                    using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                    {
                        writer.WriteOperationId(context, operationId);
                    }

                    HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
                    return(Task.CompletedTask);
                }
        }
コード例 #5
0
        public async Task StartRecording()
        {
            if (Database.TxMerger.RecordingEnabled)
            {
                throw new BadRequestException("Another recording is already in progress");
            }

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                var json = await context.ReadForMemoryAsync(RequestBodyStream(), null);

                var parameters = JsonDeserializationServer.StartTransactionsRecordingOperationParameters(json);
                if (parameters.File == null)
                {
                    ThrowRequiredPropertyNameInRequest(nameof(parameters.File));
                }

                var tcs         = new TaskCompletionSource <IOperationResult>(TaskCreationOptions.RunContinuationsAsynchronously);
                var operationId = ServerStore.Operations.GetNextOperationId();

                var command = new StartTransactionsRecordingCommand(
                    Database.TxMerger,
                    parameters.File,
                    () => tcs.SetResult(null)     // we don't provide any completion details
                    );

                await Database.TxMerger.Enqueue(command);

                var task = ServerStore.Operations.AddOperation(null,
                                                               "Recording for: '" + Database.Name + ". Output file: '" + parameters.File + "'",
                                                               Operations.Operations.OperationType.RecordTransactionCommands,
                                                               progress =>
                {
                    // push this notification to studio
                    progress(null);

                    return(tcs.Task);
                },
                                                               operationId,
                                                               new RecordingDetails
                {
                    DatabaseName = Database.Name,
                    FilePath     = parameters.File
                });

                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    writer.WriteOperationId(context, operationId);
                }
            }
        }
コード例 #6
0
        private void ExecuteQueryOperation(Func <QueryRunner, string, IndexQueryServerSide, QueryOperationOptions, Action <IOperationProgress>, OperationCancelToken, Task <IOperationResult> > operation, DocumentsOperationContext context, IDisposable returnContextToPool, DatabaseOperations.PendingOperationType operationType)
        {
            var indexName = RouteMatch.Url.Substring(RouteMatch.MatchLength);

            var query   = IndexQueryServerSide.Create(HttpContext, GetStart(), GetPageSize(int.MaxValue), context);
            var options = GetQueryOperationOptions();
            var token   = CreateTimeLimitedOperationToken();

            var queryRunner = new QueryRunner(Database, context);

            var operationId = Database.Operations.GetNextOperationId();

            var task = Database.Operations.AddOperation(indexName, operationType, onProgress =>
                                                        operation(queryRunner, indexName, query, options, onProgress, token), operationId, token);

            task.ContinueWith(_ => returnContextToPool.Dispose());

            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                writer.WriteOperationId(context, operationId);
            }
        }
コード例 #7
0
        private void ExecuteCollectionOperation(Func <CollectionRunner, string, CollectionOperationOptions, Action <IOperationProgress>, OperationCancelToken, Task <IOperationResult> > operation, DocumentsOperationContext context, IDisposable returnContextToPool, DatabaseOperations.PendingOperationType operationType)
        {
            var collectionName = GetStringQueryString("name");

            var token = CreateTimeLimitedOperationToken();

            var collectionRunner = new CollectionRunner(Database, context);

            var operationId = Database.Operations.GetNextOperationId();

            var options = GetCollectionOperationOptions();

            var task = Database.Operations.AddOperation(collectionName, operationType, onProgress =>
                                                        operation(collectionRunner, collectionName, options, onProgress, token), operationId, token);

            task.ContinueWith(_ => returnContextToPool.Dispose());

            using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
            {
                writer.WriteOperationId(context, operationId);
            }
        }