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 IDisposable LockUpgradeableRead() { return(m_Store.LockUpgradeableRead()); }