public void TestCreateAppendOnlyPageStore() { if (PersistenceManager.FileExists(PageFilePath)) { PersistenceManager.DeleteFile(PageFilePath); } using (var readwritePageStore = new AppendOnlyFilePageStore(PersistenceManager, PageFilePath, 8192, false, false)) { Assert.AreEqual(8192, readwritePageStore.PageSize); Assert.IsTrue(readwritePageStore.CanRead); Assert.IsTrue(readwritePageStore.CanWrite); using (var readonlyPageStore = new AppendOnlyFilePageStore(PersistenceManager, PageFilePath, 8192, true, false)) { Assert.AreEqual(8192, readonlyPageStore.PageSize); Assert.IsTrue(readonlyPageStore.CanRead); Assert.IsFalse(readonlyPageStore.CanWrite); } } Assert.IsTrue(PersistenceManager.FileExists(PageFilePath)); Assert.AreEqual(0, PersistenceManager.GetFileLength(PageFilePath)); }
private void CopyTestDataToImportFolder(string testDataFileName, string targetFileName = null) { #if PORTABLE using (var srcStream = _persistenceManager.GetInputStream(Configuration.DataLocation + testDataFileName)) { var targetDir = Path.Combine(Configuration.StoreLocation, "import"); var targetPath = Path.Combine(targetDir, (targetFileName ?? testDataFileName)); if (!_persistenceManager.DirectoryExists(targetDir)) { _persistenceManager.CreateDirectory(targetDir); } if (_persistenceManager.FileExists(targetPath)) { _persistenceManager.DeleteFile(targetPath); } using (var targetStream = _persistenceManager.GetOutputStream(targetPath, FileMode.CreateNew)) { srcStream.CopyTo(targetStream); } } #else var importFile = new FileInfo(Path.Combine(Configuration.DataLocation, testDataFileName)); var targetDir = new DirectoryInfo(Path.Combine(Configuration.StoreLocation, "import")); if (!targetDir.Exists) { targetDir.Create(); } importFile.CopyTo(Path.Combine(targetDir.FullName, targetFileName ?? testDataFileName), true); #endif }
public void TestCreateFile() { if (_pm.FileExists("test.txt")) { _pm.DeleteFile("test.txt"); } _pm.CreateFile("test.txt"); Assert.IsTrue(_pm.FileExists("test.txt")); }
public ulong AppendCommitPoint(CommitPoint newCommitPoint, bool overwrite = false) { if (overwrite) { Logging.LogDebug("AppendCommitPoint: Overwrite requested. Deleting existing master file at '{0}'", _masterFilePath); _persistenceManager.DeleteFile(_masterFilePath); _commitPoints.Clear(); } if (!_persistenceManager.FileExists(_masterFilePath)) { Logging.LogDebug("AppendCommitPoint: Master file not found at '{0}'. Creating new master file.", _masterFilePath); using (var stream = _persistenceManager.GetOutputStream(_masterFilePath, FileMode.Create)) { Save(stream); } } using (var stream = _persistenceManager.GetOutputStream(_masterFilePath, FileMode.Open)) { stream.Seek(0, SeekOrigin.End); newCommitPoint.Save(stream); _commitPoints.TryAdd(stream.Length - CommitPoint.RecordSize, newCommitPoint); return(newCommitPoint.CommitNumber); } }
public void TestCreateAndDeleteFile() { string fname = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "CreateFile_" + DateTime.Now.Ticks); Assert.False(_pm.FileExists(fname), "File exists before creation"); _pm.CreateFile(fname); Assert.True(_pm.FileExists(fname), "File does not exist after creation"); Assert.False(_pm.DirectoryExists(fname), "File found by DirectoryExists"); _pm.DeleteFile(fname); Assert.False(_pm.FileExists(fname), "File exists after deletion"); }
public void TestCreateAndDeleteFile() { string fname = Path.Combine(TestConfiguration.StoreLocation, "CreateFile_" + DateTime.Now.Ticks); Assert.False(_pm.FileExists(fname), "File exists before creation"); _pm.CreateFile(fname); Assert.True(_pm.FileExists(fname), "File does not exist after creation"); Assert.False(_pm.DirectoryExists(fname), "File found by DirectoryExists"); _pm.DeleteFile(fname); Assert.False(_pm.FileExists(fname), "File exists after deletion"); }
public IPageStore CreateConsolidationStore(string storeLocation) { var masterFile = GetMasterFile(storeLocation); var storePath = Path.Combine(storeLocation, ConsolidateFileName); if (_persistenceManager.FileExists(storePath)) { _persistenceManager.DeleteFile(storePath); } _persistenceManager.CreateFile(storePath); switch (masterFile.PersistenceType) { case PersistenceType.AppendOnly: return(new AppendOnlyFilePageStore(_persistenceManager, storePath, PageSize, false, _storeConfiguration.DisableBackgroundWrites)); case PersistenceType.Rewrite: return(new BinaryFilePageStore(_persistenceManager, storePath, PageSize, false, 0, 1, _storeConfiguration.DisableBackgroundWrites)); default: throw new NotImplementedException(String.Format("No support for creating consolidated store with persistence type {0}", _storeConfiguration.PersistenceType)); } }
public static IPageStore CreateEmptyPageStore(string fileName, PersistenceType persistenceType = PersistenceType.AppendOnly, BrightstarProfiler profiler = null) { using (profiler.Step("Create Empty Page Store")) { using (profiler.Step("Delete Existing")) { if (PersistenceManager.FileExists(fileName)) { PersistenceManager.DeleteFile(fileName); } //if (File.Exists(fileName)) File.Delete(fileName); } using (profiler.Step("Create New Page Store")) { if (persistenceType == PersistenceType.AppendOnly) { return(new AppendOnlyFilePageStore(PersistenceManager, fileName, 4096, false, false)); } return(new BinaryFilePageStore(PersistenceManager, fileName, 4096, false, 1)); } } }
public void ConsolidateStore(Store store, string storeLocation, Guid jobId) { // delete consolidate file if for some reason it was still there if (_persistenceManager.FileExists(store.StoreConsolidateFile)) { _persistenceManager.DeleteFile(store.StoreConsolidateFile); } // var inputStream = _persistenceManager.GetInputStream(store.StoreDataFile); var inputStream = store.InputDataStream; var outputStream = _persistenceManager.GetOutputStream(store.StoreConsolidateFile, FileMode.CreateNew); ulong offset = 0; try { using (var writer = new BinaryWriter(outputStream)) { var objectLocationManager = store.ObjectLocationManager; foreach (var container in objectLocationManager.Containers) { foreach (var objLoc in container.ObjectOffsets) { // load object var objType = GetObjectType(objLoc.Type); if (objType.Equals(typeof(Store))) { // dont write the store. continue; } var obj = ReadObject(inputStream, objLoc.Offset, GetObjectType(objLoc.Type)); // save object and update location manager var bytes = obj.Save(writer, offset); // manage offsets objectLocationManager.SetObjectOffset(obj.ObjectId, offset, PersistantTypeIdentifiers[obj.GetType()], 1); offset += (ulong)bytes; } } // write the store objectLocationManager.SetObjectOffset(store.ObjectId, offset, PersistantTypeIdentifiers[store.GetType()], 1); store.Save(writer, offset); // delete store inputStream.Close(); inputStream.Dispose(); _persistenceManager.DeleteFile(store.StoreDataFile); } // rename to new _persistenceManager.RenameFile(store.StoreConsolidateFile, store.StoreDataFile); // update the masterfile AppendCommitPoint(storeLocation, new CommitPoint(offset, 0ul, DateTime.UtcNow, jobId), true); } catch (Exception ex) { Logging.LogError(new BrightstarEventId(), "Unable to consolidate store. Error was " + ex.Message); throw; } finally { _persistenceManager.DeleteFile(store.StoreConsolidateFile); } }