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
阅读(1339) | 评论(0) | 转发(0) |