Beispiel #1
0
        private void InitFirstBlock(DBCreateOption createOption)
        {
            //数据库需要初始化
            if (createOption == null)
            {
                this.Close();
                throw new Exception("数据库需要初始化 open(path,createOption)");
            }
            else
            {
                var writetask = new WriteTask();
                writetask.CreateTable(new TableInfo(systemtable_info, "_table_info", null, DBValue.Type.String));
                writetask.CreateTable(new TableInfo(systemtable_block, "_table_block", null, DBValue.Type.UINT64));

                if (createOption.FirstTask != null)
                {
                    foreach (var t in createOption.FirstTask.items)
                    {
                        writetask.items.Add(t);
                    }
                }
                writetask.Put(systemtable_info, "_magic_".ToBytes_UTF8Encode(), DBValue.FromValue(DBValue.Type.String, createOption.MagicStr));
                this.WriteUnsafe(writetask, createOption.afterparser);
            }
        }
Beispiel #2
0
        public void Open(string path, DBCreateOption createOption = null)
        {
            if (dbPtr != IntPtr.Zero)
            {
                throw new Exception("already open a db.");
            }
            this.defaultWriteOpPtr = RocksDbSharp.Native.Instance.rocksdb_writeoptions_create();

            var HandleOption = RocksDbSharp.Native.Instance.rocksdb_options_create();

            if (createOption != null)
            {
                RocksDbSharp.Native.Instance.rocksdb_options_set_create_if_missing(HandleOption, true);
            }
            RocksDbSharp.Native.Instance.rocksdb_options_set_compression(HandleOption, RocksDbSharp.CompressionTypeEnum.rocksdb_snappy_compression);
            //RocksDbSharp.DbOptions option = new RocksDbSharp.DbOptions();
            //option.SetCreateIfMissing(true);
            //option.SetCompression(RocksDbSharp.CompressionTypeEnum.rocksdb_snappy_compression);
            IntPtr handleDB = RocksDbSharp.Native.Instance.rocksdb_open(HandleOption, path);

            this.dbPtr = handleDB;

            snapshotLast = CreateSnapInfo();
            if (snapshotLast.DataHeight == 0)
            {
                InitFirstBlock(createOption);
            }
            snapshotLast.AddRef();
        }
        public void Init()
        {
            Console.CursorLeft = 0;
            Console.WriteLine(" == Open DB ==");


            maindb = new LightDB.LightDB();

            state_DBOpen = false;
            string fullpath = System.IO.Path.GetFullPath(Program.config.server_storage_path);

            if (System.IO.Directory.Exists(fullpath) == false)
            {
                System.IO.Directory.CreateDirectory(fullpath);
            }
            string pathDB = System.IO.Path.Combine(fullpath, "maindb");

            try
            {
                maindb.Open(pathDB);
                state_DBOpen = true;
                Console.WriteLine("db opened in:" + pathDB);
            }
            catch (Exception err)
            {
                Console.WriteLine("error msg:" + err.Message);
            }
            if (state_DBOpen == false)
            {
                Console.WriteLine("open database fail. try to create it.");
                try
                {
                    LightDB.DBCreateOption createop = new LightDB.DBCreateOption();
                    createop.MagicStr  = Program.config.storage_maindb_magic;
                    createop.FirstTask = new LightDB.WriteTask();

                    createop.FirstTask.CreateTable(new LightDB.TableInfo(tableID_Writer, "_writeraddress_", "", LightDB.DBValue.Type.String));
                    createop.FirstTask.Put(tableID_Writer, Program.config.storage_maindb_firstwriter_address.ToBytes_UTF8Encode(), LightDB.DBValue.FromValue(LightDB.DBValue.Type.BOOL, true));

                    maindb.Open(pathDB, createop);
                    Console.WriteLine("db created in:" + pathDB);
                    state_DBOpen = true;
                }
                catch (Exception err)
                {
                    Console.WriteLine("error msg:" + err.Message);
                }
            }
        }
Beispiel #4
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();
        }
Beispiel #5
0
        private void InitFirstBlock(DBCreateOption createOption)
        {
            //数据库需要初始化
            if (createOption == null)
            {
                this.Close();
                throw new Exception("数据库需要初始化 open(path,createOption)");
            }
            else
            {
                var writetask = new WriteTask();
                writetask.CreateTable(new TableInfo(systemtable_info, "_table_info", null, DBValue.Type.String));
                writetask.CreateTable(new TableInfo(systemtable_block, "_table_block", null, DBValue.Type.UINT64));

                if (createOption.FirstTask != null)
                {
                    foreach (var t in createOption.FirstTask.items)
                    {
                        writetask.items.Add(t);
                    }
                }
                this.WriteUnsafe(writetask);
            }
        }