1)新增数据节点组 group4 并在该数据组中创建 11850 数据节点;
var db=new sdb("localhost",11810);
var datarg = db.createrg("group4");
datarg.createnode("sdbserver1", 11850, "/opt/sequoiadb/database/data/11850/", { logfilenum: 5, transactionon: true } );
datarg.start();
2)创建域 company_domain,其中域包含有 group1,group2,group3;
db.createdomain("company_domain", [ "group1", "group2", "group3" ], { autosplit: true } );
3)创建集合空间 company,存放于 company_domain 域中;
db.createcs("company", { domain: "company_domain" } );
4)在集合空间 company 创建 replsize 为 0 的强一致集合 employee;
db.company.createcl("employee", { "shardingkey": { "_id": 1 }, "shardingtype": "hash", "replsize": 0, "compressed": true, "compressiontype": "lzw", "autosplit": true, "ensureshardingindex": false } );
5)在 company.employee 表中插入数据为(empno:10001, ename:'georgi', age:48);
db.company.employee.insert({"empno":10001,"ename":"georgi","age":48});
6)在 company 集合空间中创建以 tx_time 为分区键,字段类型为 date 的主集合 log;
db.company.createcl("log", { "ismaincl": true, "shardingkey": {"tx_time": 1 }, "shardingtype": "range" } );
7)分别创建 year2020.log 和 year2021.log 子集合,year2020 和year2021 为集合空间名。两个子集合的 hash 分区键字段为 serial_no
(log表中的主键字段,为序列号)。并将两个子集合挂载到主集合 company.log,子集合 year2020.log 保存小于 2021年的数据,而子集合
year2021.log 保存大于等于 2021 年的数据;
db.createcs("year2020", { "domain": "company_domain" } );
db.createcs("year2021", { "domain": "company_domain" } );
db.year2020.createcl("log", { "shardingkey": { "serial_no": 1 }, "shardingtype": "hash", "replsize": -1, "compressed": true, "compressiontype": "lzw", "autosplit": true, "ensureshardingindex": false } );
db.year2021.createcl("log", { "shardingkey": { "serial_no": 1 }, "shardingtype": "hash", "replsize": -1, "compressed": true, "compressiontype": "lzw", "autosplit": true, "ensureshardingindex": false } );
db.company.log.attachcl("year2020.log", { "lowbound": { "tx_time": minkey() }, upbound: { tx_time: { "$date": "2021-01-01" } } } );
db.company.log.attachcl("year2021.log", { lowbound: { "tx_time": { "$date": "2021-01-01" } }, "upbound": { "tx_time": maxkey() } } );
8)用 snapshot 中的集合快照查看 company.employee 的集合并输出查询结果到 /home/sdbadmin/snap_collection.log 文件中;
sdb 'var db=new sdb("localhost", 11810)'
sdb 'db.snapshot(sdb_snap_collections, { name: "company.employee" } )' > /home/sdbadmin/snap_collection.log
9)用 snapshot 中的配置快照查看集群中所有协调节点、编目节点和数据节点的诊断日志路径并输出查询结果到 /home/sdbadmin/snap_diagpath.log 文件中;
sdb 'var db=new sdb("localhost", 11810)'
sdb 'db.snapshot(sdb_snap_configs)' > /home/sdbadmin/snap_diagpath.log
阅读(1157) | 评论(0) | 转发(0) |