private BaseStore LoadStore(string path, string type, int statesCacheSize) { BaseStore store = null; if (type == "rocksdb") { try { store = new RocksDBStore.RocksDBStore(path, statesCacheSize: statesCacheSize); Log.Debug("RocksDB is initialized."); } catch (TypeInitializationException e) { Log.Error("RocksDB is not available. DefaultStore will be used. {0}", e); } } else { var message = type is null ? "Storage Type is not specified" : $"Storage Type {type} is not supported"; Log.Debug($"{message}. DefaultStore will be used."); } return(store ?? new DefaultStore( path, flush: false, compress: true, statesCacheSize: statesCacheSize)); }
private static IRichStore LoadStore(Options options) { bool readOnlyMode = options.Seeds is null; BaseBlockStatesStore innerStore; switch (options.StoreType) { case "rocksdb": innerStore = new RocksDBStore.RocksDBStore(options.StorePath); break; case "default": innerStore = new DefaultStore( options.StorePath, flush: false, readOnly: readOnlyMode); break; default: // FIXME: give available store type as argument hint without code duplication. var availableStoreTypes = new[] { "rocksdb", "default" }; string longOptionName = options.GetType().GetProperty(nameof(options.StoreType)) .GetCustomAttribute <OptionAttribute>().LongName; throw new InvalidOptionValueException( "--" + longOptionName, options.StoreType, availableStoreTypes); } bool useMySQL = !string.IsNullOrEmpty(options.MySQLDatabase) && !string.IsNullOrEmpty(options.MySQLPassword) && !string.IsNullOrEmpty(options.MySQLServer) && !string.IsNullOrEmpty(options.MySQLUsername) && !(options.MySQLPort is null); if (useMySQL) { var mySqlOptions = new MySQLRichStoreOptions( options.MySQLDatabase, options.MySQLServer, options.MySQLPort.Value, options.MySQLUsername, options.MySQLPassword); return(new MySQLRichStore( innerStore, mySqlOptions )); } else { return(new LiteDBRichStore( innerStore, path: options.StorePath, flush: false, readOnly: readOnlyMode )); } }
protected (IStore, IStateStore) LoadStore(string path, string type, int statesCacheSize) { IStore store = null; if (type == "rocksdb") { try { store = new RocksDBStore.RocksDBStore( path, maxTotalWalSize: 16 * 1024 * 1024, maxLogFileSize: 16 * 1024 * 1024, keepLogFileNum: 1 ); Log.Debug("RocksDB is initialized."); } catch (TypeInitializationException e) { Log.Error("RocksDB is not available. DefaultStore will be used. {0}", e); } } else if (type == "monorocksdb") { try { store = new RocksDBStore.MonoRocksDBStore( path, maxTotalWalSize: 16 * 1024 * 1024, maxLogFileSize: 16 * 1024 * 1024, keepLogFileNum: 1 ); Log.Debug("MonoRocksDB is initialized."); } catch (TypeInitializationException e) { Log.Error("MonoRocksDB is not available. DefaultStore will be used. {0}", e); } } else { var message = type is null ? "Storage Type is not specified" : $"Storage Type {type} is not supported"; Log.Debug($"{message}. DefaultStore will be used."); } store ??= new DefaultStore(path, flush: false); store = new ReducedStore(store); IKeyValueStore stateKeyValueStore = new RocksDBKeyValueStore(Path.Combine(path, "states")), stateHashKeyValueStore = new RocksDBKeyValueStore(Path.Combine(path, "state_hashes")); IStateStore stateStore = new TrieStateStore(stateKeyValueStore, stateHashKeyValueStore); return(store, stateStore); }
private static IStore LoadStore(Options options) { bool readOnlyMode = options.Seeds is null; IStore innerStore; switch (options.StoreType) { case "rocksdb": innerStore = new RocksDBStore.RocksDBStore(options.StorePath); break; case "default": innerStore = new DefaultStore( options.StorePath, flush: false, readOnly: readOnlyMode); break; default: // FIXME: give available store type as argument hint without code duplication. var availableStoreTypes = new[] { "rocksdb", "default" }; string longOptionName = options.GetType().GetProperty(nameof(options.StoreType)) .GetCustomAttribute <OptionAttribute>().LongName; throw new InvalidOptionValueException( "--" + longOptionName, options.StoreType, availableStoreTypes); } IStore store; if (options.Seeds.Any()) { // Wrap up store to use more useful features. store = new RichStore( innerStore, path: options.StorePath, flush: false, readOnly: readOnlyMode ); } else { // If there were no given seeds, // use the store directly. store = innerStore; } return(store); }
private static IRichStore LoadStore(Options options) { // FIXME: This method basically does the same thing to Libplanet.Extensions.Cocona's // StoreCommand.LoadStoreFromUri() & StatsCommand.LoadStoreFromUri() methods. // The duplicate code should be extract to a shared common method. // https://github.com/planetarium/libplanet/issues/1573 bool readOnlyMode = options.Seeds is null; IStore innerStore; switch (options.StoreType) { case "rocksdb": innerStore = new RocksDBStore.RocksDBStore( options.StorePath, maxTotalWalSize: 16 * 1024 * 1024, keepLogFileNum: 1); break; case "default": innerStore = new DefaultStore( options.StorePath, flush: false, readOnly: readOnlyMode); break; default: // FIXME: give available store type as argument hint without code duplication. var availableStoreTypes = new[] { "rocksdb", "default" }; const string longOptionName = "store-type"; throw new InvalidOptionValueException( "--" + longOptionName, options.StoreType, availableStoreTypes); } bool useMySQL = !string.IsNullOrEmpty(options.MySQLDatabase) && !string.IsNullOrEmpty(options.MySQLPassword) && !string.IsNullOrEmpty(options.MySQLServer) && !string.IsNullOrEmpty(options.MySQLUsername) && !(options.MySQLPort is null); if (useMySQL) { var mySqlOptions = new MySQLRichStoreOptions( options.MySQLDatabase, options.MySQLServer, options.MySQLPort.Value, options.MySQLUsername, options.MySQLPassword); return(new MySQLRichStore( innerStore, mySqlOptions )); } else { return(new LiteDBRichStore( innerStore, path: options.StorePath, flush: false, readOnly: readOnlyMode )); } }
private static IRichStore LoadStore(Options options) { bool readOnlyMode = options.Seeds is null; IStore innerStore; switch (options.StoreType) { case "rocksdb": innerStore = new RocksDBStore.RocksDBStore( options.StorePath, maxTotalWalSize: 16 * 1024 * 1024, keepLogFileNum: 1); break; case "monorocksdb": innerStore = new RocksDBStore.MonoRocksDBStore( options.StorePath, maxTotalWalSize: 16 * 1024 * 1024, keepLogFileNum: 1); break; case "default": innerStore = new DefaultStore( options.StorePath, flush: false, readOnly: readOnlyMode); break; default: // FIXME: give available store type as argument hint without code duplication. var availableStoreTypes = new[] { "rocksdb", "default" }; const string longOptionName = "store-type"; throw new InvalidOptionValueException( "--" + longOptionName, options.StoreType, availableStoreTypes); } bool useMySQL = !string.IsNullOrEmpty(options.MySQLDatabase) && !string.IsNullOrEmpty(options.MySQLPassword) && !string.IsNullOrEmpty(options.MySQLServer) && !string.IsNullOrEmpty(options.MySQLUsername) && !(options.MySQLPort is null); if (useMySQL) { var mySqlOptions = new MySQLRichStoreOptions( options.MySQLDatabase, options.MySQLServer, options.MySQLPort.Value, options.MySQLUsername, options.MySQLPassword); return(new MySQLRichStore( innerStore, mySqlOptions )); } else { return(new LiteDBRichStore( innerStore, path: options.StorePath, flush: false, readOnly: readOnlyMode )); } }