/// <summary> /// Create an instance by getting a snapshot from the given KeyValueStore accessor. /// </summary> public KeyValueStoreAccessor(KeyValueStoreAccessor accessor) { StoreDirectory = accessor.StoreDirectory; ReadOnly = true; StoreVersion = accessor.StoreVersion; CreatedNewStore = false; m_store = accessor.m_store.CreateSnapshot(); m_failureHandler = accessor.m_failureHandler; }
/// <summary> /// Create an instance by getting a snapshot from the given KeyValueStore accessor. /// </summary> public KeyValueStoreAccessor(KeyValueStoreAccessor accessor) { StoreDirectory = accessor.StoreDirectory; ReadOnly = true; StoreVersion = accessor.StoreVersion; CreatedNewStore = false; m_invalidateStoreOnDispose = accessor.m_invalidateStoreOnDispose; m_failureHandler = accessor.m_failureHandler; m_disabledFailure = accessor.m_disabledFailure; m_disposed = accessor.m_disposed; m_invalidationHandler = accessor.m_invalidationHandler; if (accessor.Disabled) { // Creating a snapshot of a disabled store will carry the error along, so it should never be accessed. m_store = null; } else { m_store = accessor.m_store.CreateSnapshot(); } }
private static Possible <KeyValueStoreAccessor> OpenInternal( string storeDirectory, int storeVersion, bool defaultColumnKeyTracked, IEnumerable <string> additionalColumns, IEnumerable <string> additionalKeyTrackedColumns, Action <Failure> failureHandler, bool openReadOnly, bool dropMismatchingColumns, bool createNew) { KeyValueStoreAccessor accessor = null; bool useVersioning = storeVersion != VersionConstants.IgnoreStore; try { var persistedStoreVersion = -1; if (createNew) { accessor?.Dispose(); if (FileUtilities.FileExistsNoFollow(storeDirectory)) { FileUtilities.DeleteFile(storeDirectory); } else if (FileUtilities.DirectoryExistsNoFollow(storeDirectory)) { FileUtilities.DeleteDirectoryContents(storeDirectory); } FileUtilities.CreateDirectory(storeDirectory); if (useVersioning) { WriteVersionFile(storeDirectory, storeVersion); } persistedStoreVersion = storeVersion; } else { var possibleStoreVersion = ReadStoreVersion(storeDirectory); if (possibleStoreVersion.Succeeded) { persistedStoreVersion = possibleStoreVersion.Result; // Even if the store does not use the built in versioning, checks for an invalid store will be done to ensure a corrupt store is not opened if (persistedStoreVersion == VersionConstants.InvalidStore) { return(new Failure <string>("The existing store is invalid and and may not be safe to open.")); } // First check for invalid (corrupt) stores before incompatible store format versions if (useVersioning && persistedStoreVersion != storeVersion) { return(new Failure <string>($"The existing store format version is incompatible expected format version. Existing store version: {persistedStoreVersion}, expected format version: {storeVersion}.")); } } else { return(possibleStoreVersion.Failure); } } accessor = new KeyValueStoreAccessor( storeDirectory, persistedStoreVersion, defaultColumnKeyTracked, additionalColumns, additionalKeyTrackedColumns, failureHandler, openReadOnly, dropMismatchingColumns, createNew); } catch (Exception ex) { return(new Failure <Exception>(ex)); } return(accessor); }
private static Possible <KeyValueStoreAccessor> OpenInternal( RocksDbStoreConfiguration storeConfiguration, int storeVersion, Action <RocksDbFailureEvent>?failureHandler, bool createNewStore, Action <Failure <Exception> >?invalidationHandler) { KeyValueStoreAccessor?accessor = null; bool useVersioning = storeVersion != VersionConstants.IgnoreStore; try { var persistedStoreVersion = -1; if (createNewStore) { if (FileUtilities.FileExistsNoFollow(storeConfiguration.StoreDirectory)) { FileUtilities.DeleteFile(storeConfiguration.StoreDirectory); } else if (FileUtilities.DirectoryExistsNoFollow(storeConfiguration.StoreDirectory)) { FileUtilities.DeleteDirectoryContents(storeConfiguration.StoreDirectory); } FileUtilities.CreateDirectory(storeConfiguration.StoreDirectory); if (useVersioning) { WriteVersionFile(storeConfiguration.StoreDirectory, storeVersion); } persistedStoreVersion = storeVersion; } else { var possibleStoreVersion = ReadStoreVersion(storeConfiguration.StoreDirectory); if (possibleStoreVersion.Succeeded) { persistedStoreVersion = possibleStoreVersion.Result; // Even if the store does not use the built in versioning, checks for an invalid store will be done to ensure a corrupt store is not opened if (persistedStoreVersion == VersionConstants.InvalidStore) { return(new Failure <string>("The existing store is invalid and and may not be safe to open.")); } // First check for invalid (corrupt) stores before incompatible store format versions if (useVersioning && persistedStoreVersion != storeVersion) { return(new Failure <string>($"The existing store format version is incompatible expected format version. Existing store version: {persistedStoreVersion}, expected format version: {storeVersion}.")); } } else { return(possibleStoreVersion.Failure); } } accessor = new KeyValueStoreAccessor( storeConfiguration, persistedStoreVersion, failureHandler, createNewStore, invalidationHandler); } catch (Exception ex) { return(new Failure <Exception>(ex)); } return(accessor); }