public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) throw new ArgumentNullException("configuration"); try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration); systemDatabase.SpinBackgroundWorkers(); } else { systemDatabase = db; } fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); } catch { if (systemDatabase != null) systemDatabase.Dispose(); throw; } }
public WebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) { DatabasesLandlord = databasesLandlord; this.countersLandlord = countersLandlord; this.fileSystemsLandlord = fileSystemsLandlord; this.authorizer = authorizer; this.expectedRequestSuffix = expectedRequestSuffix; }
private void CleanupFileSystems(DatabasesLandlord databaseLandlord, FileSystemsLandlord fileSystemLandlord) { var systemDatabase = databaseLandlord.SystemDatabase; int nextStart = 0; var fileSystemDocuments = systemDatabase .Documents .GetDocumentsWithIdStartingWith(Constants.FileSystem.Prefix, null, null, 0, int.MaxValue, CancellationToken.None, ref nextStart); var fileSystemIds = fileSystemDocuments .Select(x => ((RavenJObject)x)["@metadata"]) .Where(x => x != null) .Select(x => x.Value<string>("@id")) .Where(x => x != null && x != Constants.SystemDatabase) .ToList(); foreach (var fileSystemId in fileSystemIds) { try { var key = fileSystemId; if (key.StartsWith(Constants.FileSystem.Prefix)) key = key.Substring(Constants.FileSystem.Prefix.Length); var shouldCleanup = false; DateTime value; if (fileSystemLandlord.IsFileSystemLoaded(key) == false) shouldCleanup = true; else if (fileSystemLandlord.LastRecentlyUsed.TryGetValue(key, out value) == false || (SystemTime.UtcNow - value) > maxTimeResourceCanBeIdle) shouldCleanup = true; if (shouldCleanup == false) continue; var configuration = fileSystemLandlord.CreateTenantConfiguration(key, true); fileSystemLandlord.Cleanup(key, maxTimeResourceCanBeIdle, database => false); var docKey = Constants.FileSystem.Prefix + key; systemDatabase.Documents.Delete(docKey, null, null); if (configuration == null) continue; IOExtensions.DeleteDirectory(configuration.FileSystem.DataDirectory); } catch (Exception e) { log.WarnException(string.Format("Failed to cleanup '{0}' filesystem.", fileSystemId), e); } } }
public RequestManager(DatabasesLandlord landlord) { BeforeRequest += OnBeforeRequest; cancellationTokenSource = new CancellationTokenSource(); this.landlord = landlord; maxTimeDatabaseCanBeIdle = TimeSpan.FromSeconds(landlord.MaxIdleTimeForTenantDatabaseInSec); frequencyToCheckForIdleDatabases = TimeSpan.FromSeconds(landlord.FrequencyToCheckForIdleDatabasesInSec); Init(); cancellationToken = cancellationTokenSource.Token; }
public RequestManager(DatabasesLandlord landlord) { BeforeRequest+=OnBeforeRequest; cancellationTokenSource = new CancellationTokenSource(); this.landlord = landlord; int val; if (int.TryParse(landlord.SystemConfiguration.Settings["Raven/Tenants/MaxIdleTimeForTenantDatabase"], out val) == false) val = 900; maxTimeDatabaseCanBeIdle = TimeSpan.FromSeconds(val); if (int.TryParse(landlord.SystemConfiguration.Settings["Raven/Tenants/FrequencyToCheckForIdleDatabases"], out val) == false) val = 60; frequencyToCheckForIdleDatabases = TimeSpan.FromSeconds(val); Init(); cancellationToken = cancellationTokenSource.Token; }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) throw new ArgumentNullException("configuration"); try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); ThreadPool.SetMinThreads(configuration.MinThreadPoolWorkerThreads, configuration.MinThreadPoolCompletionThreads); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration); systemDatabase.SpinBackgroundWorkers(false); } else { systemDatabase = db; } WebSocketBufferPool.Initialize(configuration.WebSockets.InitialBufferPoolSize); fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); serverStartupTasks = configuration.Container.GetExportedValues<IServerStartupTask>(); foreach (var task in serverStartupTasks) { toDispose.Add(task); task.Execute(this); } } catch { if (systemDatabase != null) systemDatabase.Dispose(); throw; } }
private static HttpConfiguration CreateHttpCfg( DatabasesLandlord databasesLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer mixedModeRequestAuthorizer, RequestManager requestManager) { var cfg = new HttpConfiguration(); cfg.Properties[typeof(DatabasesLandlord)] = databasesLandlord; cfg.Properties[typeof(FileSystemsLandlord)] = fileSystemsLandlord; cfg.Properties[typeof(MixedModeRequestAuthorizer)] = mixedModeRequestAuthorizer; cfg.Properties[typeof(RequestManager)] = requestManager; cfg.Formatters.Remove(cfg.Formatters.XmlFormatter); cfg.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new NaveValueCollectionJsonConverterOnlyForConfigFormatters()); cfg.Services.Replace(typeof(IAssembliesResolver), new MyAssemblyResolver()); cfg.Filters.Add(new RavenExceptionFilterAttribute()); cfg.MapHttpAttributeRoutes(); cfg.Routes.MapHttpRoute( "RavenFs", "ravenfs/{controller}/{action}", new {id = RouteParameter.Optional}); cfg.Routes.MapHttpRoute( "API Default", "{controller}/{action}", new { id = RouteParameter.Optional }); cfg.Routes.MapHttpRoute( "Database Route", "databases/{databaseName}/{controller}/{action}", new { id = RouteParameter.Optional }); cfg.MessageHandlers.Add(new GZipToJsonAndCompressHandler()); cfg.Services.Replace(typeof(IHostBufferPolicySelector), new SelectiveBufferPolicySelector()); cfg.EnsureInitialized(); return cfg; }
protected DatabaseBundleScalarObjectBase(string databaseName, string bundleName, DatabasesLandlord landlord, int databaseIndex, int bundleIndex, string dots) : base(databaseName, landlord, string.Format("5.2.{0}.6.{{0}}.{1}", databaseIndex, dots), bundleIndex) { BundleName = bundleName; }
public DatabaseLoaded(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, "5.2.{0}.1.13", index) { this.databaseName = databaseName; }
private static bool IsIncrementalBackupIsAllowed(DatabasesLandlord databaseLandlord,DatabaseDocument dbDoc) { // check if DatabaseDocument contains either of the incremental flags bool isVoronIncrementalBackup = dbDoc.Settings.ContainsKey("Raven/Voron/AllowIncrementalBackups"); bool isEsentCircularLog = dbDoc.Settings.ContainsKey("Raven/Esent/CircularLog"); if ( isVoronIncrementalBackup || isEsentCircularLog) { if (isEsentCircularLog && bool.TryParse(dbDoc.Settings["Raven/Esent/CircularLog"], out isEsentCircularLog)) { return (isEsentCircularLog) ? false : true; } else if (isVoronIncrementalBackup && bool.TryParse(dbDoc.Settings["Raven/Voron/AllowIncrementalBackups"], out isVoronIncrementalBackup)) { return isVoronIncrementalBackup; } } // if not check if system configuration has one of the incremental flags up. string isVoronIncrementalBackupStr = databaseLandlord.SystemConfiguration.Settings["Raven/Voron/AllowIncrementalBackups"]; string isEsentCircularLogStr = databaseLandlord.SystemConfiguration.Settings["Raven/Esent/CircularLog"]; if (isVoronIncrementalBackupStr != null || isEsentCircularLogStr != null) { if (isEsentCircularLogStr != null && bool.TryParse(isEsentCircularLogStr, out isEsentCircularLog)) { return (isEsentCircularLog) ? false : true; } else if (isVoronIncrementalBackupStr != null && bool.TryParse(isVoronIncrementalBackupStr, out isVoronIncrementalBackup)) { return isVoronIncrementalBackup; } } return false; }
public DatabaseDataWrittenPerSecond(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, SnmpOids.Databases.DataWrittenPerSecond, index) { }
public async Task <HttpResponseMessage> Restore() { if (EnsureSystemDatabase() == false) { return(GetMessageWithString("Restore is only possible from the system database", HttpStatusCode.BadRequest)); } var restoreStatus = new RestoreStatus { State = RestoreStatusState.Running, Messages = new List <string>() }; var restoreRequest = await ReadJsonObjectAsync <DatabaseRestoreRequest>(); DatabaseDocument databaseDocument = null; var databaseDocumentPath = MaintenanceActions.FindDatabaseDocument(restoreRequest.BackupLocation); if (File.Exists(databaseDocumentPath)) { var databaseDocumentText = File.ReadAllText(databaseDocumentPath); databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization <DatabaseDocument>(); } var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName : databaseDocument == null ? null : databaseDocument.Id; if (string.IsNullOrWhiteSpace(databaseName)) { var errorMessage = (databaseDocument == null || String.IsNullOrWhiteSpace(databaseDocument.Id)) ? "Database.Document file is invalid - database name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen." : "A database name must be supplied if the restore location does not contain a valid Database.Document file"; restoreStatus.Messages.Add(errorMessage); DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null, RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null); return(GetMessageWithString(errorMessage, HttpStatusCode.BadRequest)); } if (databaseName == Constants.SystemDatabase) { return(GetMessageWithString("Cannot do an online restore for the <system> database", HttpStatusCode.BadRequest)); } var existingDatabase = Database.Documents.GetDocumentMetadata("Raven/Databases/" + databaseName, null); if (existingDatabase != null) { return(GetMessageWithString("Cannot do an online restore for an existing database, delete the database " + databaseName + " and restore again.", HttpStatusCode.BadRequest)); } var ravenConfiguration = new RavenConfiguration { DatabaseName = databaseName, IsTenantDatabase = true }; if (databaseDocument != null) { foreach (var setting in databaseDocument.Settings) { ravenConfiguration.Settings[setting.Key] = setting.Value; } } if (File.Exists(Path.Combine(restoreRequest.BackupLocation, BackupMethods.Filename))) { ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Voron.TransactionalStorage).AssemblyQualifiedName; } else if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new"))) { ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName; } ravenConfiguration.CustomizeValuesForDatabaseTenant(databaseName); ravenConfiguration.Initialize(); string documentDataDir; ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir); restoreRequest.DatabaseLocation = ravenConfiguration.DataDirectory; string anotherRestoreResourceName; if (IsAnotherRestoreInProgress(out anotherRestoreResourceName)) { if (restoreRequest.RestoreStartTimeout.HasValue) { try { using (var cts = new CancellationTokenSource()) { cts.CancelAfter(TimeSpan.FromSeconds(restoreRequest.RestoreStartTimeout.Value)); var token = cts.Token; do { await Task.Delay(500, token); }while (IsAnotherRestoreInProgress(out anotherRestoreResourceName)); } } catch (OperationCanceledException) { return(GetMessageWithString(string.Format("Another restore is still in progress (resource name = {0}). Waited {1} seconds for other restore to complete.", anotherRestoreResourceName, restoreRequest.RestoreStartTimeout.Value), HttpStatusCode.ServiceUnavailable)); } } else { return(GetMessageWithString(string.Format("Another restore is in progress (resource name = {0})", anotherRestoreResourceName), HttpStatusCode.ServiceUnavailable)); } } Database.Documents.Put(RestoreInProgress.RavenRestoreInProgressDocumentKey, null, RavenJObject.FromObject(new RestoreInProgress { Resource = databaseName }), new RavenJObject(), null); DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, null); bool defrag; if (bool.TryParse(GetQueryStringValue("defrag"), out defrag)) { restoreRequest.Defrag = defrag; } var task = Task.Factory.StartNew(() => { try { MaintenanceActions.Restore(ravenConfiguration, restoreRequest, msg => { restoreStatus.Messages.Add(msg); DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null, RavenJObject.FromObject(restoreStatus), new RavenJObject(), null); }); if (databaseDocument == null) { return; } databaseDocument.Settings[Constants.RavenDataDir] = documentDataDir; if (restoreRequest.IndexesLocation != null) { databaseDocument.Settings[Constants.RavenIndexPath] = restoreRequest.IndexesLocation; } if (restoreRequest.JournalsLocation != null) { databaseDocument.Settings[Constants.RavenTxJournalPath] = restoreRequest.JournalsLocation; } bool replicationBundleRemoved = false; if (restoreRequest.DisableReplicationDestinations) { replicationBundleRemoved = TryRemoveReplicationBundle(databaseDocument); } databaseDocument.Id = databaseName; DatabasesLandlord.Protect(databaseDocument); DatabasesLandlord .SystemDatabase .Documents .Put("Raven/Databases/" + databaseName, null, RavenJObject.FromObject(databaseDocument), new RavenJObject(), null); restoreStatus.Messages.Add("The new database was created"); restoreStatus.State = RestoreStatusState.Completed; DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null, RavenJObject.FromObject(restoreStatus), new RavenJObject(), null); if (restoreRequest.GenerateNewDatabaseId) { GenerateNewDatabaseId(databaseName); } if (replicationBundleRemoved) { AddReplicationBundleAndDisableReplicationDestinations(databaseName); } } catch (Exception e) { restoreStatus.State = RestoreStatusState.Faulted; restoreStatus.Messages.Add("Unable to restore database " + e.Message); DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null, RavenJObject.FromObject(restoreStatus), new RavenJObject(), null); throw; } finally { Database.Documents.Delete(RestoreInProgress.RavenRestoreInProgressDocumentKey, null, null); } }, TaskCreationOptions.LongRunning); long id; Database.Tasks.AddTask(task, new TaskBasedOperationState(task), new TaskActions.PendingTaskDescription { StartTime = SystemTime.UtcNow, TaskType = TaskActions.PendingTaskType.RestoreDatabase, Payload = "Restoring database " + databaseName + " from " + restoreRequest.BackupLocation }, out id); return(GetMessageWithObject(new { OperationId = id })); }
public DatabaseIndexName(string databaseName, string indexName, DatabasesLandlord landlord, int databaseIndex, int indexIndex) : base(databaseName, indexName, landlord, databaseIndex, indexIndex, SnmpOids.Databases.Indexes.Name) { _name = new OctetString(indexName); }
public DatabaseIndexExists(string databaseName, string indexName, DatabasesLandlord landlord, int databaseIndex, int indexIndex) : base(databaseName, indexName, landlord, databaseIndex, indexIndex, SnmpOids.Databases.Indexes.Exists) { }
public DatabaseDeletedCommandHandler(DocumentDatabase database, DatabasesLandlord landlord) : base(database, landlord) { }
public DatabaseIndexTimeSinceLastQuery(string databaseName, string indexName, DatabasesLandlord landlord, int databaseIndex, int indexIndex) : base(databaseName, indexName, landlord, databaseIndex, indexIndex, "11") { }
public AdminLogsWebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) : base(databasesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix) { }
public DatabaseRequestsCount(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, SnmpOids.Databases.RequestsCount, index) { }
public DatabaseIndexTimeSinceLastIndexing(string databaseName, string indexName, DatabasesLandlord landlord, int databaseIndex, int indexIndex) : base(databaseName, indexName, landlord, databaseIndex, indexIndex, SnmpOids.Databases.Indexes.TimeSinceLastIndexing) { }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) { throw new ArgumentNullException("configuration"); } try { ThreadPool.SetMinThreads(configuration.MinThreadPoolWorkerThreads, configuration.MinThreadPoolCompletionThreads); HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration, null, null, (sender, exception) => { if (log.IsInfoEnabled) { log.ErrorException( @"Found errors in the system database while loading it for the first time. This is recoverable error, since we will simply ingore transactions after the faulted one.", exception); } }); systemDatabase.SpinBackgroundWorkers(false); } else { systemDatabase = db; } WebSocketBufferPool.Initialize(configuration.WebSockets.InitialBufferPoolSize); fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); timeSeriesLandlord = new TimeSeriesLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); systemDatabase.RequestManager = requestManager; ClusterManager = new Reference <ClusterManager>(); systemDatabase.ClusterManager = ClusterManager; mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); serverStartupTasks = configuration.Container.GetExportedValues <IServerStartupTask>(); foreach (var task in serverStartupTasks) { toDispose.Add(task); try { task.Execute(this); } catch (Exception e) { systemDatabase.LogErrorAndAddAlertOnStartupTaskException(task.GetType().FullName, e); } } } catch (Exception e) { if (systemDatabase != null) { systemDatabase.Dispose(); } throw; } }
public WatchTrafficWebSocketsRequestParser(DatabasesLandlord databasesLandlord, TimeSeriesLandlord timeSeriesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) : base(databasesLandlord, timeSeriesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix) { }
private void OnProposingCandidacy(object sender, ProposingCandidacyResult e) { var clusterConfigurationsDoc = DatabasesLandlord.SystemDatabase.Documents.Get(Constants.Cluster.ClusterConfigurationDocumentKey, null); if (clusterConfigurationsDoc == null) { return; } var clusterConfigurations = clusterConfigurationsDoc.DataAsJson.JsonDeserialization <ClusterConfiguration>(); if (clusterConfigurations == null) { return; } if (clusterConfigurations.DisableReplicationStateChecks == true) { return; } var replicationStateDoc = DatabasesLandlord.SystemDatabase.Documents.Get(Constants.Cluster.ClusterReplicationStateDocumentKey, null); if (replicationStateDoc == null) { //This is a case of a node loading for the first time and just never got any replication state. //If we prevent this than a cluster will be non-respnosive when loaded (mostly a test senario but could be a real issue) if (clusterManagerStartTime + maxReplicationLatency + maxReplicationLatency < DateTime.UtcNow) { e.VetoCandidacy = true; e.Reason = "Could not find replication state document"; } return; } var replicationState = replicationStateDoc.DataAsJson.ToObject <ReplicationState>(); if (replicationState == null) { e.VetoCandidacy = true; e.Reason = "Could not deserialize replication state document"; return; } var anyDatabaseUptodate = false; //preventing the case where all databases are inactive (long overnight inactivity). var anyDatabaseUp = false; DatabasesLandlord.ForAllDatabases(database => { anyDatabaseUp = true; LastModificationTimeAndTransactionalId modification; //if the source document doesn't contain this databse it means it was not active in the source //nothing we can do but ignore this. if (replicationState.DatabasesToLastModification.TryGetValue(database.Name, out modification) == false) { return; } var docKey = $"{Constants.RavenReplicationSourcesBasePath}/{modification.DatabaseId}"; var doc = database.Documents.Get(docKey, null); if (doc == null) { return; } var sourceInformation = doc.DataAsJson.JsonDeserialization <SourceReplicationInformation>(); if (sourceInformation == null) { return; } var lastUpdate = sourceInformation.LastModifiedAtSource ?? DateTime.MaxValue; if (lastUpdate == DateTime.MaxValue || lastUpdate + maxReplicationLatency >= modification.LastModified) { anyDatabaseUptodate = true; } }, true); if (anyDatabaseUptodate == false && anyDatabaseUp) { e.VetoCandidacy = true; e.Reason = "None of the active databases are up to date with the leader last replication state"; } }
public DatabaseIndexMapsPerSec(string databaseName, string indexName, DatabasesLandlord landlord, int databaseIndex, int indexIndex) : base(databaseName, indexName, landlord, databaseIndex, indexIndex, SnmpOids.Databases.Indexes.MapsPerSec) { }
public DatabaseIndexPriority(string databaseName, string indexName, DatabasesLandlord landlord, int databaseIndex, int indexIndex) : base(databaseName, indexName, landlord, databaseIndex, indexIndex, SnmpOids.Databases.Indexes.Priority) { }
public DatabaseTotalStorageSize(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, "5.2.{0}.2.4", index) { }
public DatabaseNumberOfAutoIndexes(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, "5.2.{0}.5.3", index) { }
public DatabaseTransactionalStorageDiskRemainingSpace(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, "5.2.{0}.2.5", index) { }
public HttpResponseMessage Compact() { var db = InnerRequest.RequestUri.ParseQueryString()["database"]; if (string.IsNullOrWhiteSpace(db)) { return(GetMessageWithString("Compact request requires a valid database parameter", HttpStatusCode.BadRequest)); } var configuration = DatabasesLandlord.CreateTenantConfiguration(db); if (configuration == null) { return(GetMessageWithString("No database named: " + db, HttpStatusCode.NotFound)); } var task = Task.Factory.StartNew(() => { var compactStatus = new CompactStatus { State = CompactStatusState.Running, Messages = new List <string>() }; DatabasesLandlord.SystemDatabase.Documents.Delete(CompactStatus.RavenDatabaseCompactStatusDocumentKey(db), null, null); try { var targetDb = DatabasesLandlord.GetDatabaseInternal(db).ResultUnwrap(); DatabasesLandlord.Lock(db, () => targetDb.TransactionalStorage.Compact(configuration, msg => { compactStatus.Messages.Add(msg); DatabasesLandlord.SystemDatabase.Documents.Put(CompactStatus.RavenDatabaseCompactStatusDocumentKey(db), null, RavenJObject.FromObject(compactStatus), new RavenJObject(), null); })); compactStatus.State = CompactStatusState.Completed; compactStatus.Messages.Add("Database compaction completed."); DatabasesLandlord.SystemDatabase.Documents.Put(CompactStatus.RavenDatabaseCompactStatusDocumentKey(db), null, RavenJObject.FromObject(compactStatus), new RavenJObject(), null); } catch (Exception e) { compactStatus.Messages.Add("Unable to compact database " + e.Message); compactStatus.State = CompactStatusState.Faulted; DatabasesLandlord.SystemDatabase.Documents.Put(CompactStatus.RavenDatabaseCompactStatusDocumentKey(db), null, RavenJObject.FromObject(compactStatus), new RavenJObject(), null); throw; } return(GetEmptyMessage()); }); long id; Database.Tasks.AddTask(task, new TaskBasedOperationState(task), new TaskActions.PendingTaskDescription { StartTime = SystemTime.UtcNow, TaskType = TaskActions.PendingTaskType.CompactDatabase, Payload = "Compact database " + db, }, out id); return(GetMessageWithObject(new { OperationId = id })); }
public DatabaseReducedPerSecond(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, "5.2.{0}.3.3", index) { }
public DatabaseNumberOfStaticIndexes(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, SnmpOids.Databases.NumberOfStaticIndexes, index) { }
public DatabaseUpTime(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, SnmpOids.Databases.UpTime, index) { }
private void CleanupFileSystems(DatabasesLandlord databaseLandlord, FileSystemsLandlord fileSystemLandlord) { var systemDatabase = databaseLandlord.SystemDatabase; int nextStart = 0; var fileSystemDocuments = systemDatabase .Documents .GetDocumentsWithIdStartingWith(Constants.FileSystem.Prefix, null, null, 0, int.MaxValue, CancellationToken.None, ref nextStart); var fileSystemIds = fileSystemDocuments .Select(x => ((RavenJObject)x)["@metadata"]) .Where(x => x != null) .Select(x => x.Value <string>("@id")) .Where(x => x != null && x != Constants.SystemDatabase) .ToList(); foreach (var fileSystemId in fileSystemIds) { try { var key = fileSystemId; if (key.StartsWith(Constants.FileSystem.Prefix)) { key = key.Substring(Constants.FileSystem.Prefix.Length); } var shouldCleanup = false; DateTime value; if (fileSystemLandlord.IsFileSystemLoaded(key) == false) { shouldCleanup = true; } else if (fileSystemLandlord.LastRecentlyUsed.TryGetValue(key, out value) == false || (SystemTime.UtcNow - value) > maxTimeResourceCanBeIdle) { shouldCleanup = true; } if (shouldCleanup == false) { continue; } var configuration = fileSystemLandlord.CreateTenantConfiguration(key, true); fileSystemLandlord.Cleanup(key, maxTimeResourceCanBeIdle, database => false); var docKey = Constants.FileSystem.Prefix + key; systemDatabase.Documents.Delete(docKey, null, null); if (configuration == null) { continue; } IOExtensions.DeleteDirectory(configuration.FileSystem.DataDirectory); } catch (Exception e) { log.WarnException(string.Format("Failed to cleanup '{0}' filesystem.", fileSystemId), e); } } }
public DatabaseActiveBundles(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, "5.2.{0}.1.12", index) { }
public DatabaseCountOfUniqueAttachments(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, SnmpOids.Databases.CountOfUniqueAttachments, index) { }
public DatabaseMapIndexIndexedPerSecond(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, SnmpOids.Databases.MapIndexIndexesPerSecond, index) { }
public DatabaseStorageDiskRemainingSpace(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, SnmpOids.Databases.StorageDiskRemainingSpace, index) { }
public DatabaseCurrentNumberOfItemsToIndexInSingleBatch(string databaseName, DatabasesLandlord landlord, int index) : base(databaseName, landlord, "5.2.{0}.1.8", index) { }
public DatabaseIndexLastQueryTime(string databaseName, string indexName, DatabasesLandlord landlord, int databaseIndex, int indexIndex) : base(databaseName, indexName, landlord, databaseIndex, indexIndex, SnmpOids.Databases.Indexes.LastQueryTime) { }