public Store(string storeLocation, IPageStore dataPageStore, IResourceTable resourceTable) { DirectoryPath = storeLocation; _pageStore = dataPageStore; _graphIndex = new ConcurrentGraphIndex(_pageStore); _subjectRelatedResourceIndex = new RelatedResourceIndex.RelatedResourceIndex(_currentTxnId + 1, _pageStore); _objectRelatedResourceIndex = new RelatedResourceIndex.RelatedResourceIndex(_currentTxnId + 1, _pageStore); _prefixManager = new PrefixManager(_pageStore); _resourceTable = resourceTable; _resourceIndex = new ResourceIndex.ResourceIndex(1, _pageStore, _resourceTable); }
/* * Data format for the store page: * * 00-03: Store format version (int) * 04-11: Transaction id (ulong) * 12-19: Graph Index start page id (ulong) * 20-27: Prefix Manager start page id (ulong) * 28-35: Resource Index start page id (ulong) * 36-43: Subject Related Resource Index start page id (ulong) * 44-51: Object Related Resource Index start page id (ulong) * 44-107: Reserved (all zeros for now) * 108-127: SHA1 hash of bytes 00-108 * 128-255: Repeat of the above structure */ private bool Load(IPage storePage, BrightstarProfiler profiler) { using (profiler.Step("Store.Load")) { // Validate the hash for the index bloc using (var sha1 = new SHA1Managed()) { var recordedHash = new byte[20]; Array.Copy(storePage.Data, 108, recordedHash, 0, 20); var calculatedHash = sha1.ComputeHash(storePage.Data, 0, 108); if (recordedHash.Compare(calculatedHash) != 0) { return(false); } } // Load indexes from the pointers int storeVersion = BitConverter.ToInt32(storePage.Data, 0); if (storeVersion == 1) { _currentTxnId = BitConverter.ToUInt64(storePage.Data, 4); var graphIndexId = BitConverter.ToUInt64(storePage.Data, 12); _graphIndex = new ConcurrentGraphIndex(_pageStore, graphIndexId, profiler); var prefixManagerId = BitConverter.ToUInt64(storePage.Data, 20); _prefixManager = new PrefixManager(_pageStore, prefixManagerId, profiler); var resourceIndexId = BitConverter.ToUInt64(storePage.Data, 28); _resourceIndex = new ResourceIndex.ResourceIndex(_pageStore, _resourceTable, resourceIndexId); var relatedResourceIndexId = BitConverter.ToUInt64(storePage.Data, 36); _subjectRelatedResourceIndex = new RelatedResourceIndex.RelatedResourceIndex(_pageStore, relatedResourceIndexId, profiler); var objectRelatedResourceIndexId = BitConverter.ToUInt64(storePage.Data, 44); _objectRelatedResourceIndex = new RelatedResourceIndex.RelatedResourceIndex(_pageStore, objectRelatedResourceIndexId, profiler); } return(true); } }
/* * Data format for the store page: * * 00-03: Store format version (int) * 04-11: Transaction id (ulong) * 12-19: Graph Index start page id (ulong) * 20-27: Prefix Manager start page id (ulong) * 28-35: Resource Index start page id (ulong) * 36-43: Subject Related Resource Index start page id (ulong) * 44-51: Object Related Resource Index start page id (ulong) * 44-107: Reserved (all zeros for now) * 108-127: SHA1 hash of bytes 00-108 * 128-255: Repeat of the above structure */ private bool Load(IPage storePage, BrightstarProfiler profiler) { using (profiler.Step("Store.Load")) { // Validate the hash for the index bloc using (var sha1 = new SHA1Managed()) { var recordedHash = new byte[20]; Array.Copy(storePage.Data, 108, recordedHash, 0, 20); var calculatedHash = sha1.ComputeHash(storePage.Data, 0, 108); if (recordedHash.Compare(calculatedHash) != 0) { return false; } } // Load indexes from the pointers int storeVersion = BitConverter.ToInt32(storePage.Data, 0); if (storeVersion == 1) { _currentTxnId = BitConverter.ToUInt64(storePage.Data, 4); var graphIndexId = BitConverter.ToUInt64(storePage.Data, 12); _graphIndex = new ConcurrentGraphIndex(_pageStore, graphIndexId, profiler); var prefixManagerId = BitConverter.ToUInt64(storePage.Data, 20); _prefixManager = new PrefixManager(_pageStore, prefixManagerId, profiler); var resourceIndexId = BitConverter.ToUInt64(storePage.Data, 28); _resourceIndex = new ResourceIndex.ResourceIndex(_pageStore, _resourceTable, resourceIndexId); var relatedResourceIndexId = BitConverter.ToUInt64(storePage.Data, 36); _subjectRelatedResourceIndex = new RelatedResourceIndex.RelatedResourceIndex(_pageStore, relatedResourceIndexId, profiler); var objectRelatedResourceIndexId = BitConverter.ToUInt64(storePage.Data, 44); _objectRelatedResourceIndex = new RelatedResourceIndex.RelatedResourceIndex(_pageStore, objectRelatedResourceIndexId, profiler); } return true; } }