Example #1
0
        private static void PreloadData()
        {
            if (Directory.Exists(path))
                Directory.Delete(path, true);

            var options = new Options();
            options.CreateIfMissing = true;
            var leveldb = new DB(options, path);

            var id = Guid.NewGuid().ToString();
            string rowkey = "bob";

            leveldb.Put("/users", "table");
            leveldb.Put("/users/index/column0", "index");
            leveldb.Put("/users/index/column49", "index");

            for (int i = 0; i < rows; i++)
            {
                leveldb.Put(string.Format("/users/{0}", i), "row");
                for (int x = 0; x < columns; x++)
                {
                    leveldb.Put(string.Format("/users/{0}:column{1}", i, x), "bob" + i);
                    leveldb.Put(string.Format("/users/index/column{0}:{1}", x, "bob" + i),
                                string.Format("/users/{0}", i));
                }
            }
            leveldb.Dispose();

            Console.WriteLine(
                "Rows created: " + string.Format("{0:N}", rows) +
                " Columns per row: " + columns +
                " Total keys in DB: " + string.Format("{0:N}", rows * columns));
        }
Example #2
0
File: Ops.cs Project: ren85/cfs
        public static void Put(string Key, string Value)
        {
            Init();

            var hash = Utils.Utils.CalculateMD5Hash(Key);
            int bin = Utils.Utils.GetBinFromHash(hash, Utils.Utils.Partitions);

            CustomLock l = null;
            lock(_lock)
            {
                l = Locks.First(f => f.Name == "db"+bin);
            }
            lock(l)
            {
                if(!dbs.ContainsKey(bin))
                {
                    Options options = new Options()
                    {
                        CreateIfMissing = true
                    };
                    dbs[bin] = DB.Open(options, Path.Combine(Utils.Utils.RootDir, "db"+bin));
                }
                dbs[bin].Put(Key, Value);
            }
        }
Example #3
0
 /// <summary>
 /// Open the storage for use.
 /// </summary>
 public void Open()
 {
     if (db == null)
     {
         var options = new Options { CreateIfMissing = true };
         db = new DB(options, path);
     }
 }
Example #4
0
 private void Rebuilt()
 {
     Cache c = new Cache(100*1024*1024);
     var options = new Options()
     {
         BlockCache = c,
         CreateIfMissing = true,
     };
     this._db = new DB(options, this._path);
 }
Example #5
0
 internal void Initilize()
 {
     string tempPath = Path.GetTempPath();
     string randName = Path.GetRandomFileName();
     LevelDB.Cache c = new LevelDB.Cache(100 * 1024 * 1024);
     var options = new Options()
     {
         BlockCache = c,
         CreateIfMissing = true,
     };
     Database = new LevelDB.DB(options, "tmp/data/.sso/");
 }
Example #6
0
        public override void Init()
        {
            var options = new Options()
            {
                CreateIfMissing = true,
                WriteBufferSize = 1024 * 1024 * 1024,
                MaxOpenFiles = 10
            };

            string DBPath = Path.Combine(Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:///", "")), "PendingTasks");
            _DB = new DB(options, DBPath);
        }
Example #7
0
        public void Cache()
        {
            Database.Dispose();

            // open the DB with a cache that is not owned by LevelDB, then
            // close DB and then free the cache
            var options = new Options() {
                BlockCache = new Cache(64)
            };
            Database = new DB(options, DatabasePath);
            options = null;
            GC.Collect();
            Database.Put("key1", "value1");
            Database.Dispose();
            GC.Collect();
        }
Example #8
0
        static void Main()
        {
            var l = new Logger(s => Console.WriteLine(s));
            var x = new Options 
                    { 
                        CreateIfMissing = true, 
                        RestartInterval = 13, 
                        MaxOpenFiles = 100,
                        InfoLog = l
                    };

            var db = new DB(x, @"C:\Temp\A");
            db.Put("hello", "world");
            var world = db.Get("hello");
            Console.WriteLine(world);

            for (var j = 0; j < 5; j++)
            {
                var r = new Random(0);
                var data = "";

                for (int i = 0; i < 1024; i++)
                {
                    data += 'a' + r.Next(26);
                }
                for (int i = 0; i < 5*1024; i++)
                {
                    db.Put(string.Format("row{0}", i), data);
                }
                Thread.Sleep(100);
            }
            Console.WriteLine();

            //using(var logger = new Logger(Console.WriteLine))
            //{
            //    Console.WriteLine("hello");
            //}

            db.Dispose();
            GC.KeepAlive(l);
        }
Example #9
0
File: LDB.cs Project: ren85/cfs
        void Init()
        {
            if (db == null)
            {
                lock (_lock)
                {
                    if (db == null)
                    {
                        if (!Directory.Exists(DB_PATH))
                        {
                            Directory.CreateDirectory(DB_PATH);
                        }

                        var options = new Options()
                        {
                            CreateIfMissing = true,
                            BloomFilter = new BloomFilterPolicy(10)
                        };

                        db = new DB(DB_PATH, options);
                    }
                }
            }
        }
Example #10
0
File: DBTests.cs Project: vebin/BD2
 public void SetUp()
 {
     var tempPath = Path.GetTempPath ();
     var randName = Path.GetRandomFileName ();
     DatabasePath = Path.Combine (tempPath, randName);
     var options = new Options () {
         CreateIfMissing = true
     };
     Database = new DB (options, DatabasePath);
 }
Example #11
0
File: DBTests.cs Project: vebin/BD2
 public void Error()
 {
     var options = new Options () {
         CreateIfMissing = false
     };
     var db = new DB (options, "non-existent");
     Assert.Fail ();
     db.Get ("key1");
 }
Example #12
0
 /// <summary>
 /// Open the database connection.
 /// </summary>
 private void Open()
 {
     var options = new Options { CreateIfMissing = true };
     db = new DB(options, path);
     opened = true;
     container.RegisterSingle<DB>(db);
 }
Example #13
0
        public DB GetDB(string filePath, Dictionary<string, string> options = null)
        {
            DB db = null;

            if (dbCache.ContainsKey(filePath))
            {
                DBLock lockObj = dbCache[filePath];
                // inc the lockcount
                lockObj.lockCount = lockObj.lockCount + 1;
                // save it back in the list
                dbCache[filePath] = lockObj;
                // store the db obj for return
                db = lockObj.DB;
            }
            else
            {
                // create the new DB
                Options levelDBOptions = new Options();
                levelDBOptions.CreateIfMissing = true;

                db = DB.Open(filePath, levelDBOptions);
                // create the new lock object
                DBLock lockObj = new DBLock();
                lockObj.DB = db;
                // store the new lock obj
                dbCache[filePath] = lockObj;
            }

            return db;
        }
Example #14
0
 public void Delete(Options options)
 {
     //DB.Destroy(options.GetDBOptions(), BASE_PATH + storeName + "\\docStore");
     //DB.Destroy(options.GetDBOptions(), BASE_PATH + storeName + "\\sequenceStore");
     //DB.Destroy(options.GetDBOptions(), BASE_PATH + storeName + "\\attachStore");
     //DB.Destroy(options.GetDBOptions(), BASE_PATH + storeName + "\\attachBinaryStore");
     //DB.Destroy(options.GetDBOptions(), BASE_PATH + storeName);
 }
        public override void Init(int flowCount, long flowRecordCount)
        {
            options = new Options();

            options.CreateIfMissing = true;
            options.CompressionLevel = Compression;
            options.BlockSize = BlockSize;
            options.Cache = new Cache(Cache);
            options.WriteBufferSize = WriteBufferSize;
            options.MaxOpenFiles = MaxOpenFiles;

            database = new DB(Path.Combine(DataDirectory, CollectionName), options);
        }