public void SaveAndParentOrderAscGet()
        {
            var dbOptions = new RocksDbSharp.DbOptions();

            dbOptions.SetCreateIfMissing();
            var rocksDb    = RocksDbSharp.RocksDb.Open(dbOptions, @"C:\rocks\secondaryrepositorytst\");
            var repository = new RocksSecondaryRepository(rocksDb, "ent");

            try
            {
                var parentId = ByteArray.New(32);

                var id1    = ByteArray.New(32);
                var value1 = ByteArray.New(256);
                var id2    = ByteArray.New(32);
                var value2 = ByteArray.New(256);
                var id3    = ByteArray.New(32);
                var value3 = ByteArray.New(256);

                using (var transaction = repository.CreateTransaction())
                {
                    var key1 = transaction.AppendValue(parentId, id1, value1.Bytes, value1.Length);
                    transaction.AppendScoreIndex(parentId, id1, key1, 14, IndexLevel.Parent, OrderType.Asc);

                    var key2 = transaction.AppendValue(parentId, id2, value2.Bytes, value2.Length);
                    transaction.AppendScoreIndex(parentId, id2, key2, 12, IndexLevel.Parent, OrderType.Asc);

                    var key3 = transaction.AppendValue(parentId, id3, value3.Bytes, value3.Length);
                    transaction.AppendScoreIndex(parentId, id3, key3, 15, IndexLevel.Parent, OrderType.Asc);

                    transaction.Commit();
                }

                var result  = repository.GetValues(parentId, OrderType.Asc, true).ToArray();
                var result2 = repository.GetValues(parentId, true).ToArray();

                Assert.IsNotNull(result);
                Assert.AreEqual(3, result.Length);

                Assert.IsNotNull(result);
                Assert.AreEqual(3, result2.Length);

                Assert.IsTrue(result[0].Value.ContainsSequence32(value2.Bytes));
                Assert.IsTrue(result[1].Value.ContainsSequence32(value1.Bytes));
                Assert.IsTrue(result[2].Value.ContainsSequence32(value3.Bytes));
            }
            finally
            {
                rocksDb.Dispose();
                Directory.Delete(@"C:\rocks\secondaryrepositorytst\", true);
            }
        }
Ejemplo n.º 2
0
        public void OpenRead(string path)
        {
            if (db != null)
            {
                throw new Exception("already open a db.");
            }
            this.defaultWriteOpPtr = RocksDbSharp.Native.Instance.rocksdb_writeoptions_create();
            RocksDbSharp.DbOptions option = new RocksDbSharp.DbOptions();
            option.SetCreateIfMissing(false);
            option.SetCompression(RocksDbSharp.CompressionTypeEnum.rocksdb_snappy_compression);
            this.db = RocksDbSharp.RocksDb.OpenReadOnly(option, path, true);

            snapshotLast = CreateSnapInfo();
            snapshotLast.AddRef();
        }
Ejemplo n.º 3
0
        public RocksDbStore(string path)
        {
            var options = new RocksDbSharp.DbOptions()
                          .SetCreateIfMissing(false)
                          .SetCreateMissingColumnFamilies(false);

            db         = RocksDb.Open(options, path, ColumnFamilies);
            blockIndex = GetBlocks()
                         .OrderBy(t => t.blockState.header.Index)
                         .Select(t => t.key)
                         .ToList();

            governingTokenHash = new Lazy <UInt256>(() => GetTokenHash(AssetType.GoverningToken));
            utilityTokenHash   = new Lazy <UInt256>(() => GetTokenHash(AssetType.UtilityToken));
        }
Ejemplo n.º 4
0
        public static void TestRocksDb()
        {
            string temp    = System.IO.Path.GetTempPath();
            var    options = new RocksDbSharp.DbOptions().SetCreateIfMissing(true);

            using (var db = RocksDbSharp.RocksDb.Open(options,
                                                      System.IO.Path.Combine(temp, "rocksdb_example")))
            {
                {
                    var iter = db.NewIterator();
                    iter.SeekToLast();
                    if (iter.Valid())
                    {
                        Console.WriteLine($"last is({BitConverter.ToString(iter.Key())},{BitConverter.ToString(iter.Value())})");
                    }
                    else
                    {
                        Console.WriteLine("last not found.");
                    }
                }
                var key1   = Encoding.UTF8.GetBytes("key1");
                var value1 = Encoding.UTF8.GetBytes("value1");
                db.Put(key1, value1);
                Console.WriteLine(BitConverter.ToString(db.Get(key1)));
                var value1get = db.Get(key1);
                Console.WriteLine(null == value1get ? "null" : BitConverter.ToString(value1get));
                var key2   = Encoding.UTF8.GetBytes("key2");
                var value2 = Encoding.UTF8.GetBytes("value2");
                db.Put(key2, value2);
                {
                    var iter = db.NewIterator();
                    iter.SeekToLast();
                    if (iter.Valid())
                    {
                        Console.WriteLine($"last is({BitConverter.ToString(iter.Key())},{BitConverter.ToString(iter.Value())})");
                    }
                    else
                    {
                        Console.WriteLine("last not found.");
                    }
                }
                db.Remove(key1);
                db.Remove(key2);
            }
        }
Ejemplo n.º 5
0
        public void Open(string path, DBCreateOption createOption = null)
        {
            if (db != null)
            {
                throw new Exception("already open a db.");
            }
            this.defaultWriteOpPtr = RocksDbSharp.Native.Instance.rocksdb_writeoptions_create();
            RocksDbSharp.DbOptions option = new RocksDbSharp.DbOptions();
            option.SetCreateIfMissing(true);
            option.SetCompression(RocksDbSharp.CompressionTypeEnum.rocksdb_snappy_compression);
            this.db = RocksDbSharp.RocksDb.Open(option, path);

            snapshotLast = CreateSnapInfo();
            if (snapshotLast.DataHeight == 0)
            {
                InitFirstBlock(createOption);
            }
            snapshotLast.AddRef();
        }