Beispiel #1
1
		public TaskActions(RavenFileSystem fileSystem, ILog log)
			: base(fileSystem, log)
		{
			timer = Observable.Interval(TimeSpan.FromMinutes(1));

			InitializeTimer();
		}
Beispiel #2
0
 public BackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup,
                        FileSystemDocument filesystemDocument)
     : base(systemDatabase, filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, filesystemDocument)
 {
     instance         = ((TransactionalStorage)filesystem.Storage).Instance;
     backupConfigPath = Path.Combine(backupDestinationDirectory, "RavenDB.Backup");
 }
		protected void StartServerInstance(int port)
		{
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port);
			HttpSelfHostConfiguration config = null;
			Task.Factory.StartNew(() => // initialize in MTA thread
				                      {
					                      config = new HttpSelfHostConfiguration(ServerAddress(port))
						                               {
							                               MaxReceivedMessageSize = Int64.MaxValue,
							                               TransferMode = TransferMode.Streamed
						                               };

					                      var configuration = new InMemoryConfiguration();
					                      configuration.Initialize();
					                      configuration.DataDirectory = "~/" + port;
					                      configuration.Port = port;

					                      IOExtensions.DeleteDirectory(configuration.DataDirectory);

					                      var ravenFileSystem = new RavenFileSystem(configuration);
					                      ravenFileSystem.Start(config);
					                      disposables.Add(ravenFileSystem);
				                      })
			    .Wait();

			var server = new HttpSelfHostServer(config);
			server.OpenAsync().Wait();

			disposables.Add(server);
		}
Beispiel #4
0
        public TaskActions(RavenFileSystem fileSystem, ILog log)
            : base(fileSystem, log)
        {
            timer = Observable.Interval(TimeSpan.FromMinutes(1));

            InitializeTimer();
        }
 public static SynchronizingFileStream CreatingOrOpeningAndWriting(RavenFileSystem fileSystem, string fileName, RavenJObject metadata)
 {
     return(new SynchronizingFileStream(fileSystem, fileName, metadata, StorageStreamAccess.CreateAndWrite)
     {
         PreventUploadComplete = true
     });
 }
Beispiel #6
0
        protected BaseBackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup,
                                      FileSystemDocument filesystemDocument, ResourceBackupState state, CancellationToken token)
        {
            if (filesystem == null)
            {
                throw new ArgumentNullException("filesystem");
            }
            if (filesystemDocument == null)
            {
                throw new ArgumentNullException("filesystemDocument");
            }
            if (backupSourceDirectory == null)
            {
                throw new ArgumentNullException("backupSourceDirectory");
            }
            if (backupDestinationDirectory == null)
            {
                throw new ArgumentNullException("backupDestinationDirectory");
            }

            this.filesystem                 = filesystem;
            this.backupSourceDirectory      = backupSourceDirectory.ToFullPath();
            this.backupDestinationDirectory = backupDestinationDirectory.ToFullPath();
            this.incrementalBackup          = incrementalBackup;
            this.filesystemDocument         = filesystemDocument;
            this.state = state;
            this.token = token;
        }
Beispiel #7
0
 public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup,
                        FileSystemDocument filesystemDocument, ResourceBackupState state, CancellationToken token)
     : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, filesystemDocument, state, token)
 {
     instance         = ((TransactionalStorage)filesystem.Storage).Instance;
     backupConfigPath = Path.Combine(backupDestinationDirectory, "RavenDB.Backup");
 }
        public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup,
	                           FileSystemDocument filesystemDocument)
            : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, filesystemDocument)
        {
            instance = ((TransactionalStorage)filesystem.Storage).Instance;
            backupConfigPath = Path.Combine(backupDestinationDirectory, "RavenDB.Backup");
	    }
		public WebApiTest()
		{
			IOExtensions.DeleteDirectory("Test");
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(19079);
			Task.Factory.StartNew(() => // initialize in MTA thread
				                      {
					                      config = new HttpSelfHostConfiguration(Url)
						                               {
							                               MaxReceivedMessageSize = Int64.MaxValue,
							                               TransferMode = TransferMode.Streamed
						                               };
					                      var configuration = new InMemoryConfiguration();
					                      configuration.Initialize();
					                      configuration.DataDirectory = "~/Test";
					                      ravenFileSystem = new RavenFileSystem(configuration);
					                      ravenFileSystem.Start(config);
				                      })
			    .Wait();

			server = new HttpSelfHostServer(config);
			server.OpenAsync().Wait();

			WebClient = new WebClient
				            {
					            BaseAddress = Url
				            };
		}
        protected BaseBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument filesystemDocument)
        {
            if (filesystem == null)
            {
                throw new ArgumentNullException("filesystem");
            }
            if (filesystemDocument == null)
            {
                throw new ArgumentNullException("filesystemDocument");
            }
            if (systemDatabase == null)
            {
                throw new ArgumentNullException("systemDatabase");
            }
            if (backupSourceDirectory == null)
            {
                throw new ArgumentNullException("backupSourceDirectory");
            }
            if (backupDestinationDirectory == null)
            {
                throw new ArgumentNullException("backupDestinationDirectory");
            }

            this.systemDatabase             = systemDatabase;
            this.filesystem                 = filesystem;
            this.backupSourceDirectory      = backupSourceDirectory.ToFullPath();
            this.backupDestinationDirectory = backupDestinationDirectory.ToFullPath();
            this.incrementalBackup          = incrementalBackup;
            this.filesystemDocument         = filesystemDocument;
        }
 public SynchronizationTopologyDiscoverer(RavenFileSystem filesystem, RavenJArray @from, int ttl, ILog log)
 {
     this.filesystem = filesystem;
     this.ttl        = ttl;
     this.log        = log;
     this.@from      = @from;
     requestFactory  = new HttpRavenRequestFactory();
 }
		public SynchronizationStorageTests()
		{
			source = NewClient(0);
			destination = NewClient(1);

			sourceRfs = GetRavenFileSystem(0);
			destinationRfs = GetRavenFileSystem(1);
		}
        public SynchronizationStorageTests()
        {
            source      = (IAsyncFilesCommandsImpl)NewAsyncClient(0);
            destination = (IAsyncFilesCommandsImpl)NewAsyncClient(1);

            sourceRfs      = GetRavenFileSystem(0);
            destinationRfs = GetRavenFileSystem(1);
        }
Beispiel #14
0
        public static bool IsVersioningActive(this RavenFileSystem fileSystem)
        {
            var exists = false;

            fileSystem.Storage.Batch(accessor => exists = accessor.IsVersioningActive());

            return(exists);
        }
        public SynchronizationStorageTests()
        {
            source      = NewClient(0);
            destination = NewClient(1);

            sourceRfs      = GetRavenFileSystem(0);
            destinationRfs = GetRavenFileSystem(1);
        }
Beispiel #16
0
        public static bool TryToCreateTransactionalStorage(InMemoryRavenConfiguration ravenConfiguration,
                                                           bool hasCompression, EncryptionConfiguration encryption, bool isRavenFs,
                                                           out ITransactionalStorage storage, out Database.FileSystem.Storage.ITransactionalStorage fileStorage)
        {
            storage     = null;
            fileStorage = null;
            if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, Voron.Impl.Constants.DatabaseFilename)))
            {
                if (isRavenFs)
                {
                    fileStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration);
                }
                else
                {
                    storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.VoronTypeName, () => { }, () => { });
                }
            }
            else if (File.Exists(Path.Combine(ravenConfiguration.DataDirectory, "Data.jfm")))
            {
                if (isRavenFs)
                {
                    fileStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration);
                }
                else
                {
                    storage = ravenConfiguration.CreateTransactionalStorage(InMemoryRavenConfiguration.EsentTypeName, () => { }, () => { });
                }
            }
            if (storage == null && fileStorage == null)
            {
                return(false);
            }
            if (isRavenFs)
            {
                var filesOrderedPartCollection = new OrderedPartCollection <Database.FileSystem.Plugins.AbstractFileCodec>();
                fileStorage.Initialize(new UuidGenerator(), filesOrderedPartCollection);
                return(true);
            }
            var orderedPartCollection = new OrderedPartCollection <AbstractDocumentCodec>();

            if (encryption != null)
            {
                var documentEncryption = new DocumentEncryption();
                documentEncryption.SetSettings(new EncryptionSettings(encryption.EncryptionKey, encryption.SymmetricAlgorithmType,
                                                                      encryption.EncryptIndexes, encryption.PreferedEncryptionKeyBitsSize));
                orderedPartCollection.Add(documentEncryption);
            }
            if (hasCompression)
            {
                orderedPartCollection.Add(new DocumentCompression());
            }
            storage.Initialize(new SequentialUuidGenerator {
                EtagBase = 0
            }, orderedPartCollection);

            return(true);
        }
Beispiel #17
0
        public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory,
                               string backupDestinationDirectory, StorageEnvironment env, bool incrementalBackup,
                               FileSystemDocument fileSystemDocument)
            : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, fileSystemDocument)
        {
            if (env == null) throw new ArgumentNullException("env");

            this.env = env;
        }
 public SynchronizationBehavior(string fileName, Etag sourceFileEtag, RavenJObject sourceMetadata, FileSystemInfo sourceFs, SynchronizationType type, RavenFileSystem fs)
 {
     this.fileName = fileName;
     this.sourceFileEtag = sourceFileEtag;
     this.sourceMetadata = sourceMetadata;
     this.sourceFs = sourceFs;
     this.type = type;
     this.fs = fs;
 }
Beispiel #19
0
 public SynchronizationBehavior(string fileName, Etag sourceFileEtag, RavenJObject sourceMetadata, FileSystemInfo sourceFs, SynchronizationType type, RavenFileSystem fs)
 {
     this.fileName       = fileName;
     this.sourceFileEtag = sourceFileEtag;
     this.sourceMetadata = sourceMetadata;
     this.sourceFs       = sourceFs;
     this.type           = type;
     this.fs             = fs;
 }
Beispiel #20
0
        public void StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument fileSystemDocument)
        {
            if (new InstanceParameters(instance).Recovery == false)
            {
                throw new InvalidOperationException("Cannot start backup operation since the recovery option is disabled. In order to enable the recovery please set the RunInUnreliableYetFastModeThatIsNotSuitableForProduction configuration parameter value to false.");
            }

            var backupOperation = new BackupOperation(filesystem, systemDatabase.Configuration.DataDirectory, backupDestinationDirectory, incrementalBackup, fileSystemDocument);

            Task.Factory.StartNew(backupOperation.Execute);
        }
Beispiel #21
0
        public SynchronizationStorageTests()
        {
            configuration = new InMemoryRavenConfiguration();
            configuration.Initialize();

            source      = (IAsyncFilesCommandsImpl)NewAsyncClient(0);
            destination = (IAsyncFilesCommandsImpl)NewAsyncClient(1);

            sourceRfs      = GetFileSystem(0);
            destinationRfs = GetFileSystem(1);
        }
Beispiel #22
0
        public BackupOperation(RavenFileSystem filesystem, string backupSourceDirectory,
                               string backupDestinationDirectory, StorageEnvironment env, bool incrementalBackup,
                               FileSystemDocument fileSystemDocument)
            : base(filesystem, backupSourceDirectory, backupDestinationDirectory, incrementalBackup, fileSystemDocument)
        {
            if (env == null)
            {
                throw new ArgumentNullException("env");
            }

            this.env = env;
        }
		protected void Application_Start(object sender, EventArgs e)
		{
			HttpEndpointRegistration.RegisterHttpEndpointTarget();
			ConfigureLogging();

			ravenFileSystem = new RavenFileSystem(new RavenFileSystemConfiguration());

			ravenFileSystem.Start(GlobalConfiguration.Configuration);

            // turn this on so we don't a conflict between the /search endpoint handled by the SearchController
            // and the Search folder.
		    RouteTable.Routes.RouteExistingFiles = true;
		}
        protected BaseBackupOperation(RavenFileSystem filesystem, string backupSourceDirectory, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument filesystemDocument)
        {
            if (filesystem == null) throw new ArgumentNullException("filesystem");
            if (filesystemDocument == null) throw new ArgumentNullException("filesystemDocument");
            if (backupSourceDirectory == null) throw new ArgumentNullException("backupSourceDirectory");
            if (backupDestinationDirectory == null) throw new ArgumentNullException("backupDestinationDirectory");

            this.filesystem = filesystem;
            this.backupSourceDirectory = backupSourceDirectory.ToFullPath();
            this.backupDestinationDirectory = backupDestinationDirectory.ToFullPath();
            this.incrementalBackup = incrementalBackup;
            this.filesystemDocument = filesystemDocument;
        }
		public void Start()
		{
			ravenFileSystem = new RavenFileSystem(Configuration);
			config = new HttpSelfHostConfiguration(Configuration.ServerUrl)
			{
				MaxReceivedMessageSize = Int64.MaxValue,
				TransferMode = TransferMode.Streamed,
				ReceiveTimeout = TimeSpan.MaxValue,
				SendTimeout = TimeSpan.MaxValue,
			};
			ravenFileSystem.Start(config);
			server = new HttpSelfHostServer(config);
			server.OpenAsync().Wait();
		}
Beispiel #26
0
        public static bool ChangesToRevisionsAllowed(this RavenFileSystem fileSystem)
        {
            var changesToRevisionsAllowed = fileSystem.Configuration.Settings[Constants.FileSystem.Versioning.ChangesToRevisionsAllowed];

            if (changesToRevisionsAllowed == null)
            {
                return(false);
            }
            bool result;

            if (bool.TryParse(changesToRevisionsAllowed, out result) == false)
            {
                return(false);
            }
            return(result);
        }
Beispiel #27
0
        public void StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup,
                                         FileSystemDocument fileSystemDocument)
        {
            if (tableStorage == null)
            {
                throw new InvalidOperationException("Cannot begin database backup - table store is not initialized");
            }

            var backupOperation = new BackupOperation(filesystem, systemDatabase.Configuration.DataDirectory,
                                                      backupDestinationDirectory, tableStorage.Environment, incrementalBackup, fileSystemDocument);

            Task.Factory.StartNew(() =>
            {
                using (backupOperation)
                    backupOperation.Execute();
            });
        }
Beispiel #28
0
        protected StorageStream(RavenFileSystem fileSystem, ITransactionalStorage storage, string fileName, RavenJObject metadata, StorageStreamAccess storageStreamAccess)
        {
            this.fileSystem = fileSystem;
            this.storage    = storage;

            StorageStreamAccess = storageStreamAccess;
            Name = fileName;

            switch (storageStreamAccess)
            {
            case StorageStreamAccess.Read:
                storage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
                if (fileHeader.TotalSize == null)
                {
                    throw new FileNotFoundException("File is not uploaded yet");
                }
                Metadata = fileHeader.Metadata;
                Seek(0, SeekOrigin.Begin);
                break;

            case StorageStreamAccess.CreateAndWrite:

                if (this.fileSystem == null)
                {
                    throw new ArgumentNullException("fileSystem");
                }

                storage.Batch(accessor =>
                {
                    using (fileSystem.DisableAllTriggersForCurrentThread())
                    {
                        fileSystem.Files.IndicateFileToDelete(fileName, null);
                    }

                    var putResult = accessor.PutFile(fileName, null, metadata);
                    fileSystem.Search.Index(fileName, metadata, putResult.Etag);
                });
                Metadata = metadata;
                break;

            default:
                throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
            }
        }
        /// <summary>
        /// Uses an encrypted document to verify that the encryption key is correct and decodes it to the right value.
        /// </summary>
        public static void VerifyEncryptionKey(RavenFileSystem fileSystem, EncryptionSettings settings)
        {
            RavenJObject config = null;

            try
            {
                fileSystem.Storage.Batch(accessor =>
                {
                    try
                    {
                        config = accessor.GetConfig(Constants.InResourceKeyVerificationDocumentName);
                    }
                    catch (FileNotFoundException)
                    {
                    }
                });
            }
            catch (CryptographicException e)
            {
                throw new ConfigurationErrorsException("The file system is encrypted with a different key and/or algorithm than the ones "
                                                       + "currently in the configuration file.", e);
            }

            if (config != null)
            {
                var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer();
                if (!ravenJTokenEqualityComparer.Equals(config, Constants.InResourceKeyVerificationDocumentContents))
                {
                    throw new ConfigurationErrorsException("The file system is encrypted with a different key and/or algorithm than the ones is currently configured");
                }
            }
            else
            {
                // This is the first time the file system is loaded.
                if (EncryptedFileExist(fileSystem))
                {
                    throw new InvalidOperationException("The file system already has existing files, you cannot start using encryption now.");
                }

                var clonedDoc = (RavenJObject)Constants.InResourceKeyVerificationDocumentContents.CreateSnapshot();
                fileSystem.Storage.Batch(accessor => accessor.SetConfig(Constants.InResourceKeyVerificationDocumentName, clonedDoc));
            }
        }
Beispiel #30
0
        public Task StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup,
                                         FileSystemDocument fileSystemDocument, ResourceBackupState state, CancellationToken token)
        {
            if (tableStorage == null)
            {
                throw new InvalidOperationException("Cannot begin database backup - table store is not initialized");
            }

            var backupOperation = new BackupOperation(filesystem, systemDatabase.Configuration.DataDirectory,
                                                      backupDestinationDirectory, tableStorage.Environment, incrementalBackup, fileSystemDocument, state, token);

            return(Task.Factory.StartNew(() =>
            {
                using (backupOperation)
                {
                    backupOperation.Execute();
                }
            }));
        }
Beispiel #31
0
        public void Initialize(RavenFileSystem filesystem)
        {
            try
            {
                this.filesystem = filesystem;
                indexDirectory  = configuration.FileSystem.IndexStoragePath;

                // Skip crash markers setup when running in memory.
                if (configuration.RunInMemory == false)
                {
                    var filesystemDirectory = configuration.FileSystem.DataDirectory;
                    if (!Directory.Exists(filesystemDirectory))
                    {
                        Directory.CreateDirectory(filesystemDirectory);
                    }

                    var crashMarkerPath = Path.Combine(filesystemDirectory, "indexing.crash-marker");

                    if (File.Exists(crashMarkerPath))
                    {
                        // the only way this can happen is if we crashed because of a power outage
                        // in this case, we consider open indexes to be corrupt and force them
                        // to be reset. This is because to get better perf, we don't flush the files to disk,
                        // so in the case of a power outage, we can't be sure that there wasn't still stuff in
                        // the OS buffer that wasn't written yet.

                        resetIndexOnUncleanShutdown = true;
                    }

                    // The delete on close ensures that the only way this file will exists is if there was
                    // a power outage while the server was running.
                    crashMarker = File.Create(crashMarkerPath, 16, FileOptions.DeleteOnClose);
                }

                OpenIndexOnStartup();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Beispiel #32
0
        public HttpResponseMessage Get()
        {
            var count = 0;

            Storage.Batch(accessor =>
            {
                count = accessor.GetFileCount();
            });

            var stats = new FileSystemStats
            {
                Name         = FileSystemName,
                FileCount    = count,
                Metrics      = RavenFileSystem.CreateMetrics(),
                ActiveSyncs  = RavenFileSystem.SynchronizationTask.Queue.Active.ToList(),
                PendingSyncs = RavenFileSystem.SynchronizationTask.Queue.Pending.ToList()
            };

            return(this.GetMessageWithObject(stats).WithNoCache());
        }
Beispiel #33
0
        protected StorageStream(RavenFileSystem fileSystem, ITransactionalStorage storage, string fileName, RavenJObject metadata, StorageStreamAccess storageStreamAccess)
        {
            this.fileSystem = fileSystem;
            this.storage = storage;

            StorageStreamAccess = storageStreamAccess;
            Name = fileName;

            switch (storageStreamAccess)
            {
                case StorageStreamAccess.Read:
                    storage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
                    if (fileHeader.TotalSize == null)
                    {
                        throw new FileNotFoundException("File is not uploaded yet");
                    }
                    Metadata = fileHeader.Metadata;
                    Seek(0, SeekOrigin.Begin);
                    break;
                case StorageStreamAccess.CreateAndWrite:

                    if (this.fileSystem == null)
                        throw new ArgumentNullException("fileSystem");

                    storage.Batch(accessor =>
                    {
                        using (fileSystem.DisableAllTriggersForCurrentThread())
                        {
                            fileSystem.Files.IndicateFileToDelete(fileName, null);
                        }

                        var putResult = accessor.PutFile(fileName, null, metadata);
                        fileSystem.Search.Index(fileName, metadata, putResult.Etag);
                    });
                    Metadata = metadata;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
            }
        }
Beispiel #34
0
        public void Initialize(RavenFileSystem filesystem)
        {
            try
            {
                this.filesystem = filesystem;                                
                indexDirectory = configuration.FileSystem.IndexStoragePath;         
       
                // Skip crash markers setup when running in memory.
                if ( configuration.RunInMemory == false )
                {
                    var filesystemDirectory = configuration.FileSystem.DataDirectory;
                    if (!Directory.Exists(filesystemDirectory))
                        Directory.CreateDirectory(filesystemDirectory);

                    var crashMarkerPath = Path.Combine(filesystemDirectory, "indexing.crash-marker");

                    if (File.Exists(crashMarkerPath))
                    {
                        // the only way this can happen is if we crashed because of a power outage
                        // in this case, we consider open indexes to be corrupt and force them
                        // to be reset. This is because to get better perf, we don't flush the files to disk,
                        // so in the case of a power outage, we can't be sure that there wasn't still stuff in
                        // the OS buffer that wasn't written yet.

                        resetIndexOnUncleanShutdown = true;
                    }

                    // The delete on close ensures that the only way this file will exists is if there was
                    // a power outage while the server was running.
                    crashMarker = File.Create(crashMarkerPath, 16, FileOptions.DeleteOnClose);
                }
                                
                OpenIndexOnStartup();
            }
            catch
            {
                Dispose();
                throw;
            }           
        }
        private static bool EncryptedFileExist(RavenFileSystem fileSystem)
        {
            const int pageSize = 10;
            var       start    = Guid.Empty;

            bool foundEncryptedDoc = false;

            while (true)
            {
                var foundMoreDocs = false;

                fileSystem.Storage.Batch(accessor =>
                {
                    var fileHeaders = accessor.GetFilesAfter(start, pageSize);

                    foreach (var fileHeader in fileHeaders)
                    {
                        foundMoreDocs = true;

                        if (EncryptionSettings.DontEncrypt(fileHeader.Name) == false)
                        {
                            foundEncryptedDoc = true;
                            break;
                        }

                        start = fileHeader.Etag;
                    }
                });

                if (foundEncryptedDoc || foundMoreDocs == false)
                {
                    break;
                }
            }

            return(foundEncryptedDoc);
        }
Beispiel #36
0
		public virtual void Initialize(RavenFileSystem fileSystem)
		{
			FileSystem = fileSystem;
			Initialize();
		}
Beispiel #37
0
        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 <FilesystemRestoreRequest>();

            var fileSystemDocumentPath = FindFilesystemDocument(restoreRequest.BackupLocation);

            if (!File.Exists(fileSystemDocumentPath))
            {
                throw new InvalidOperationException("Cannot restore when the Filesystem.Document file is missing in the backup folder: " + restoreRequest.BackupLocation);
            }

            var filesystemDocumentText = File.ReadAllText(fileSystemDocumentPath);
            var filesystemDocument     = RavenJObject.Parse(filesystemDocumentText).JsonDeserialization <FileSystemDocument>();

            var filesystemName = !string.IsNullOrWhiteSpace(restoreRequest.FilesystemName) ? restoreRequest.FilesystemName
                                   : filesystemDocument == null ? null : filesystemDocument.Id;

            if (string.IsNullOrWhiteSpace(filesystemName))
            {
                var errorMessage = (filesystemDocument == null || String.IsNullOrWhiteSpace(filesystemDocument.Id))
                                ? Constants.FilesystemDocumentFilename + " file is invalid - filesystem 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 filesystem name must be supplied if the restore location does not contain a valid " + Constants.FilesystemDocumentFilename + " file";

                restoreStatus.Messages.Add(errorMessage);
                DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null, RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);

                return(GetMessageWithString(errorMessage, HttpStatusCode.BadRequest));
            }

            var ravenConfiguration = new RavenConfiguration
            {
                FileSystemName = filesystemName,
            };

            if (filesystemDocument != null)
            {
                foreach (var setting in filesystemDocument.Settings)
                {
                    ravenConfiguration.Settings[setting.Key] = setting.Value;
                }
            }

            if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
            {
                ravenConfiguration.FileSystem.DefaultStorageTypeName = InMemoryRavenConfiguration.EsentTypeName;
            }
            else
            {
                ravenConfiguration.FileSystem.DefaultStorageTypeName = InMemoryRavenConfiguration.VoronTypeName;
            }

            ravenConfiguration.CustomizeValuesForFileSystemTenant(filesystemName);
            ravenConfiguration.Initialize();

            string documentDataDir;

            ravenConfiguration.FileSystem.DataDirectory = ResolveTenantDataDirectory(restoreRequest.FilesystemLocation, filesystemName, out documentDataDir);
            restoreRequest.FilesystemLocation           = ravenConfiguration.FileSystem.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 = filesystemName
            }), new RavenJObject(), null);

            DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null, null);

            bool defrag;

            if (bool.TryParse(GetQueryStringValue("defrag"), out defrag))
            {
                restoreRequest.Defrag = defrag;
            }

            var task = Task.Factory.StartNew(() =>
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(restoreRequest.FilesystemLocation))
                    {
                        ravenConfiguration.FileSystem.DataDirectory = restoreRequest.FilesystemLocation;
                    }

                    using (var transactionalStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration))
                    {
                        transactionalStorage.Restore(restoreRequest, msg =>
                        {
                            restoreStatus.Messages.Add(msg);
                            DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null,
                                                                           RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
                        });
                    }

                    if (filesystemDocument == null)
                    {
                        return;
                    }

                    filesystemDocument.Settings[Constants.FileSystem.DataDirectory] = documentDataDir;

                    if (restoreRequest.IndexesLocation != null)
                    {
                        filesystemDocument.Settings[Constants.RavenIndexPath] = restoreRequest.IndexesLocation;
                    }
                    if (restoreRequest.JournalsLocation != null)
                    {
                        filesystemDocument.Settings[Constants.RavenTxJournalPath] = restoreRequest.JournalsLocation;
                    }
                    filesystemDocument.Id = filesystemName;

                    FileSystemsLandlord.Protect(filesystemDocument);

                    DatabasesLandlord.SystemDatabase.Documents.Put(Constants.FileSystem.Prefix + filesystemName, null, RavenJObject.FromObject(filesystemDocument), new RavenJObject(), null);

                    restoreStatus.State = RestoreStatusState.Completed;
                    restoreStatus.Messages.Add("The new filesystem was created");
                    DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null, RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
                }
                catch (Exception e)
                {
                    restoreStatus.State = RestoreStatusState.Faulted;
                    restoreStatus.Messages.Add("Unable to restore filesystem " + e.Message);
                    DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), 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.RestoreFilesystem,
                Payload   = "Restoring filesystem " + filesystemName + " from " + restoreRequest.BackupLocation
            }, out id);

            return(GetMessageWithObject(new
            {
                OperationId = id
            }));
        }
Beispiel #38
0
        public void StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup, FileSystemDocument fileSystemDocument)
        {
            if (new InstanceParameters(instance).Recovery == false)
                throw new InvalidOperationException("Cannot start backup operation since the recovery option is disabled. In order to enable the recovery please set the RunInUnreliableYetFastModeThatIsNotSuitableForProduction configuration parameter value to false.");

            var backupOperation = new BackupOperation(filesystem, systemDatabase.Configuration.DataDirectory, backupDestinationDirectory, incrementalBackup, fileSystemDocument);
            Task.Factory.StartNew(backupOperation.Execute);
        }
Beispiel #39
0
 public FileActions(RavenFileSystem fileSystem, ILog log)
     : base(fileSystem, log)
 {
     InitializeTimer();
 }
Beispiel #40
0
		public FilesystemDataDumper(RavenFileSystem fileSystem, SmugglerFilesOptions options = null) : base(options ?? new SmugglerFilesOptions())
		{
			Operations = new SmugglerEmbeddedFilesOperations(fileSystem);
		}
 private SynchronizingFileStream(RavenFileSystem fileSystem, string fileName,
                                 RavenJObject metadata, StorageStreamAccess storageStreamAccess)
     : base(fileSystem, fileSystem.Storage, fileName, metadata, storageStreamAccess)
 {
     md5Hasher = Encryptor.Current.CreateHash();
 }
 public SmugglerEmbeddedFilesOperations(RavenFileSystem filesystem)
 {
     this.filesystem = filesystem;
 }
Beispiel #43
0
 protected ActionsBase(RavenFileSystem fileSystem, ILog log)
 {
     FileSystem = fileSystem;
     Log = log;
 }
		private SynchronizingFileStream(RavenFileSystem fileSystem, string fileName,
										RavenJObject metadata, StorageStreamAccess storageStreamAccess)
			: base(fileSystem, fileSystem.Storage, fileName, metadata, storageStreamAccess)
		{
		    md5Hasher = Encryptor.Current.CreateHash();
		}
Beispiel #45
0
 public static StorageStream CreatingNewAndWritting(RavenFileSystem fileSystem, string fileName, RavenJObject metadata)
 {
     return new StorageStream(fileSystem, fileSystem.Storage, fileName, metadata, StorageStreamAccess.CreateAndWrite);
 }
		public static SynchronizingFileStream CreatingOrOpeningAndWriting(RavenFileSystem fileSystem, string fileName, RavenJObject metadata)
		{
			return new SynchronizingFileStream(fileSystem, fileName, metadata, StorageStreamAccess.CreateAndWrite) { PreventUploadComplete = true };
		}
 public virtual void Initialize(RavenFileSystem fileSystem)
 {
     FileSystem = fileSystem;
     Initialize();
 }
 public VersioningTriggerActions(RavenFileSystem fileSystem)
 {
     this.fileSystem = fileSystem;
 }
Beispiel #49
0
 public static StorageStream CreatingNewAndWritting(RavenFileSystem fileSystem, string fileName, RavenJObject metadata)
 {
     return(new StorageStream(fileSystem, fileSystem.Storage, fileName, metadata, StorageStreamAccess.CreateAndWrite));
 }
Beispiel #50
0
 public FileActions(RavenFileSystem fileSystem, ILog log)
     : base(fileSystem, log)
 {
     InitializeTimer();
 }
Beispiel #51
0
 public StorageStreamTest()
 {
     NewAsyncClient();
     fs = GetFileSystem();
     transactionalStorage = fs.Storage;
 }
        public void StartBackupOperation(DocumentDatabase systemDatabase, RavenFileSystem filesystem, string backupDestinationDirectory, bool incrementalBackup,
            FileSystemDocument fileSystemDocument)
        {
            if (tableStorage == null)
                throw new InvalidOperationException("Cannot begin database backup - table store is not initialized");

            var backupOperation = new BackupOperation(filesystem, systemDatabase.Configuration.DataDirectory,
                backupDestinationDirectory, tableStorage.Environment, incrementalBackup, fileSystemDocument);

            Task.Factory.StartNew(() =>
            {
                using (backupOperation)
                    backupOperation.Execute();
            });
        }
 public SynchronizationActions(RavenFileSystem fileSystem, ILog log)
     : base(fileSystem, log)
 {
 }
		public SynchronizationActions(RavenFileSystem fileSystem, ILog log)
			: base(fileSystem, log)
		{
		}