|
| 1 | +# 索引工具 |
| 2 | + |
| 3 | +主要有两个功能,一个是给未生成索引的 active 订单生成索引,另一个是迁移 top index 到 MongoDB,迁移 shard 到 MySQL。 |
| 4 | + |
| 5 | +### 编译 |
| 6 | + |
| 7 | +``` |
| 8 | +make index |
| 9 | +``` |
| 10 | + |
| 11 | +### 生成索引 |
| 12 | + |
| 13 | +先去 droplet 获取订单状态是 active 的订单,然后去遍历 car 文件,如果被 active 订单使用且未生成索引,则为其生成索引。 |
| 14 | + |
| 15 | +* --car-dir:存储 car 文件的目录。 |
| 16 | +* --index-dir:存储索引文件的目录,`droplet` 默认在 `~/.droplet/dagstore/index`。 |
| 17 | +* --mongo-url:MongoDB 的连接地址,用于存储 top index,数据库是 `market_index`,collection 是 `top_index`。 |
| 18 | +* --mysql-url:MySQL 的连接地址,用于存储 shard 状态,要和 `droplet` 使用同一个数据库,表名是 `shards`。 |
| 19 | +* --droplet-url:droplet 服务的 RPC 地址。 |
| 20 | +* --droplet-token:droplet 服务的 token。 |
| 21 | + |
| 22 | +```bash |
| 23 | +./index-tool gen-index \ |
| 24 | +--car-dir=<car dir> \ |
| 25 | +--index-dir=<index dir> \ |
| 26 | +--mongo-url="mongodb://user:pass@host/?retryWrites=true&w=majority" \ |
| 27 | +--mysql-url="user:pass@(127.0.0.1:3306)/venus-market?parseTime=true&loc=Local" \ |
| 28 | +--droplet-urls="/ip4/127.0.0.1/tcp/41235" \ |
| 29 | +--droplet-token=<token> |
| 30 | +``` |
| 31 | + |
| 32 | +> 成功生成索引会输出类似日志:`generate index success: xxxxxx` |
| 33 | +
|
| 34 | +### 迁移索引 |
| 35 | + |
| 36 | +目前 top index 和 shard 都是存储在 badger,这样多个 droplet 时不能共享,所有需要把 top index 存储到 MongoDB,shard 存储到 MySQL,方便共享数据。 |
| 37 | + |
| 38 | +* --index-dir:存储索引文件的目录,`droplet` 默认在 `~/.droplet/dagstore/index`。 |
| 39 | +* --mongo-url:MongoDB 的连接地址,用于存储 top index,数据库是 `market_index`,`collection` 是 `top_index`。 |
| 40 | +* --mysql-url:MySQL 的连接地址,用于存储 shard 状态,要和 `droplet` 使用同一个数据库,表名是 `shards`。 |
| 41 | + |
| 42 | +```bash |
| 43 | +./index-tool migrate-index \ |
| 44 | +--index-dir=<index dir> \ |
| 45 | +--mongo-url="mongodb://user:pass@host/?retryWrites=true&w=majority" \ |
| 46 | +--mysql-url="user:pass@(127.0.0.1:3306)/venus-market?parseTime=true&loc=Local" \ |
| 47 | +--droplet-urls="/ip4/127.0.0.1/tcp/41235" \ |
| 48 | +--droplet-token=<token> |
| 49 | +``` |
| 50 | + |
| 51 | +> 成功迁移索引会输出类似日志:`migrate xxxxx success` |
0 commit comments