Exemple #1
0
        public void ReopenStoreAfterDispose()
        {
            var path = Path.Combine(Path.GetTempPath(), $"rocksdb_test_{Guid.NewGuid()}");

            try
            {
                var store      = new MonoRocksDBStore(path);
                var stateStore = new TrieStateStore(new MemoryKeyValueStore());
                var blocks     = new BlockChain <DumbAction>(
                    new NullPolicy <DumbAction>(),
                    new VolatileStagePolicy <DumbAction>(),
                    store,
                    stateStore,
                    Fx.GenesisBlock
                    );
                store.Dispose();

                store = new MonoRocksDBStore(path);
                store.Dispose();
            }
            finally
            {
                Directory.Delete(path, true);
            }
        }
Exemple #2
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
                {
#pragma warning disable CS0618  // Type or member is obsolete
                    store = new MonoRocksDBStore(
                        path,
                        maxTotalWalSize: 16 * 1024 * 1024,
                        maxLogFileSize: 16 * 1024 * 1024,
                        keepLogFileNum: 1
                        );
#pragma warning restore CS0618  // Type or member is obsolete
                    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"));
            IStateStore    stateStore         = new TrieStateStore(stateKeyValueStore);
            return(store, stateStore);
        }
        public MonoRocksDBStoreFixture()
        {
            Path = System.IO.Path.Combine(
                System.IO.Path.GetTempPath(),
                $"rocksdb_test_{Guid.NewGuid()}"
                );

            Scheme = "monorocksdb://";

            var store = new MonoRocksDBStore(Path, blockCacheSize: 2, txCacheSize: 2);

            Store      = store;
            StateStore = LoadTrieStateStore(Path);
        }
Exemple #4
0
        public void Migration(
            [Option('o', Description = "Path to migration target root path.")]
            string originRootPath,
            [Option('d', Description = "Path to migrated dist root path.")]
            string distRootPath,
            [Option('c', Description = "Skip the copy from target store.")]
            bool skipCopy,
            [Option('b', Description = "Skip the block from target store.")]
            bool skipBlock,
            [Option('t', Description = "Skip the transaction from target store.")]
            bool skipTransaction
            )
        {
            if (!skipCopy)
            {
                Console.WriteLine("Copy Start!");
                DirectoryCopy(originRootPath, distRootPath, true);
                Directory.Delete(Path.Combine(distRootPath, "tx"), true);
                Directory.Delete(Path.Combine(distRootPath, "block"), true);
                Console.WriteLine("Copy Success!");
            }
            else
            {
                Console.WriteLine("Skip copy");
            }

            var originStore = new MonoRocksDBStore(originRootPath);
            var distStore   = new RocksDBStore(distRootPath);

            var totalLength = originStore.CountBlocks();

            if (!skipBlock)
            {
                Console.WriteLine("Start migrate block.");
                foreach (var item in
                         originStore.IterateBlockHashes().Select((value, i) => new { i, value }))
                {
                    Console.WriteLine($"block progress: {item.i}/{totalLength}");
                    Block <NCAction> block = originStore.GetBlock <NCAction>(
                        _ => HashAlgorithmType.Of <SHA256>(),  // thunk getter
                        item.value
                        );
                    distStore.PutBlock(block);
                }

                Console.WriteLine("Finish migrate block.");
            }

            totalLength = originStore.CountTransactions();
            if (!skipTransaction)
            {
                Console.WriteLine("Start migrate transaction.");
                foreach (var item in
                         originStore.IterateTransactionIds()
                         .Select((value, i) => new { i, value }))
                {
                    Console.WriteLine($"tx progress: {item.i}/{totalLength}");
                    distStore.PutTransaction(originStore.GetTransaction <NCAction>(item.value));
                }

                Console.WriteLine("Finish migrate transaction.");
            }

            originStore.Dispose();
            distStore.Dispose();

            Console.WriteLine("Migration Success!");
        }