コード例 #1
0
        public IStore CreateStore(string storeLocation, PersistenceType storePersistenceType, bool readOnly)
        {
            Logging.LogInfo("Create Store {0} with persistence type {1}", storeLocation, storePersistenceType);
            if (_persistenceManager.DirectoryExists(storeLocation))
            {
                throw new StoreManagerException(storeLocation, "Store already exists");
            }

            _persistenceManager.CreateDirectory(storeLocation);

            var dataFilePath = Path.Combine(storeLocation, DataFileName);
            _persistenceManager.CreateFile(dataFilePath);

            var resourceFilePath = Path.Combine(storeLocation, ResourceFileName);
            _persistenceManager.CreateFile(resourceFilePath);

            MasterFile.Create(_persistenceManager, storeLocation, _storeConfiguration, Guid.NewGuid());
            IPageStore dataPageStore = null;
            switch (storePersistenceType)
            {
                case PersistenceType.AppendOnly:
                    dataPageStore = new AppendOnlyFilePageStore(_persistenceManager, dataFilePath, PageSize, false, _storeConfiguration.DisableBackgroundWrites);
                    break;
                case PersistenceType.Rewrite:
                    dataPageStore = new BinaryFilePageStore(_persistenceManager, dataFilePath, PageSize, false, 0);
                    break;
            }
            IPageStore resourcePageStore = new AppendOnlyFilePageStore(_persistenceManager, resourceFilePath, PageSize, false, _storeConfiguration.DisableBackgroundWrites);
            var resourceTable = new ResourceTable(resourcePageStore);
            using (var store = new Store(storeLocation, dataPageStore, resourceTable))
            {
                store.Commit(Guid.Empty);
            }

            Logging.LogInfo("Store created at {0}", storeLocation);
            return OpenStore(storeLocation, readOnly);
        }
コード例 #2
0
 public IStore OpenStore(string storeLocation, bool readOnly)
 {
     Logging.LogInfo("Open Store {0}", storeLocation);
     var masterFile = MasterFile.Open(_persistenceManager, storeLocation);
     var latestCommitPoint = masterFile.GetLatestCommitPoint();
     var dataFilePath = Path.Combine(storeLocation, DataFileName);
     var resourceFilePath = Path.Combine(storeLocation, ResourceFileName);
     if (_persistenceManager.FileExists(dataFilePath))
     {
         IPageStore dataPageStore = null;
         switch (masterFile.PersistenceType)
         {
                 case PersistenceType.AppendOnly:
                 dataPageStore = new AppendOnlyFilePageStore(_persistenceManager, dataFilePath, PageSize, readOnly, _storeConfiguration.DisableBackgroundWrites);
                 break;
                 case PersistenceType.Rewrite:
                 dataPageStore = new BinaryFilePageStore(_persistenceManager, dataFilePath, PageSize, readOnly, latestCommitPoint.CommitNumber);
                 break;
         }
         var resourcePageStore = new AppendOnlyFilePageStore(_persistenceManager, resourceFilePath, PageSize, readOnly, _storeConfiguration.DisableBackgroundWrites);
         var resourceTable = new ResourceTable(resourcePageStore);
         var store = new Store(storeLocation, dataPageStore, resourceTable, latestCommitPoint.LocationOffset, null);
         Logging.LogInfo("Store {0} opened successfully", storeLocation);
         return store;
     }
     throw new StoreManagerException(storeLocation, "Data file not found");
 }
コード例 #3
0
        /// <summary>
        /// Opens the store at the specified commit point (always read-only)
        /// </summary>
        /// <param name="storeLocation"></param>
        /// <param name="commitPointId"></param>
        /// <returns></returns>
        public IStore OpenStore(string storeLocation, ulong commitPointId)
        {
            if (_storeConfiguration.PersistenceType == PersistenceType.Rewrite)
            {
                throw new InvalidOperationException("Rewrite page store does not support opening at a previous commit point");
            }
            Logging.LogInfo("Open Store {0} at commit point {1}", storeLocation, commitPointId);
            var dataFilePath = Path.Combine(storeLocation, DataFileName);
            var resourceFilePath = Path.Combine(storeLocation, ResourceFileName);
            var commitPoint = GetMasterFile(storeLocation).GetCommitPoints().FirstOrDefault(cp => cp.LocationOffset == commitPointId);
            if (commitPoint != null)
            {
                if (!_persistenceManager.FileExists(resourceFilePath))
                {
                    throw new StoreManagerException(storeLocation, "Resource file not found");
                }
                if (!_persistenceManager.FileExists(dataFilePath))
                {
                    throw new StoreManagerException(storeLocation, "Data file not found");
                }
                var pageStore = new AppendOnlyFilePageStore(_persistenceManager, dataFilePath, PageSize, true, _storeConfiguration.DisableBackgroundWrites);
                var resourceStore = new AppendOnlyFilePageStore(_persistenceManager, resourceFilePath, PageSize, true, _storeConfiguration.DisableBackgroundWrites);
                var resourceTable = new ResourceTable(resourceStore);
                var store = new Store(storeLocation, pageStore, resourceTable, commitPointId, null);
                return store;

            }
            throw new StoreManagerException(storeLocation, "Commit point not found");
        }