/// <summary>
        /// Initializes a new instance of the <see cref="LightningStorageEngine"/> class.
        /// </summary>
        /// <param name="dataPath">The database path.</param>
        public LightningStorageEngine(string dataPath)
        {
            DataPath = dataPath;            

            if (!Directory.Exists(DataPath))
                Directory.CreateDirectory(DataPath);

            _log.Info($"Data Path: {DataPath}");
            _log.Info($"Compression Option: {LightningStorageUtils._compressionOption}");

            var config = new EnvironmentConfiguration
            {
                MaxDatabases = MAX_DATABASES,               
                MapSize = MAX_MAP_SIZE,                
                MaxReaders = MAX_READERS                
            };            

            _environment = new LightningEnvironment(DataPath, config);

            var openFlags = EnvironmentOpenFlags.WriteMap | 
                            EnvironmentOpenFlags.NoMetaSync | 
                            EnvironmentOpenFlags.MapAsync | 
                            EnvironmentOpenFlags.NoThreadLocalStorage;

            _environment.Open(openFlags); 

            _openDatabases = new ConcurrentDictionary<string, LightningDatabase>();                  
            _writeOperationsQueue = new BlockingCollection<WriteOperation>();
            _cancellationTokenSource = new CancellationTokenSource();
            _cancellationToken = _cancellationTokenSource.Token;

            Task.Factory.StartNew(() => BackgroundWriter(), TaskCreationOptions.LongRunning);
        }
        /// <summary>
        /// Creates a new instance of LightningEnvironment.
        /// </summary>
        /// <param name="path">Directory for storing database files.</param>
        /// <param name="configuration">Configuration for the environment.</param>
        public LightningEnvironment(string path, EnvironmentConfiguration configuration = null)
        {
            if (string.IsNullOrWhiteSpace(path))
                throw new ArgumentException("Invalid directory name");

            mdb_env_create(out _handle);

            Path = path;

            var config = configuration ?? _config;
            config.Configure(this);
            _config = config;
        }
예제 #3
0
        /// <summary>
        /// Creates a new instance of LightningEnvironment.
        /// </summary>
        /// <param name="path">Directory for storing database files.</param>
        /// <param name="configuration">Configuration for the environment.</param>
        public LightningEnvironment(string path, EnvironmentConfiguration configuration = null)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Invalid directory name");
            }

            mdb_env_create(out _handle);

            Path = path;

            _config = configuration ?? new EnvironmentConfiguration();
            _config.Configure(this);
        }
        /// <summary>
        /// Creates a new instance of LightningEnvironment.
        /// </summary>
        /// <param name="path">Directory for storing database files.</param>
        /// <param name="configuration">Configuration for the environment.</param>
        public LightningEnvironment(string path, EnvironmentConfiguration configuration = null)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Invalid directory name");
            }

            var config = configuration ?? _config;

#if NETCOREAPP3_1 || NET5_0 || NET6_0
            if (config.AutoResizeWindows)
            {
                LoadWindowsAutoResizeLibrary();
            }
#endif

            mdb_env_create(out _handle).ThrowOnError();
            config.Configure(this);
            _config = config;

            Path = path;
        }