企业做网站哪家便宜,台州网站推广,网站建设制作的规划方案,服务器上的网站分布式id生成算法的有很多种#xff0c;Twitter的SnowFlake就是其中经典的一种。概述SnowFlake算法生成id的结果是一个64bit大小的整数#xff0c;它的结构如下图#xff1a;1位#xff0c;不用。二进制中最高位为1的都是负数#xff0c;但是我们生成的id一般都使用整数Twitter的SnowFlake就是其中经典的一种。概述SnowFlake算法生成id的结果是一个64bit大小的整数它的结构如下图1位不用。二进制中最高位为1的都是负数但是我们生成的id一般都使用整数所以这个最高位固定是041位用来记录时间戳(毫秒)。41位可以表示$2^{41}-1$个数字如果只用来表示正整数(计算机中正数包含0)可以表示的数值范围是0 至 $2^{41}-1$减1是因为可表示的数值范围是从0开始算的而不是1。也就是说41位可以表示$2^{41}-1$个毫秒的值转化成单位年则是$(2^{41}-1) / (1000 * 60 * 60 * 24 * 365) 69$年10位用来记录工作机器id。可以部署在$2^{10} 1024$个节点包括5位datacenterId和5位workerId5位(bit)可以表示的最大正整数是$2^{5}-1 31$即可以用0、1、2、3、....31这32个数字来表示不同的datecenterId或workerId12位序列号用来记录同毫秒内产生的不同id。12位(bit)可以表示的最大正整数是$2^{12}-1 4095$即可以用0、1、2、3、....4094这4095个数字来表示同一机器同一时间截(毫秒)内产生的4095个ID序号由于在Java中64bit的整数是long类型所以在Java中SnowFlake算法生成的id就是long来存储的。SnowFlake可以保证所有生成的id按时间趋势递增整个分布式系统内不会产生重复id(因为有datacenterId和workerId来做区分)Talk is cheap, show you the code以下是Twitter官方原版的用Scala写的(我也不懂Scala当成Java看即可)/** Copyright 2010-2012 Twitter, Inc.*/package com.twitter.service.snowflakeimport com.twitter.ostrich.stats.Statsimport com.twitter.service.snowflake.gen._import java.util.Randomimport com.twitter.logging.Logger/*** An object that generates IDs.* This is broken into a separate class in case* we ever want to support multiple worker threads* per process*/class IdWorker(val workerId: Long,val datacenterId: Long,private val reporter: Reporter,var sequence: Long 0L) extends Snowflake.Iface {private[this] def genCounter(agent: String) {Stats.incr(ids_generated)Stats.incr(ids_generated_%s.format(agent))}private[this] val exceptionCounter Stats.getCounter(exceptions)private[this] val log Logger.getprivate[this] val rand new Randomval twepoch 1288834974657Lprivate[this] val workerIdBits 5Lprivate[this] val datacenterIdBits 5Lprivate[this] val maxWorkerId -1L ^ (-1L workerIdBits)private[this] val maxDatacenterId -1L ^ (-1L datacenterIdBits)private[this] val sequenceBits 12Lprivate[this] val workerIdShift sequenceBitsprivate[this] val datacenterIdShift sequenceBits workerIdBitsprivate[this] val timestampLeftShift sequenceBits workerIdBits datacenterIdBitsprivate[this] val sequenceMask -1L ^ (-1L sequenceBits)private[this] var lastTimestamp -1L// sanity check for workerIdif (workerId maxWorkerId || workerId 0) {exceptionCounter.incr(1)throw new IllegalArgumentException(worker Id cant be greater than %d or less than 0.format(maxWorkerId))}if (datacenterId maxDatacenterId || datacenterId 0) {exceptionCounter.incr(1)throw new IllegalArgumentException(datacenter Id cant be greater than %d or less than 0.format(maxDatacenterId))}log.info(worker starting. timestamp left shift %d, datacenter id bits %d, worker id bits %d, sequence bits %d, workerid %d,timestampLeftShift, datacenterIdBits, workerIdBits, sequenceBits, workerId)def get_id(useragent: String): Long {if (!validUseragent(useragent)) {exceptionCounter.incr(1)throw new InvalidUserAgentError}val id nextId()genCounter(useragent)reporter.report(new AuditLogEntry(id, useragent, rand.nextLong))id}def get_worker_id(): Long workerIddef get_datacenter_id(): Long datacenterIddef get_timestamp() System.currentTimeMillisprotected[snowflake] def nextId(): Long synchronized {var timestamp timeGen()if (timestamp lastTimestamp) {exceptionCounter.incr(1)log.error(clock is moving backwards. Rejecting requests until %d., lastTimestamp);throw new InvalidSystemClock(Clock moved backwards. Refusing to generate id for %d milliseconds.format(lastTimestamp - timestamp))}if (lastTimestamp timestamp) {sequence (sequence 1) sequenceMaskif (sequence 0) {timestamp tilNextMillis(lastTimestamp)}} else {sequence 0}lastTimestamp timestamp((timestamp - twepoch) timestampLeftShift) |(datacenterId datacenterIdShift) |(workerId workerIdShift) |sequence}protected def tilNextMillis(lastTimestamp: Long): Long {var timestamp timeGen()while (timestamp lastTimestamp) {timestamp timeGen()}timestamp}protected def timeGen(): Long System.currentTimeMillis()val AgentParser ([a-zA-Z][a-zA-Z\-0-9]*).rdef validUseragent(useragent: String): Boolean useragent match {case AgentParser(_) truecase _ false}}Scala是一门可以编译成字节码的语言简单理解是在Java语法基础上加上了很多语法糖例如不用每条语句后写分号可以使用动态类型等等。抱着试一试的心态我把Scala版的代码“翻译”成Java版本的对scala代码改动的地方如下/** Copyright 2010-2012 Twitter, Inc.*/package com.twitter.service.snowflakeimport com.twitter.ostrich.stats.Statsimport com.twitter.service.snowflake.gen._import java.util.Randomimport com.twitter.logging.Logger/*** An object that generates IDs.* This is broken into a separate class in case* we ever want to support multiple worker threads* per process*/class IdWorker( // |val workerId: Long, // |val datacenterId: Long, // |private val reporter: Reporter,//日志相关删 // |var sequence: Long 0L) // |extends Snowflake.Iface { //接口找不到删 // |private[this] def genCounter(agent: String) { // |Stats.incr(ids_generated) // |Stats.incr(ids_generated_%s.format(agent)) // |} // |private[this] val exceptionCounter Stats.getCounter(exceptions) // |private[this] val log Logger.get // |private[this] val rand new Random // |val twepoch 1288834974657Lprivate[this] val workerIdBits 5Lprivate[this] val datacenterIdBits 5Lprivate[this] val maxWorkerId -1L ^ (-1L workerIdBits)private[this] val maxDatacenterId -1L ^ (-1L datacenterIdBits)private[this] val sequenceBits 12Lprivate[this] val workerIdShift sequenceBitsprivate[this] val datacenterIdShift sequenceBits workerIdBitsprivate[this] val timestampLeftShift sequenceBits workerIdBits datacenterIdBitsprivate[this] val sequenceMask -1L ^ (-1L sequenceBits)private[this] var lastTimestamp -1L//----------------------------------------------------------------------------------------------------------------------------//// sanity check for workerId //if (workerId maxWorkerId || workerId 0) { //exceptionCounter.incr(1) //throw new IllegalArgumentException(worker Id cant be greater than %d or less than 0.format(maxWorkerId)) //这// |--改成throw new IllegalArgumentException //部// (String.format(worker Id cant be greater than %d or less than 0,maxWorkerId)) //分} //放//到if (datacenterId maxDatacenterId || datacenterId 0) { //构exceptionCounter.incr(1) //throw new IllegalArgumentException(datacenter Id cant be greater than %d or less than 0.format(maxDatacenterId)) //函// |--改成throw new IllegalArgumentException //数// (String.format(datacenter Id cant be greater than %d or less than 0,maxDatacenterId)) //中} ////log.info(worker starting. timestamp left shift %d, datacenter id bits %d, worker id bits %d, sequence bits %d, workerid %d, //timestampLeftShift, datacenterIdBits, workerIdBits, sequenceBits, workerId) //// |--改成System.out.printf(worker...%d...,timestampLeftShift,...); ////----------------------------------------------------------------------------------------------------------------------------////-------------------------------------------------------------------////这个函数删除错误处理相关的代码后剩下一行代码val id nextId() ////所以我们直接调用nextId()函数可以了所以在“翻译”时可以删除这个函数 //def get_id(useragent: String): Long { //if (!validUseragent(useragent)) { //exceptionCounter.incr(1) //throw new InvalidUserAgentError //删} //除//val id nextId() //genCounter(useragent) ////reporter.report(new AuditLogEntry(id, useragent, rand.nextLong)) //id //} ////-------------------------------------------------------------------//def get_worker_id(): Long workerId // |def get_datacenter_id(): Long datacenterId // |def get_timestamp() System.currentTimeMillis // |protected[snowflake] def nextId(): Long synchronized { // 改成Java函数var timestamp timeGen()if (timestamp lastTimestamp) {exceptionCounter.incr(1) // 错误处理相关删log.error(clock is moving backwards. Rejecting requests until %d., lastTimestamp); // 改成System.err.printf(...)throw new InvalidSystemClock(Clock moved backwards. Refusing to generate id for %d milliseconds.format(lastTimestamp - timestamp)) // 改成RumTimeException}if (lastTimestamp timestamp) {sequence (sequence 1) sequenceMaskif (sequence 0) {timestamp tilNextMillis(lastTimestamp)}} else {sequence 0}lastTimestamp timestamp((timestamp - twepoch) timestampLeftShift) | // |(datacenterId datacenterIdShift) | // |(workerId workerIdShift) | // |sequence // |}protected def tilNextMillis(lastTimestamp: Long): Long { // 改成Java函数var timestamp timeGen()while (timestamp lastTimestamp) {timestamp timeGen()}timestamp // 加上关键字return}protected def timeGen(): Long System.currentTimeMillis() // 改成Java函数val AgentParser ([a-zA-Z][a-zA-Z\-0-9]*).r // |// |def validUseragent(useragent: String): Boolean useragent match { // |case AgentParser(_) true // |case _ false // |} // |}改出来的Java版public class IdWorker{private long workerId;private long datacenterId;private long sequence;public IdWorker(long workerId, long datacenterId, long sequence){// sanity check for workerIdif (workerId maxWorkerId || workerId 0) {throw new IllegalArgumentException(String.format(worker Id cant be greater than %d or less than 0,maxWorkerId));}if (datacenterId maxDatacenterId || datacenterId 0) {throw new IllegalArgumentException(String.format(datacenter Id cant be greater than %d or less than 0,maxDatacenterId));}System.out.printf(worker starting. timestamp left shift %d, datacenter id bits %d, worker id bits %d, sequence bits %d, workerid %d,timestampLeftShift, datacenterIdBits, workerIdBits, sequenceBits, workerId);this.workerId workerId;this.datacenterId datacenterId;this.sequence sequence;}private long twepoch 1288834974657L;private long workerIdBits 5L;private long datacenterIdBits 5L;private long maxWorkerId -1L ^ (-1L workerIdBits);private long maxDatacenterId -1L ^ (-1L datacenterIdBits);private long sequenceBits 12L;private long workerIdShift sequenceBits;private long datacenterIdShift sequenceBits workerIdBits;private long timestampLeftShift sequenceBits workerIdBits datacenterIdBits;private long sequenceMask -1L ^ (-1L sequenceBits);private long lastTimestamp -1L;public long getWorkerId(){return workerId;}public long getDatacenterId(){return datacenterId;}public long getTimestamp(){return System.currentTimeMillis();}public synchronized long nextId() {long timestamp timeGen();if (timestamp lastTimestamp) {System.err.printf(clock is moving backwards. Rejecting requests until %d., lastTimestamp);throw new RuntimeException(String.format(Clock moved backwards. Refusing to generate id for %d milliseconds,lastTimestamp - timestamp));}if (lastTimestamp timestamp) {sequence (sequence 1) sequenceMask;if (sequence 0) {timestamp tilNextMillis(lastTimestamp);}} else {sequence 0;}lastTimestamp timestamp;return ((timestamp - twepoch) timestampLeftShift) |(datacenterId datacenterIdShift) |(workerId workerIdShift) |sequence;}private long tilNextMillis(long lastTimestamp) {long timestamp timeGen();while (timestamp lastTimestamp) {timestamp timeGen();}return timestamp;}private long timeGen(){return System.currentTimeMillis();}//---------------测试---------------public static void main(String[] args) {IdWorker worker new IdWorker(1,1,1);for (int i 0; i 30; i) {System.out.println(worker.nextId());}}}代码理解上面的代码中有部分位运算的代码如sequence (sequence 1) sequenceMask;private long maxWorkerId -1L ^ (-1L workerIdBits);return ((timestamp - twepoch) timestampLeftShift) |(datacenterId datacenterIdShift) |(workerId workerIdShift) |sequence;为了能更好理解我对相关知识研究了一下。负数的二进制表示在计算机中负数的二进制是用补码来表示的。假设我是用Java中的int类型来存储数字的int类型的大小是32个二进制位(bit)即4个字节(byte)。(1 byte 8 bit)那么十进制数字3在二进制中的表示应该是这样的00000000 00000000 00000000 00000011// 3的二进制表示就是原码那数字-3在二进制中应该如何表示我们可以反过来想想因为-330在二进制运算中把-3的二进制看成未知数x来求解求解算式的二进制表示如下00000000 00000000 00000000 00000011 //3原码 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx //-3补码-----------------------------------------------00000000 00000000 00000000 00000000反推x的值3的二进制加上什么值才使结果变成00000000 00000000 00000000 0000000000000000 00000000 00000000 00000011 //3原码 11111111 11111111 11111111 11111101 //-3补码-----------------------------------------------1 00000000 00000000 00000000 00000000反推的思路是3的二进制数从最低位开始逐位加1使溢出的1不断向高位溢出直到溢出到第33位。然后由于int类型最多只能保存32个二进制位所以最高位的1溢出了剩下的32位就成了(十进制的)0。补码的意义就是可以拿补码和原码(3的二进制)相加最终加出一个“溢出的0”以上是理解的过程实际中记住公式就很容易算出来补码 反码 1补码 (原码 - 1)再取反码因此-1的二进制应该这样算00000000 00000000 00000000 00000001 //原码1的二进制11111111 11111111 11111111 11111110 //取反码1的二进制的反码11111111 11111111 11111111 11111111 //加1-1的二进制表示(补码)用位运算计算n个bit能表示的最大数值比如这样一行代码private long workerIdBits 5L;private long maxWorkerId -1L ^ (-1L workerIdBits);上面代码换成这样看方便一点long maxWorkerId -1L ^ (-1L 5L)咋一看真的看不准哪个部分先计算于是查了一下Java运算符的优先级表:所以上面那行代码中运行顺序是-1 左移 5得结果a-1 异或 along maxWorkerId -1L ^ (-1L 5L)的二进制运算过程如下-1 左移 5得结果a 11111111 11111111 11111111 11111111 //-1的二进制表示(补码)11111 11111111 11111111 11111111 11100000 //高位溢出的不要低位补011111111 11111111 11111111 11100000 //结果a-1 异或 a 11111111 11111111 11111111 11111111 //-1的二进制表示(补码)^ 11111111 11111111 11111111 11100000 //两个操作数的位中相同则为0不同则为1---------------------------------------------------------------------------00000000 00000000 00000000 00011111 //最终结果31最终结果是31二进制00000000 00000000 00000000 00011111转十进制可以这么算$$ 2^4 2^3 2^2 2^1 2^0 16 8 4 2 1 31 $$那既然现在知道算出来long maxWorkerId -1L ^ (-1L 5L)中的maxWorkerId 31有什么含义为什么要用左移5来算如果你看过概述部分请找到这段内容看看5位(bit)可以表示的最大正整数是$2^{5}-1 31$即可以用0、1、2、3、....31这32个数字来表示不同的datecenterId或workerId-1L ^ (-1L 5L)结果是31$2^{5}-1$的结果也是31所以在代码中-1L ^ (-1L 5L)的写法是利用位运算计算出5位能表示的最大正整数是多少用mask防止溢出有一段有趣的代码sequence (sequence 1) sequenceMask;分别用不同的值测试一下你就知道它怎么有趣了long seqMask -1L ^ (-1L 12L); //计算12位能耐存储的最大正整数相当于2^12-1 4095System.out.println(seqMask: seqMask);System.out.println(1L seqMask);System.out.println(2L seqMask);System.out.println(3L seqMask);System.out.println(4L seqMask);System.out.println(4095L seqMask);System.out.println(4096L seqMask);System.out.println(4097L seqMask);System.out.println(4098L seqMask);/**seqMask: 409512344095012*/这段代码通过位与运算保证计算的结果范围始终是 0-4095 用位运算汇总结果还有另外一段诡异的代码return ((timestamp - twepoch) timestampLeftShift) |(datacenterId datacenterIdShift) |(workerId workerIdShift) |sequence;为了弄清楚这段代码首先 需要计算一下相关的值private long twepoch 1288834974657L; //起始时间戳用于用当前时间戳减去这个时间戳算出偏移量private long workerIdBits 5L; //workerId占用的位数5private long datacenterIdBits 5L; //datacenterId占用的位数5private long maxWorkerId -1L ^ (-1L workerIdBits); // workerId可以使用的最大数值31private long maxDatacenterId -1L ^ (-1L datacenterIdBits); // datacenterId可以使用的最大数值31private long sequenceBits 12L;//序列号占用的位数12private long workerIdShift sequenceBits; // 12private long datacenterIdShift sequenceBits workerIdBits; // 125 17private long timestampLeftShift sequenceBits workerIdBits datacenterIdBits; // 1255 22private long sequenceMask -1L ^ (-1L sequenceBits);//4095private long lastTimestamp -1L;其次 写个测试把参数都写死并运行打印信息方便后面来核对计算结果//---------------测试---------------public static void main(String[] args) {long timestamp 1505914988849L;long twepoch 1288834974657L;long datacenterId 17L;long workerId 25L;long sequence 0L;System.out.printf(\ntimestamp: %d \n,timestamp);System.out.printf(twepoch: %d \n,twepoch);System.out.printf(datacenterId: %d \n,datacenterId);System.out.printf(workerId: %d \n,workerId);System.out.printf(sequence: %d \n,sequence);System.out.println();System.out.printf((timestamp - twepoch): %d \n,(timestamp - twepoch));System.out.printf(((timestamp - twepoch) 22L): %d \n,((timestamp - twepoch) 22L));System.out.printf((datacenterId 17L): %d \n ,(datacenterId 17L));System.out.printf((workerId 12L): %d \n,(workerId 12L));System.out.printf(sequence: %d \n,sequence);long result ((timestamp - twepoch) 22L) |(datacenterId 17L) |(workerId 12L) |sequence;System.out.println(result);}/** 打印信息timestamp: 1505914988849twepoch: 1288834974657datacenterId: 17workerId: 25sequence: 0(timestamp - twepoch): 217080014192((timestamp - twepoch) 22L): 910499571845562368(datacenterId 17L): 2228224(workerId 12L): 102400sequence: 0910499571847892992*/代入位移的值得之后就是这样return ((timestamp - 1288834974657) 22) |(datacenterId 17) |(workerId 12) |sequence;对于尚未知道的值我们可以先看看概述 中对SnowFlake结构的解释再代入在合法范围的值(windows系统可以用计算器方便计算这些值的二进制)来了解计算的过程。当然由于我的测试代码已经把这些值写死了那直接用这些值来手工验证计算结果即可long timestamp 1505914988849L;long twepoch 1288834974657L;long datacenterId 17L;long workerId 25L;long sequence 0L;设timestamp 1505914988849twepoch 12888349746571505914988849 - 1288834974657 217080014192 (timestamp相对于起始时间的毫秒偏移量)其(a)二进制左移22位计算过程如下|00000000 00000000 000000|00 00110010 10001010 11111010 00100101 01110000 // a 21708001419200001100 10100010 10111110 10001001 01011100 00|000000 00000000 00000000 // a左移22位后的值(la)|设datacenterId 17其(b)二进制左移17位计算过程如下|00000000 00000000 0|0000000 00000000 00000000 00000000 00000000 00010001 // b 1700000000 00000000 00000000 00000000 00000000 0010001|0 00000000 00000000 // b左移17位后的值(lb)|设workerId 25其(c)二进制左移12位计算过程如下|00000000 0000|0000 00000000 00000000 00000000 00000000 00000000 00011001 // c 2500000000 00000000 00000000 00000000 00000000 00000001 1001|0000 00000000 // c左移12位后的值(lc)|设sequence 0其二进制如下00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 // sequence 0现在知道了每个部分左移后的值(la,lb,lc)代码可以简化成下面这样去理解return ((timestamp - 1288834974657) 22) |(datacenterId 17) |(workerId 12) |sequence;-----------------------------||简化\|/-----------------------------return (la) |(lb) |(lc) |sequence;上面的管道符号|在Java中也是一个位运算符。其含义是x的第n位和y的第n位 只要有一个是1则结果的第n位也为1否则为0因此我们对四个数的位或运算如下1 | 41 | 5 | 5 | 120|0001100 10100010 10111110 10001001 01011100 00|00000|0 0000|0000 00000000 //la0|0000000 00000000 00000000 00000000 00000000 00|10001|0 0000|0000 00000000 //lb0|0000000 00000000 00000000 00000000 00000000 00|00000|1 1001|0000 00000000 //lcor 0|0000000 00000000 00000000 00000000 00000000 00|00000|0 0000|0000 00000000 //sequence------------------------------------------------------------------------------------------0|0001100 10100010 10111110 10001001 01011100 00|10001|1 1001|0000 00000000 //结果910499571847892992结果计算过程1) 从至左列出1出现的下标(从0开始算)0000 1 1 00 1 0 1 000 1 0 1 0 1 1 1 1 1 0 1 000 1 00 1 0 1 0 1 1 1 0000 1 000 1 1 1 00 1 0000 0000 000059 58 55 53 49 47 45 44 43 42 41 39 35 32 30 28 27 26 21 17 16 15 122) 各个下标作为2的幂数来计算并相加$ 2^{59}2^{58}2^{55}2^{53}2^{49}2^{47}2^{45}2^{44}2^{43}2^{42}2^{41}2^{39}2^{35}2^{32}2^{30}2^{28}2^{27}2^{26}2^{21}2^{17}2^{16}2^{15}2^{2} $2^59} : 5764607523034234882^58} : 2882303761517117442^55} : 360287970189639682^53} : 90071992547409922^49} : 5629499534213122^47} : 1407374883553282^45} : 351843720888322^44} : 175921860444162^43} : 87960930222082^42} : 43980465111042^41} : 21990232555522^39} : 5497558138882^35} : 343597383682^32} : 42949672962^30} : 10737418242^28} : 2684354562^27} : 1342177282^26} : 671088642^21} : 20971522^17} : 1310722^16} : 655362^15} : 32768 2^12} : 4096----------------------------------------910499571847892992计算截图跟测试程序打印出来的结果一样手工验证完毕观察1 | 41 | 5 | 5 | 120|0001100 10100010 10111110 10001001 01011100 00| | | //la0| |10001| | //lb0| | |1 1001| //lcor 0| | | |0000 00000000 //sequence------------------------------------------------------------------------------------------0|0001100 10100010 10111110 10001001 01011100 00|10001|1 1001|0000 00000000 //结果910499571847892992上面的64位我按1、41、5、5、12的位数截开了方便观察。纵向观察发现:在41位那一段除了la一行有值其它行(lb、lc、sequence)都是0(我爸其它)在左起第一个5位那一段除了lb一行有值其它行都是0在左起第二个5位那一段除了lc一行有值其它行都是0按照这规律如果sequence是0以外的其它值12位那段也会有值的其它行都是0横向观察发现:在la行由于左移了5512位5、5、12这三段都补0了所以la行除了41那段外其它肯定都是0同理lb、lc、sequnece行也以此类推正因为左移的操作使四个不同的值移到了SnowFlake理论上相应的位置然后四行做位或运算(只要有1结果就是1)就把4段的二进制数合并成一个二进制数。结论所以在这段代码中return ((timestamp - 1288834974657) 22) |(datacenterId 17) |(workerId 12) |sequence;左移运算是为了将数值移动到对应的段(41、5、512那段因为本来就在最右因此不用左移)。然后对每个左移后的值(la、lb、lc、sequence)做位或运算是为了把各个短的数据合并起来合并成一个二进制数。最后转换成10进制就是最终生成的id扩展在理解了这个算法之后其实还有一些扩展的事情可以做根据自己业务修改每个位段存储的信息。算法是通用的可以根据自己需求适当调整每段的大小以及存储的信息。解密id由于id的每段都保存了特定的信息所以拿到一个id应该可以尝试反推出原始的每个段的信息。反推出的信息可以帮助我们分析。比如作为订单可以知道该订单的生成日期负责处理的数据中心等等。