Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var dbOptions      = new DbOptions().SetCreateIfMissing().SetCreateMissingColumnFamilies();
            var columnFamilies = new ColumnFamilies
            {
                { "default", new ColumnFamilyOptions().OptimizeForPointLookup(256) },
                {
                    "user", new ColumnFamilyOptions()
                    .SetMemtableHugePageSize(2 * 1024 * 1024)
                    .SetPrefixExtractor(SliceTransform.CreateFixedPrefix(5))
                    .SetBlockBasedTableFactory(
                        new BlockBasedTableOptions().SetFilterPolicy(BloomFilterPolicy.Create(10, false))
                        .SetWholeKeyFiltering(false))
                }
            };
            var db         = RocksDb.Open(dbOptions, "my.db", columnFamilies);
            var testFamily = db.GetColumnFamily("user");

            db.Put("hello:hi", "hi");
            for (var i = 0; i < 5; i++)
            {
                db.Put($"user:{Guid.NewGuid()}", Guid.NewGuid().ToString(), testFamily);
            }
            using (var it = db.NewIterator(testFamily))
            {
                it.Seek(Encoding.UTF8.GetBytes("user:"******"Done!" + db.Get("hello:hi"));
        }
Exemplo n.º 2
0
        private static void RocksDb3()
        {
            string directory = @"C:\Users\Peska\source\repos\Esent.Tests\RocksDB";

            var bbto = new BlockBasedTableOptions()
                       .SetFilterPolicy(BloomFilterPolicy.Create(10, false))
                       .SetWholeKeyFiltering(false);

            var options = new DbOptions()
                          .SetCreateIfMissing(true)
                          .SetCreateMissingColumnFamilies(true);

            var columnFamilies = new ColumnFamilies
            {
                { "default", new ColumnFamilyOptions().OptimizeForPointLookup(256) },
                { "test", new ColumnFamilyOptions()
                  //.SetWriteBufferSize(writeBufferSize)
                  //.SetMaxWriteBufferNumber(maxWriteBufferNumber)
                  //.SetMinWriteBufferNumberToMerge(minWriteBufferNumberToMerge)
                  .SetMemtableHugePageSize(2 * 1024 * 1024)
                  .SetPrefixExtractor(SliceTransform.CreateFixedPrefix(8))
                  .SetBlockBasedTableFactory(bbto) },
            };

            using (var db = RocksDbSharp.RocksDb.Open(options, directory, columnFamilies))
            {
                var cf = db.GetColumnFamily("test");

                db.Put("00000000Zero", "", cf: cf);
                db.Put("00000001Red", "", cf: cf);
                db.Put("00000000One", "", cf: cf);
                db.Put("00000000Two", "", cf: cf);
                db.Put("00000000Three", "", cf: cf);
                db.Put("00000001Black", "", cf: cf);
                db.Put("00000002Apple", "", cf: cf);
                db.Put("00000002Cranberry", "", cf: cf);
                db.Put("00000001Green", "", cf: cf);
                db.Put("00000002Banana", "", cf: cf);

                var readOptions = new ReadOptions().SetIterateUpperBound("00000002");

                var iter = db.NewIterator(readOptions: readOptions, cf: cf);
                GC.Collect();
                GC.WaitForPendingFinalizers();

                var b = Encoding.UTF8.GetBytes("00000001");

                iter = iter.Seek(b);

                while (iter.Valid())
                {
                    Console.WriteLine(iter.StringKey());
                    iter = iter.Next();
                }

                Console.ReadKey();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string temp = Path.GetTempPath();
            string path = Environment.ExpandEnvironmentVariables(Path.Combine(temp, "rocksdb_prefix_example"));
            var    bbto = new BlockBasedTableOptions()
                          .SetFilterPolicy(BloomFilterPolicy.Create(10, false))
                          .SetWholeKeyFiltering(false)
            ;
            var options = new DbOptions()
                          .SetCreateIfMissing(true)
                          .SetCreateMissingColumnFamilies(true)
            ;
            var columnFamilies = new ColumnFamilies
            {
                { "default", new ColumnFamilyOptions().OptimizeForPointLookup(256) },
                { "test", new ColumnFamilyOptions()
                  //.SetWriteBufferSize(writeBufferSize)
                  //.SetMaxWriteBufferNumber(maxWriteBufferNumber)
                  //.SetMinWriteBufferNumberToMerge(minWriteBufferNumberToMerge)
                  .SetMemtableHugePageSize(2 * 1024 * 1024)
                  .SetPrefixExtractor(SliceTransform.CreateFixedPrefix((ulong)8))
                  .SetBlockBasedTableFactory(bbto) },
            };

            using (var db = RocksDb.Open(options, path, columnFamilies))
            {
                var cf = db.GetColumnFamily("test");

                db.Put("00000000Zero", "", cf: cf);
                db.Put("00000000One", "", cf: cf);
                db.Put("00000000Two", "", cf: cf);
                db.Put("00000000Three", "", cf: cf);
                db.Put("00000001Red", "", cf: cf);
                db.Put("00000001Green", "", cf: cf);
                db.Put("00000001Black", "", cf: cf);
                db.Put("00000002Apple", "", cf: cf);
                db.Put("00000002Cranberry", "", cf: cf);
                db.Put("00000002Banana", "", cf: cf);

                var readOptions = new ReadOptions();
                using (var iter = db.NewIterator(readOptions: readOptions, cf: cf))
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    var b = Encoding.UTF8.GetBytes("00000001");
                    iter.Seek(b);
                    while (iter.Valid())
                    {
                        Console.WriteLine(iter.StringKey());
                        iter.Next();
                    }
                }
            }
            Console.WriteLine("Done...");
        }
Exemplo n.º 4
0
        private static void RocksDb2()
        {
            string directory = @"C:\Users\Peska\source\repos\Esent.Tests\RocksDB";

            DbOptions options = new DbOptions().SetCreateIfMissing();

            using (RocksDb rocksDb = RocksDbSharp.RocksDb.Open(options, directory))
            {
                TestObject o1 = new TestObject {
                    EQNum = "3L1234", Mnemonic = "20013L1234011"
                };
                TestObject o2 = new TestObject {
                    EQNum = "3L5678", Mnemonic = "20023L5678011"
                };
                TestObject o3 = new TestObject {
                    EQNum = "3L9012", Mnemonic = "20033L9012011"
                };
                TestObject o4 = new TestObject {
                    EQNum = "3L9012", Mnemonic = "20013L9012012"
                };

                rocksDb.Put(o1.Mnemonic, JsonConvert.SerializeObject(o1));
                rocksDb.Put(o2.Mnemonic, JsonConvert.SerializeObject(o2));
                rocksDb.Put(o3.Mnemonic, JsonConvert.SerializeObject(o3));
                rocksDb.Put(o4.Mnemonic, JsonConvert.SerializeObject(o4));

                SliceTransform         sliceTransform         = SliceTransform.CreateFixedPrefix(4);
                BlockBasedTableOptions blockBasedTableOptions = new BlockBasedTableOptions().SetWholeKeyFiltering(false);

                ColumnFamilyOptions columnFamilyOptions = new ColumnFamilyOptions()
                                                          .SetPrefixExtractor(sliceTransform)
                                                          .SetBlockBasedTableFactory(blockBasedTableOptions);

                ColumnFamilies columnFamilies = new ColumnFamilies(columnFamilyOptions);

                Iterator iterator = rocksDb.NewIterator();
                iterator = iterator.Seek("2001");

                while (iterator.Valid())
                {
                    string key   = iterator.StringKey();
                    string value = iterator.StringValue();

                    iterator.Next();
                }
            }
        }
Exemplo n.º 5
0
 public RocksDatabase(string path, ulong maxKeyLength = 100)
 {
     Path         = path;
     RocksDb      = RocksDbFactory.GetDatabase(path, SliceTransform.CreateFixedPrefix(maxKeyLength));
     MaxKeyLength = maxKeyLength;
 }