static void test_db_tablecreate(string[] words) { try { Console.WriteLine("test db table"); using (var snap = db.UseSnapShot()) { var writetask = db.CreateWriteTask(); { var info = new TableInfo( new byte[] { 0x01, 0x02, 0x03 }, //tableid 是区分表格的数据,至少长度2,太短的不允许 //下面三个参数都是提供表的信息,无所谓什么 "mytable", //tablename "testtable0001", //tabledesc DBValue.Type.String //tablekeytype ); writetask.CreateTable(info); for (var i = 0; i < 100; i++) { var key = ("key" + i).ToBytes_UTF8Encode(); writetask.Put(new byte[] { 0x01, 0x02, 0x03 }, key, DBValue.FromValue(DBValue.Type.UINT32, (UInt32)i)); } db.Write(writetask); } } Console.WriteLine("create table and write 100 item."); } catch (Exception err) { Console.WriteLine("error:" + err.Message); } }
static void test_db_checkpoint(string[] words) { //建立当前数据库的副本 db.CheckPoint("d:\\db_cp001"); //根据rocksdb的说明,这个建立副本贼鸡儿高效 //然后就从这个数据库读了,这是作为历史记录的数据库,对他只读,别去瞎几把改 var db2 = new LightDB(); db2.OpenRead("d:\\db_cp001"); var snap = db2.UseSnapShot(); var table = snap.GetTableInfo(new byte[] { 01, 02, 03 }); Console.WriteLine("db2 table=" + table.tablename); Console.WriteLine("db2 dataheight=" + snap.DataHeight); }