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));
        }
Exemple #2
0
        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
        }
Exemple #3
0
        public void TestCreateStore()
        {
            Configuration.ResourceCacheLimit = 10000;
            Configuration.PageCacheSize      = 4;

            var client    = GetEmbeddedClient();
            var storeName = "TestCreateStore_" + _runId;
            var storePath = Path.Combine(TestConfiguration.StoreLocation, storeName);
            var dataPath  = Path.Combine(storePath, "data.bs");

            client.CreateStore(storeName);


            Assert.IsTrue(client.DoesStoreExist(storeName));
            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsTrue(_pm.DirectoryExists(storePath));
            Assert.IsTrue(_pm.FileExists(dataPath));

            client.DeleteStore(storeName);

            Task.Delay(50).Wait(); // Wait to allow store to shutdown

            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsFalse(_pm.DirectoryExists(storePath));
            Assert.IsFalse(_pm.FileExists(dataPath));
            Assert.IsFalse(client.DoesStoreExist(storeName));
        }
Exemple #4
0
        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");
        }
Exemple #5
0
        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");
        }
Exemple #6
0
 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 AppendOnlyFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly, bool disableBackgroundWrites)
        {
            _peristenceManager = persistenceManager;
            _path = filePath;

            if ((_pageSize % 4096) != 0)
            {
                throw new ArgumentException("Page size must be a multiple of 4096 bytes");
            }
            _pageSize = pageSize;
            _bitShift = (int)Math.Log(_pageSize, 2.0);

            if (!_peristenceManager.FileExists(filePath) && !readOnly)
            {
                // Create an empty file that we can write to later
                _peristenceManager.CreateFile(filePath);
            }
            _stream = _peristenceManager.GetInputStream(_path);
            _nextPageId = ((ulong)_stream.Length >> _bitShift) + 1;
            if (!readOnly)
            {
                _newPages = new List<IPage>(512);
                _newPageOffset = _nextPageId;
            }
            _pageSize = pageSize;
            _readonly = readOnly;

            if (!readOnly && !disableBackgroundWrites)
            {
                _backgroundPageWriter =
                    new BackgroundPageWriter(persistenceManager.GetOutputStream(filePath, FileMode.Open));
            }

        }
Exemple #8
0
        public AppendOnlyFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly, bool disableBackgroundWrites)
        {
            _peristenceManager = persistenceManager;
            _path = filePath;

            if ((_pageSize % 4096) != 0)
            {
                throw new ArgumentException("Page size must be a multiple of 4096 bytes");
            }
            _pageSize = pageSize;
            _bitShift = (int)Math.Log(_pageSize, 2.0);

            if (!_peristenceManager.FileExists(filePath) && !readOnly)
            {
                // Create an empty file that we can write to later
                _peristenceManager.CreateFile(filePath);
            }
            _stream     = _peristenceManager.GetInputStream(_path);
            _nextPageId = ((ulong)_stream.Length >> _bitShift) + 1;
            if (!readOnly)
            {
                _newPages      = new List <IPage>(512);
                _newPageOffset = _nextPageId;
            }
            _pageSize = pageSize;
            _readonly = readOnly;

            if (!readOnly && !disableBackgroundWrites)
            {
                _backgroundPageWriter =
                    new BackgroundPageWriter(persistenceManager.GetOutputStream(filePath, FileMode.Open));
            }
        }
Exemple #9
0
        public IEnumerable <StoreStatistics> GetStatistics()
        {
            if (!_persistenceManager.FileExists(GetStatisticsHeaderFile()))
            {
                yield break;
            }
            using (var headerStream = _persistenceManager.GetInputStream(GetStatisticsHeaderFile()))
            {
                using (var headerReader = new BinaryReader(headerStream))
                {
                    using (
                        var recordStream =
                            _persistenceManager.GetInputStream(GetStatisticsLogFile()))
                    {
                        long offset = headerStream.Length - StoreStatisticsHeaderRecord.RecordSize;
                        while (offset >= 0)
                        {
                            headerReader.BaseStream.Seek(offset, SeekOrigin.Begin);
                            var header = StoreStatisticsHeaderRecord.Load(headerReader);
                            recordStream.Seek(header.StartOffset, SeekOrigin.Begin);
                            var recordReader = new StreamReader(recordStream);
                            var record       = StoreStatisticsRecord.Load(recordReader);
                            yield return
                                (new StoreStatistics(header.CommitNumber, header.Timestamp, record.TotalTripleCount,
                                                     record.PredicateTripleCounts));

                            offset -= StoreStatisticsHeaderRecord.RecordSize;
                        }
                    }
                }
            }
        }
        public IEnumerable <string> ListStores(string baseLocation)
        {
            var directories = _persistenceManager.ListSubDirectories(baseLocation);

            foreach (var directory in directories)
            {
                if (_persistenceManager.FileExists(baseLocation + "\\" + directory + "\\masterfile.bs"))
                {
                    yield return(directory);
                }
            }
        }
Exemple #11
0
 public static void Initialise(string logFileName, bool enableDebug = false)
 {
     _persistenceManager = PlatformAdapter.Resolve<IPersistenceManager>();
     if (logFileName != null)
     {
         if (!_persistenceManager.FileExists(logFileName))
         {
             _persistenceManager.CreateFile(logFileName);
         }
         _logFileName = logFileName;
     }
     IsDebugEnabled = enableDebug;
 }
Exemple #12
0
 public static void Initialise(string logFileName, bool enableDebug = false)
 {
     _persistenceManager = PlatformAdapter.Resolve <IPersistenceManager>();
     if (logFileName != null)
     {
         if (!_persistenceManager.FileExists(logFileName))
         {
             _persistenceManager.CreateFile(logFileName);
         }
         _logFileName = logFileName;
     }
     IsDebugEnabled = enableDebug;
 }
        public IEnumerable <string> ListStores(string baseLocation)
        {
            foreach (var directory in _persistenceManager.ListSubDirectories(baseLocation))
            {
#if SILVERLIGHT || PORTABLE
                // Silverlight does not have a Path.Combine that takes three params
                var path = Path.Combine(Path.Combine(baseLocation, directory), MasterFile.MasterFileName);
#else
                var path = Path.Combine(baseLocation, directory, MasterFile.MasterFileName);
#endif
                if (_persistenceManager.FileExists(path))
                {
                    yield return(directory);
                }
            }
        }
Exemple #14
0
 public static MasterFile Open(IPersistenceManager persistenceManager, string directoryPath)
 {
     var masterFilePath = Path.Combine(directoryPath, MasterFileName);
     if (!persistenceManager.FileExists(masterFilePath))
     {
         throw new StoreManagerException(directoryPath, "Master file not found");
     }
     var mf = new MasterFile(persistenceManager, directoryPath, masterFilePath,
                             StoreConfiguration.DefaultStoreConfiguration, Guid.Empty);
     using (var mfStream = persistenceManager.GetInputStream(masterFilePath))
     {
         mf.Load(mfStream);
     }
     return mf;
 }
        public void TestCreateStore(PersistenceType persistenceType)
        {
            var client    = GetEmbeddedClient();
            var storeName = MakeStoreName("TestCreateStore", persistenceType);
            var storePath = Path.Combine(TestConfiguration.StoreLocation, storeName);
            var dataPath  = Path.Combine(storePath, "data.bs");

            client.CreateStore(storeName, persistenceType);


            Assert.IsTrue(client.DoesStoreExist(storeName));
            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsTrue(_pm.DirectoryExists(storePath));
            Assert.IsTrue(_pm.FileExists(dataPath));

            client.DeleteStore(storeName);

            Task.Delay(1000).Wait(); // Wait to allow store to shutdown

            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation));
            Assert.IsFalse(_pm.FileExists(dataPath), "Expected data file to be deleted, but it was still found at {0}", dataPath);
            Assert.IsFalse(_pm.DirectoryExists(storePath), "Expected store directory to be deleted, but it was still found at {0}", storePath);
            Assert.IsFalse(client.DoesStoreExist(storeName), "Expected client to report that store not longer exists after deletion");
        }
Exemple #16
0
        public ITransactionInfo ReadTransactionInfo(int transactionNumber)
        {
            if (!_persistenceManager.FileExists(GetTransactionLogHeaderFile()))
            {
                return(null);
            }

            using (var stream = _persistenceManager.GetInputStream(GetTransactionLogHeaderFile()))
            {
                var readPosition = transactionNumber * TransactionInfo.TransactionInfoRecordSize;

                // check if this is a valid transaction number, return null if beyond end of file.
                if (readPosition > stream.Length)
                {
                    return(null);
                }

                // seek to position
                stream.Seek(-readPosition, SeekOrigin.End);

                // read
                return(TransactionInfo.Load(new BinaryReader(stream)));
            }
        }
Exemple #17
0
        public void TestCreateAndDeleteStore()
        {
            var client    = GetEmbeddedClient();
            var storeName = "TestCreateStore_" + _runId;
            var storePath = Path.Combine(TestConfiguration.StoreLocation, storeName);
            var dataPath  = Path.Combine(storePath, "data.bs");

            client.CreateStore(storeName);


            Assert.IsTrue(client.DoesStoreExist(storeName), "Expected True from DoesStoreExist after store created.");
            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation), "Expected stores directory at {0}", TestConfiguration.StoreLocation);
            Assert.IsTrue(_pm.DirectoryExists(storePath), "Expected store directory at {0}", storePath);
            Assert.IsTrue(_pm.FileExists(dataPath), "Expected B* data file at {0}", dataPath);

            client.DeleteStore(storeName);

            Task.Delay(50).Wait(); // Wait to allow store to shutdown

            Assert.IsTrue(_pm.DirectoryExists(TestConfiguration.StoreLocation), "Expected stores directory at {0} after store deleted.", TestConfiguration.StoreLocation);
            Assert.IsFalse(_pm.FileExists(dataPath), "Expected data file to be deleted from {0}.", dataPath);
            Assert.IsFalse(_pm.DirectoryExists(storePath), "Expected store directory to be deleted from {0}.", storePath);
            Assert.IsFalse(client.DoesStoreExist(storeName), "Expected False from DoesStoreExist after store deleted.");
        }
Exemple #18
0
 public static MasterFile Create(IPersistenceManager persistenceManager, string directoryPath,
                                 StoreConfiguration storeConfiguration, Guid storeSetId)
 {
     var masterFilePath = Path.Combine(directoryPath, MasterFileName);
     if (persistenceManager.FileExists(masterFilePath))
     {
         throw new StoreManagerException(directoryPath, "Master file already exists");
     }
     persistenceManager.CreateFile(masterFilePath);
     using (var stream = persistenceManager.GetOutputStream(masterFilePath, FileMode.Open))
     {
         var newMaster = new MasterFile(persistenceManager, directoryPath, masterFilePath, storeConfiguration,
                                        storeSetId);
         newMaster.Save(stream);
         return newMaster;
     }
 }
Exemple #19
0
        public static MasterFile Open(IPersistenceManager persistenceManager, string directoryPath)
        {
            var masterFilePath = Path.Combine(directoryPath, MasterFileName);

            if (!persistenceManager.FileExists(masterFilePath))
            {
                throw new StoreManagerException(directoryPath, "Master file not found");
            }
            var mf = new MasterFile(persistenceManager, directoryPath, masterFilePath,
                                    StoreConfiguration.DefaultStoreConfiguration, Guid.Empty);

            using (var mfStream = persistenceManager.GetInputStream(masterFilePath))
            {
                mf.Load(mfStream);
            }
            return(mf);
        }
Exemple #20
0
        public static MasterFile Create(IPersistenceManager persistenceManager, string directoryPath,
                                        StoreConfiguration storeConfiguration, Guid storeSetId)
        {
            var masterFilePath = Path.Combine(directoryPath, MasterFileName);

            if (persistenceManager.FileExists(masterFilePath))
            {
                throw new StoreManagerException(directoryPath, "Master file already exists");
            }
            persistenceManager.CreateFile(masterFilePath);
            using (var stream = persistenceManager.GetOutputStream(masterFilePath, FileMode.Open))
            {
                var newMaster = new MasterFile(persistenceManager, directoryPath, masterFilePath, storeConfiguration,
                                               storeSetId);
                newMaster.Save(stream);
                return(newMaster);
            }
        }
        private void OpenInputStream()
        {
            if (!_persistenceManager.FileExists(_filePath))
            {
                if (CanWrite)
                {
                    // Attempt to create the file
                    _persistenceManager.CreateFile(_filePath);
                }
                else
                {
                    // File not found
#if PORTABLE || WINDOWS_PHONE
                    throw new FileNotFoundException(String.Format("Could not find file at {0}", _filePath));
#else
                    throw new FileNotFoundException("Could not find requested file", _filePath);
#endif
                }
            }
            _inputStream = _persistenceManager.GetInputStream(_filePath);
        }
Exemple #22
0
 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 BinaryFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly, ulong currentTransactionId)
        {
            _persistenceManager = persistenceManager;
            _filePath = filePath;
            _nominalPageSize = pageSize;
            _isReadOnly = readOnly;
            _modifiedPages = new Dictionary<ulong, BinaryFilePage>();
            CurrentTransactionId = currentTransactionId;
            if(!_persistenceManager.FileExists(filePath))
            {
                if (readOnly)
                {
#if SILVERLIGHT
                    throw new FileNotFoundException(String.Format("Could not find file at {0}", filePath));
#else
                    throw new FileNotFoundException(String.Format("Could not find file at {0}", filePath), filePath);
#endif
                }
                _persistenceManager.CreateFile(filePath);
            }
            _inputStream = _persistenceManager.GetInputStream(filePath);
            _nextPageId = (ulong)_inputStream.Length/((uint)pageSize*2) + 1;
        }
        public BinaryFilePageStore(IPersistenceManager persistenceManager, string filePath, int pageSize, bool readOnly, ulong currentTransactionId)
        {
            _persistenceManager  = persistenceManager;
            _filePath            = filePath;
            _nominalPageSize     = pageSize;
            _isReadOnly          = readOnly;
            _modifiedPages       = new Dictionary <ulong, BinaryFilePage>();
            CurrentTransactionId = currentTransactionId;
            if (!_persistenceManager.FileExists(filePath))
            {
                if (readOnly)
                {
#if SILVERLIGHT
                    throw new FileNotFoundException(String.Format("Could not find file at {0}", filePath));
#else
                    throw new FileNotFoundException(String.Format("Could not find file at {0}", filePath), filePath);
#endif
                }
                _persistenceManager.CreateFile(filePath);
            }
            _inputStream = _persistenceManager.GetInputStream(filePath);
            _nextPageId  = (ulong)_inputStream.Length / ((uint)pageSize * 2) + 1;
        }
Exemple #25
0
 private void CheckEnabled()
 {
     IsEnabled = _persistenceManager.FileExists(GetTransactionLogHeaderFile());
 }
 public void TestCreateFile()
 {
     if (_pm.FileExists("test.txt"))
     {
         _pm.DeleteFile("test.txt");
     }
     _pm.CreateFile("test.txt");
     Assert.IsTrue(_pm.FileExists("test.txt"));
 }