public void ParallelGetTransaction()
        {
            var path  = Path.Combine(Path.GetTempPath(), $"rocksdb_test_{Guid.NewGuid()}");
            var store = new RocksDBStore(path);

            Transaction <DumbAction>[] txs = new[]
            {
                Fx.Transaction1,
                Fx.Transaction2,
                Fx.Transaction3,
            };
            try
            {
                store.PutTransaction(Fx.Transaction1);
                store.PutTransaction(Fx.Transaction2);
                store.PutTransaction(Fx.Transaction3);
                store.Dispose();
                store = new RocksDBStore(path);

                Enumerable.Range(0, 3).AsParallel().ForAll(i =>
                {
                    Assert.NotNull(store.GetTransaction <DumbAction>(txs[i].Id));
                });
            }
            finally
            {
                store.Dispose();
                Directory.Delete(path, true);
            }
        }
Beispiel #2
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!");
        }