示例#1
0
        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);
        }
示例#2
0
        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
                           ));
            }
        }