Skip to content

Instantly share code, notes, and snippets.

@fdwills
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save fdwills/1136d33ab5ec30a2f298 to your computer and use it in GitHub Desktop.

Select an option

Save fdwills/1136d33ab5ec30a2f298 to your computer and use it in GitHub Desktop.

Revisions

  1. fdwills revised this gist Dec 3, 2014. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions db.md
    Original file line number Diff line number Diff line change
    @@ -30,8 +30,8 @@
    * pw_contact
    * pw_contact_request
    * pw_contact_note
    * pw_payment
    * pw_message
    * pw_call_ledger
    * pw_block

    ### 2. peiwo_shard1, peiwo_shard2, peiwo_shard3系列数据库
    @@ -42,11 +42,10 @@
    * pw_event
    * pw_dialog
    * pw_push
    * pw_payment
    * pw_iap_error
    * pw_reward
    * pw_withdraw
    * pw_task
    * pw_call_ledger

    ## 新用户注册流程

  2. fdwills revised this gist Dec 2, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion db.md
    Original file line number Diff line number Diff line change
    @@ -33,14 +33,14 @@
    * pw_message
    * pw_call_ledger
    * pw_block
    * pw_dialog

    ### 2. peiwo_shard1, peiwo_shard2, peiwo_shard3系列数据库

    #### 类别: 只有一个uid的表

    * pw_user
    * pw_event
    * pw_dialog
    * pw_push
    * pw_payment
    * pw_iap_error
  3. fdwills revised this gist Nov 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion db.md
    Original file line number Diff line number Diff line change
    @@ -33,13 +33,13 @@
    * pw_message
    * pw_call_ledger
    * pw_block
    * pw_dialog

    ### 2. peiwo_shard1, peiwo_shard2, peiwo_shard3系列数据库

    #### 类别: 只有一个uid的表

    * pw_user
    * pw_dialog
    * pw_event
    * pw_push
    * pw_payment
  4. fdwills revised this gist Nov 27, 2014. No changes.
  5. fdwills revised this gist Nov 27, 2014. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion db.md
    Original file line number Diff line number Diff line change
    @@ -57,4 +57,13 @@

    1. 按查找的数据类别,去common或者shard里面查找
    2. 查找pw_user_shard表或redis
    3. 去peiwo_shard#{shard_id}数据库里面查找数据
    3. 去peiwo_shard#{shard_id}数据库里面查找数据

    ## 上线移植

    1. peiwo_common指向当前的peiwo-0的sneaky数据库
    2. peiwo_shard1指向当前的peiwo-0的sneaky数据库
    3. peiwo-1上新建数据库sneaky,peiwo_shard2指向该数据库
    4. peiwo-2上新建数据库sneaky,peiwo_shard3指向该数据库
    5. peiwo_common里建表pw_shard, 插入(1, 0), (2, 50), (3,50)
    6. peiwo_common里建表pw_user_shard,将当前所有用户的shard_id设为1插入pw_user_shard中
  6. fdwills revised this gist Nov 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion db.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@

    #### 第二类: 有uid和tuid表

    存储在common的好处是方便查询
    存储在common的好处是方便查询,后期partition

    * pw_contact
    * pw_contact_request
  7. fdwills revised this gist Nov 27, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions db.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    1. peiwo_common: 存储应用通用数据,存储user的shard数据,存储部分跨用户的数据
    2. peiwo_shard#{1,2,3,4}系列: 主要存储用户数据,以uid分库。存储部分跨用户的数据

    ### peiwo_common数据库
    ### 1. peiwo_common数据库

    #### 第一类: 存储无uid master表

    @@ -34,7 +34,7 @@
    * pw_call_ledger
    * pw_block

    ### peiwo_shard1, peiwo_shard2, peiwo_shard3系列数据库
    ### 2. peiwo_shard1, peiwo_shard2, peiwo_shard3系列数据库

    #### 类别: 只有一个uid的表

  8. fdwills revised this gist Nov 27, 2014. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions db.md
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@
    1. peiwo_common: 存储应用通用数据,存储user的shard数据,存储部分跨用户的数据
    2. peiwo_shard#{1,2,3,4}系列: 主要存储用户数据,以uid分库。存储部分跨用户的数据

    ### peiwo_common
    ### peiwo_common数据库

    #### 第一类: 无uid master数据
    #### 第一类: 存储无uid master表

    * pw_shard

    @@ -23,7 +23,7 @@

    * pw_captcha

    #### 第二类: 有uid和tuid
    #### 第二类: 有uid和tuid表

    存储在common的好处是方便查询

    @@ -34,9 +34,9 @@
    * pw_call_ledger
    * pw_block

    ### peiwo_shard1, peiwo_shard2, peiwo_shard3系列
    ### peiwo_shard1, peiwo_shard2, peiwo_shard3系列数据库

    #### 类别: 只有一个uid
    #### 类别: 只有一个uid的表

    * pw_user
    * pw_dialog
  9. fdwills revised this gist Nov 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion db.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ## DB结构
    ## DB分库、分表

    1. peiwo_common: 存储应用通用数据,存储user的shard数据,存储部分跨用户的数据
    2. peiwo_shard#{1,2,3,4}系列: 主要存储用户数据,以uid分库。存储部分跨用户的数据
  10. fdwills revised this gist Nov 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion db.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@

    #### 第二类: 有uid和tuid

    方便查询
    存储在common的好处是方便查询

    * pw_contact
    * pw_contact_request
  11. fdwills revised this gist Nov 27, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions db.md
    Original file line number Diff line number Diff line change
    @@ -51,9 +51,10 @@
    ## 新用户注册流程

    1. 查找pw_shard表,按权重随机选择shard_id
    2. 将(uid, shard_id)写入pw_user_shard表
    3. (uid, shard_id)写入redis
    2. 将(uid, shard_id)写入pw_user_shard表或redis

    ## 用户数据读取


    1. 按查找的数据类别,去common或者shard里面查找
    2. 查找pw_user_shard表或redis
    3. 去peiwo_shard#{shard_id}数据库里面查找数据
  12. fdwills renamed this gist Nov 27, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  13. fdwills revised this gist Nov 27, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@
    #### 第一类: 无uid master数据

    * pw_shard

    | column | 说明 |
    |--------|------|
    | id | shard_id |
  14. fdwills revised this gist Nov 27, 2014. 1 changed file with 24 additions and 20 deletions.
    44 changes: 24 additions & 20 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -5,26 +5,26 @@

    ### peiwo_common

    无uid
    #### 第一类: 无uid master数据

    * pw_shard
    ```json
    {
    'id': int
    }
    ```
    | column | 说明 |
    |--------|------|
    | id | shard_id |
    | weight | 权重 |

    * pw_user_shard
    ```
    {
    'uid': int,
    'shard_id': int
    }
    ```

    | column | 说明 |
    |--------|------|
    | uid | pw_user表里的uid,用于shard的key |
    | shard_id | 此uid所属的shard |

    * pw_captcha

    有uid和tuid
    #### 第二类: 有uid和tuid

    方便查询

    * pw_contact
    * pw_contact_request
    @@ -33,9 +33,9 @@
    * pw_call_ledger
    * pw_block

    ### peiwo_shard1, peiwo_shard2, peiwo_shard3...
    ### peiwo_shard1, peiwo_shard2, peiwo_shard3系列

    只有一个uid
    #### 类别: 只有一个uid

    * pw_user
    * pw_dialog
    @@ -47,8 +47,12 @@
    * pw_withdraw
    * pw_task

    - 新用户注册
    1. 查找pw_shard表
    2. 随机选择shard_id
    3. 将(uid, shard_id)写入pw_user_shard表
    4. 以后所有的数据写入pw_shard#{shard_id}数据库
    ## 新用户注册流程

    1. 查找pw_shard表,按权重随机选择shard_id
    2. 将(uid, shard_id)写入pw_user_shard表
    3. (uid, shard_id)写入redis

    ## 用户数据读取


  15. fdwills revised this gist Nov 26, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@
    * pw_call_ledger
    * pw_block

    ## peiwo_shard1, peiwo_shard2, peiwo_shard3...
    ### peiwo_shard1, peiwo_shard2, peiwo_shard3...

    只有一个uid

  16. fdwills revised this gist Nov 26, 2014. 1 changed file with 51 additions and 21 deletions.
    72 changes: 51 additions & 21 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,54 @@
    ## peiwo_common
    pw_shard
    pw_user_shard
    pw_captcha

    pw_contact;
    pw_contact_request;
    pw_contact_note;
    pw_message;
    pw_dialog;;
    pw_event;
    pw_push;
    pw_payment;
    pw_iap_error;
    pw_reward;
    pw_withdraw;
    pw_call_ledger;
    pw_block;
    pw_task;
    ## DB结构

    1. peiwo_common: 存储应用通用数据,存储user的shard数据,存储部分跨用户的数据
    2. peiwo_shard#{1,2,3,4}系列: 主要存储用户数据,以uid分库。存储部分跨用户的数据

    ### peiwo_common

    无uid

    * pw_shard
    ```json
    {
    'id': int
    }
    ```

    * pw_user_shard
    ```
    {
    'uid': int,
    'shard_id': int
    }
    ```

    * pw_captcha

    有uid和tuid

    * pw_contact
    * pw_contact_request
    * pw_contact_note
    * pw_message
    * pw_call_ledger
    * pw_block

    ## peiwo_shard1, peiwo_shard2, peiwo_shard3...

    * pw_user: 用户表
    *
    只有一个uid

    * pw_user
    * pw_dialog
    * pw_event
    * pw_push
    * pw_payment
    * pw_iap_error
    * pw_reward
    * pw_withdraw
    * pw_task

    - 新用户注册
    1. 查找pw_shard表
    2. 随机选择shard_id
    3. 将(uid, shard_id)写入pw_user_shard表
    4. 以后所有的数据写入pw_shard#{shard_id}数据库
  17. fdwills created this gist Nov 26, 2014.
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    ## peiwo_common
    pw_shard
    pw_user_shard
    pw_captcha

    pw_contact;
    pw_contact_request;
    pw_contact_note;
    pw_message;
    pw_dialog;;
    pw_event;
    pw_push;
    pw_payment;
    pw_iap_error;
    pw_reward;
    pw_withdraw;
    pw_call_ledger;
    pw_block;
    pw_task;

    ## peiwo_shard1, peiwo_shard2, peiwo_shard3...

    * pw_user: 用户表
    *