public async Task Revert() { RevertRevisionsRequest configuration; using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context)) { var json = await context.ReadForMemoryAsync(RequestBodyStream(), "revisions/revert"); configuration = JsonDeserializationServer.RevertRevisions(json); } var token = CreateTimeLimitedOperationToken(); var operationId = ServerStore.Operations.GetNextOperationId(); var t = Database.Operations.AddOperation( Database, $"Revert database '{Database.Name}' to {configuration.Time} UTC.", Operations.Operations.OperationType.DatabaseRevert, onProgress => Database.DocumentsStorage.RevisionsStorage.RevertRevisions(configuration.Time, TimeSpan.FromSeconds(configuration.WindowInSec), onProgress, token), operationId, token: token); using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context)) using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteOperationIdAndNodeTag(context, operationId, ServerStore.NodeTag); } }
public async Task MigrateFromRavenDB() { 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 (migrationConfigurationJson.MigrationSettings == null) { throw new ArgumentException("MigrationSettings cannot be null"); } if (string.IsNullOrWhiteSpace(migrationConfigurationJson.MigrationSettings.DatabaseName)) { throw new ArgumentException("Database name cannot be null or empty"); } var migrator = new Migrator(migrationConfigurationJson, ServerStore); await migrator.UpdateBuildInfoIfNeeded(); var operationId = migrator.StartMigratingSingleDatabase(migrationConfigurationJson.MigrationSettings, Database); using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteOperationIdAndNodeTag(context, operationId, ServerStore.NodeTag); } } }
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.WriteOperationIdAndNodeTag(context, operationId, ServerStore.NodeTag); } } }
public Task EnforceConfigRevisions() { var token = CreateTimeLimitedOperationToken(); var operationId = ServerStore.Operations.GetNextOperationId(); var t = Database.Operations.AddOperation( Database, $"Enforce revision configuration in database '{Database.Name}'.", Operations.Operations.OperationType.EnforceRevisionConfiguration, onProgress => Database.DocumentsStorage.RevisionsStorage.EnforceConfiguration(onProgress, token), operationId, token: token); using (ServerStore.ContextPool.AllocateOperationContext(out JsonOperationContext context)) using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteOperationIdAndNodeTag(context, operationId, ServerStore.NodeTag); } return(Task.CompletedTask); }
private void ExecuteQueryOperation(IndexQueryServerSide query, Func <QueryRunner, QueryOperationOptions, Action <IOperationProgress>, OperationCancelToken, Task <IOperationResult> > operation, QueryOperationContext queryContext, IDisposable returnContextToPool, Operations.Operations.OperationType operationType) { var options = GetQueryOperationOptions(); var token = CreateTimeLimitedQueryOperationToken(); var operationId = Database.Operations.GetNextOperationId(); var indexName = query.Metadata.IsDynamic ? (query.Metadata.IsCollectionQuery ? "collection/" : "dynamic/") + query.Metadata.CollectionName : query.Metadata.IndexName; var details = new BulkOperationResult.OperationDetails { Query = query.Query }; var task = Database.Operations.AddOperation( Database, indexName, operationType, onProgress => operation(Database.QueryRunner, options, onProgress, token), operationId, details, token); using (var writer = new BlittableJsonTextWriter(queryContext.Documents, ResponseBodyStream())) { writer.WriteOperationIdAndNodeTag(queryContext.Documents, operationId, ServerStore.NodeTag); } task.ContinueWith(_ => { using (returnContextToPool) token.Dispose(); }); }
private void ExecuteCollectionOperation(Func <CollectionRunner, string, CollectionOperationOptions, Action <IOperationProgress>, OperationCancelToken, Task <IOperationResult> > operation, DocumentsOperationContext context, IDisposable returnContextToPool, Documents.Operations.Operations.OperationType operationType, HashSet <string> excludeIds) { var collectionName = GetStringQueryString("name"); var token = CreateTimeLimitedCollectionOperationToken(); var collectionRunner = new StudioCollectionRunner(Database, context, excludeIds); var operationId = Database.Operations.GetNextOperationId(); // use default options var options = new CollectionOperationOptions(); var task = Database.Operations.AddOperation(Database, collectionName, operationType, onProgress => operation(collectionRunner, collectionName, options, onProgress, token), operationId, token: token); task.ContinueWith(_ => returnContextToPool.Dispose()); using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteOperationIdAndNodeTag(context, operationId, ServerStore.NodeTag); } }
public Task Dump() { var name = GetStringQueryString("name"); var path = GetStringQueryString("path"); var index = Database.IndexStore.GetIndex(name); if (index == null) { IndexDoesNotExistException.ThrowFor(name); return(null);//never hit } var operationId = Database.Operations.GetNextOperationId(); var token = CreateTimeLimitedQueryOperationToken(); Database.Operations.AddOperation( Database, "Dump index " + name + " to " + path, Operations.Operations.OperationType.DumpRawIndexData, onProgress => { var totalFiles = index.Dump(path, onProgress); return(Task.FromResult((IOperationResult) new DumpIndexResult { Message = $"Dumped {totalFiles} files from {name}", })); }, operationId, token: token); using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context)) using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteOperationIdAndNodeTag(context, operationId, ServerStore.NodeTag); } return(Task.CompletedTask); }