public void MergeStores() { var newMemoryStore = new PropertyDatabaseMemoryStore(); using (m_MemoryStore.LockUpgradeableRead()) using (m_FileStore.LockUpgradeableRead()) using (var newMemoryStoreView = (PropertyDatabaseMemoryStoreView)newMemoryStore.GetView()) { // Merge both stores newMemoryStoreView.MergeWith(m_FileStoreView); newMemoryStoreView.MergeWith(m_MemoryStoreView); // Write new memory store to file. var tempFilePath = GetTempFilePath(m_FileStore.filePath); newMemoryStoreView.SaveToFile(tempFilePath); // Swap file store with new one m_FileStore.SwapFile(tempFilePath); // Clear the memory store after file was swapped. If you do it before, you risk // entering a state where another thread could try to read between the moment the clear is done // and the new file is written and opened. m_MemoryStoreView.Clear(); } }
public PropertyDatabaseView(PropertyDatabase propertyDatabase, PropertyDatabaseVolatileMemoryStore volatileMemoryStore, PropertyDatabaseMemoryStore memoryStore, PropertyDatabaseFileStore fileStore, PropertyStringTable stringTable, bool delayedSync) { m_PropertyDatabase = propertyDatabase; m_MemoryStore = memoryStore; m_FileStore = fileStore; m_VolatileMemoryStoreView = (PropertyDatabaseVolatileMemoryStoreView)volatileMemoryStore.GetView(); m_MemoryStoreView = (PropertyDatabaseMemoryStoreView)memoryStore.GetView(); m_FileStoreView = (PropertyDatabaseFileStoreView)fileStore.GetView(); m_StringTableView = stringTable.GetView(delayedSync); m_Disposed = false; m_DelayedSync = delayedSync; }