1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-28 07:22:20 +00:00
2018-07-08 23:00:30 +08:00

2.7 KiB

6.7. 分布式 id 生成器

                                                                                                     
                                                               datacenter_id          sequence_id    
    unused                                                                                           
                                                                      │                     │        
       │                                                              │                     │        
       │                                                              │                     │        
       │  │                                                      │    │                     │        
       │  │                                                      │    │                     │        
       ▼  │◀──────────────────    41 bits   ────────────────────▶│    ▼                     ▼        
    ┌─────┼──────────────────────────────────────────────────────┼────────┬────────┬────────────────┐
    │  0  │ 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0  │ 00000  │ 00000  │ 0000 0000 0000 │
    └─────┴──────────────────────────────────────────────────────┴────────┴────────┴────────────────┘
                                      ▲                                        ▲                     
                                      │                                        │                     
                                      │                                        │                     
                                      │                                        │                     
                                      │                                        │                     
                                      │                                        │                     
                                      │                                        │                     
                                                                                                     
                            time in milliseconds                          worker_id