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); } }
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!"); }