圖解Janusgraph系列-分佈式id生成策略分析
{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"JanusGraph - 分佈式id的生成策略"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"大家好,我是洋仔,JanusGraph圖解系列文章,"},{"type":"codeinline","content":[{"type":"text","text":"實時更新"}]},{"type":"text","text":"~"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本次更新時間:2020-9-1"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"文章爲作者跟蹤源碼和查看官方文檔整理,如有任何問題,請聯繫我或在評論區指出,感激不盡!"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"**"},{"type":"codeinline","content":[{"type":"text","text":"圖數據庫網上資源太少,評論區評論 or 私信我,邀你加入“圖庫交流微信羣”,一起交流學習!"}]},{"type":"text","text":"**"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"源碼分析相關:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://liyangyang.blog.csdn.net/article/details/106674499","title":""},"content":[{"type":"text","text":"源碼圖庫-一文搞定janusgraph圖數據庫的本地源碼編譯(janusgraph source code compile)"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖解圖庫JanusGraph系列-一文知曉導入數據流程(待發布)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖解圖庫JanusGraph系列-簡要分析查詢讀數據流程(待發布)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖解圖庫JanusGraph系列-一文知曉鎖機制(本地鎖+分佈式鎖)(待發布)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s?__biz=MzAwODkwMDk4OQ==&mid=2247483936&idx=1&sn=1b0ebe5699ee267d4b0360c90c937492&chksm=9b669a32ac111324e66af490a24478b81ad5221a88af61897353a6f4d80ff6005b60fbbb8490&scene=126&sessionid=1598925790&key=4598b5ee8f6c495005e73b5167cd30412733226c9d6ce36","title":""},"content":[{"type":"text","text":"圖解圖庫JanusGraph系列-一文知曉分佈式id生成策略"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖解圖庫JanusGraph系列-一文知曉圖庫存儲分區策略(待發布)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"存儲結構相關:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s?_biz=MzAwODkwMDk4OQ==&mid=2247483894&idx=1&sn=0d7b98d8d7abf86bfacf8c86b694651d&chksm=9b6699e4ac1110f2626789d78aaf617dc02b7a9cdad320c5273172a6fa3a21d8f40d63958461&token=2053731774&lang=zhCN#rd","title":""},"content":[{"type":"text","text":"圖解圖庫JanusGraph系列-一文知曉圖數據底層存儲結構"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"其他:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://mp.weixin.qq.com/s?_biz=MzAwODkwMDk4OQ==&mid=2247483830&idx=1&sn=71ad0d9e0d5868ae15011b7744c0fe8f&chksm=9b6699a4ac1110b294487a6987be5392a5093405a7a40f58d4bca697a18d64000db1aeda0a6f&token=1631136587&lang=zhCN#rd","title":""},"content":[{"type":"text","text":"解惑圖數據庫!你知道什麼是圖數據庫嗎?"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"圖解圖庫JanusGraph系列-官方測試圖:諸神之圖分析(待發布)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"**"},{"type":"codeinline","content":[{"type":"text","marks":[{"type":"strong"}],"text":"源碼分析相關可查看github(求star~~)"}]},{"type":"text","text":"**: "},{"type":"link","attrs":{"href":"https://github.com/YYDreamer/janusgraph","title":""},"content":[{"type":"text","text":"https://github.com/YYDreamer/janusgraph"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下述流程高清大圖地址:"},{"type":"link","attrs":{"href":"https://www.processon.com/view/link/5f471b2e7d9c086b9903b629","title":""},"content":[{"type":"text","text":"https://www.processon.com/view/link/5f471b2e7d9c086b9903b629"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"版本:JanusGraph-0.5.2"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "},{"type":"text","marks":[{"type":"strong"}],"text":"轉載文章請保留以下聲明:"}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作者:洋仔聊編程"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微信公衆號:匠心Java"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原文地址:"},{"type":"link","attrs":{"href":"https://xie.infoq.cn/article/20cfc44ff85cf6bf326f3f6f7","title":""},"content":[{"type":"text","text":"https://xie.infoq.cn/article/20cfc44ff85cf6bf326f3f6f7"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"正文"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在介紹JanusGraph的分佈式ID生成策略之前,我們來簡單分析一下"},{"type":"codeinline","content":[{"type":"text","text":"分佈式ID"}]},{"type":"text","text":"應該滿足哪些特徵?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"全局唯一"},{"type":"text","text":":必須保證ID是分佈式環境中全局性唯一的,這是基本要求"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"高性能"},{"type":"text","text":":高可用低延時,ID生成響應快;否則可能會成爲業務瓶頸"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"高可用"},{"type":"text","text":":提供分佈式id的生成的服務要保證高可用,不能隨隨便便就掛掉了,會對業務產生影響"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"趨勢遞增"},{"type":"text","text":":主要看業務場景,類似於圖存儲中節點的唯一id就儘量保持趨勢遞增;但是如果類似於電商訂單就儘量不要趨勢遞增,因爲趨勢遞增會被惡意估算出當天的訂單量和成交量,泄漏公司信息"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"接入方便"},{"type":"text","text":":如果是中間件,要秉着拿來即用的設計原則,在系統設計和實現上要儘可能的簡單"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"一:常用分佈式id生成策略"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當前"},{"type":"codeinline","content":[{"type":"text","text":"常用的"}]},{"type":"text","text":"分佈式id的生成策略主要分爲以下四種:"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"UUID"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"數據庫+號段模式(優化:數據庫+號段+雙buffer)"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"基於Redis實現"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"雪花算法(SnowFlake)"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"還有一些其他的比如:基於數據庫自增id、數據庫多主模式等,這些在小併發的情況下可以使用,大併發的情況下就不太ok了"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"市面上有一些生成分佈式id的開源組件,包括滴滴基於"},{"type":"codeinline","content":[{"type":"text","text":"數據庫+號段"}]},{"type":"text","text":"實現的"},{"type":"codeinline","content":[{"type":"text","text":"TinyID"}]},{"type":"text","text":" 、百度基於"},{"type":"codeinline","content":[{"type":"text","text":"SnowFlake"}]},{"type":"text","text":"的"},{"type":"codeinline","content":[{"type":"text","text":"Uidgenerator"}]},{"type":"text","text":"、美團支持"},{"type":"codeinline","content":[{"type":"text","text":"號段"}]},{"type":"text","text":"和"},{"type":"codeinline","content":[{"type":"text","text":"SnowFlake"}]},{"type":"text","text":"的"},{"type":"codeinline","content":[{"type":"text","text":"Leaf"}]},{"type":"text","text":"等"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那麼,在JanusGraph中分佈式id的生成是採用的什麼方式呢? "}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"二:JanusGraph的分佈式id策略"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在JanusGraph中,分佈式id的生成採用的是"},{"type":"codeinline","content":[{"type":"text","text":"數據庫+號段+雙buffer優化"}]},{"type":"text","text":"的模式; 下面我們來具體分析一下:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分佈式id生成使用的數據庫就是JanusGraph當前使用的第三方存儲後端,這裏我們以使用的存儲後端"},{"type":"codeinline","content":[{"type":"text","text":"Hbase"}]},{"type":"text","text":"爲例;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"JanusGraph分佈式id生成所需元數據存儲位置:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在Hbase中有"},{"type":"codeinline","content":[{"type":"text","text":"column family 列族"}]},{"type":"text","text":"的概念; JanusGraph在初始化Hbase表時默認創建了9大列族,用於存儲不同的數據, 具體看《圖解圖庫JanusGraph系列-一文知曉圖數據底層存儲結構》;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其中有一個列族"},{"type":"codeinline","content":[{"type":"text","text":"janusgraph_ids"}]},{"type":"text","text":"簡寫爲"},{"type":"codeinline","content":[{"type":"text","text":"i"}]},{"type":"text","text":"這個列族,主要存儲的就是JanusGraph分佈式id生成所需要的元數據!"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"JanusGraph的分佈式id的組成結構:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"\t // 源碼中有一句話體現\n /*\t\t--- JanusGraphElement id bit format ---\n * [ 0 | count | partition | ID padding (if any) ]\n */"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"主要分爲4部分:"},{"type":"codeinline","content":[{"type":"text","text":"0、count、partition、ID padding(每個類型是固定值)"}]},{"type":"text","text":";"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其實這4部分的順序在序列化爲二進制數據時,順序會有所改變;這裏只是標明瞭id的組成部分!"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上述部分的"},{"type":"codeinline","content":[{"type":"text","text":"partition"}]},{"type":"text","text":" + "},{"type":"codeinline","content":[{"type":"text","text":"count"}]},{"type":"text","text":"來保證分佈式節點的唯一性;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"partition id:分區id值,JanusGraph默認分了32個邏輯分區;節點分到哪個分區採用的是"},{"type":"codeinline","content":[{"type":"text","text":"隨機分配"}]},{"type":"text","text":";"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"count:每個partition都有對應的一個count範圍:0-2的55次冪;JanusGraph每次拉取一部分的範圍作爲節點的count取值;JanusGraph保證了針對相同的partition,不會重複獲取同一個count值!"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"保證count在partition維度保持全局唯一性,就保證了生成的最終id的全局唯一性!!"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"*則分佈式id的唯一性保證,就在於"},{"type":"codeinline","content":[{"type":"text","text":"count"}]},{"type":"text","text":"基於"},{"type":"codeinline","content":[{"type":"text","text":"partition"}]},{"type":"text","text":"維度的唯一性!下面我們的分析也是着重在"},{"type":"codeinline","content":[{"type":"text","text":"count"}]},{"type":"text","text":"的獲取!* "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"JanusGraph分佈式id生成的主要邏輯流程如下圖所示:(推薦結合源碼分析觀看!)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分析過程中有一個概念爲"},{"type":"codeinline","content":[{"type":"text","text":"id block"}]},{"type":"text","text":":指當前獲取的號段範圍"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/29/29288622004088ff0034a30a0be8d1cd.png","alt":"在這裏插入圖片描述","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"JanusGraph主要使用`"},{"type":"codeinline","content":[{"type":"text","text":"PartitionIDPool "}]},{"type":"text","text":"類來存儲不同類型的"},{"type":"codeinline","content":[{"type":"text","text":"StandardIDPool"}]},{"type":"text","text":"; 在"},{"type":"codeinline","content":[{"type":"text","text":"StandardIDPool"}]},{"type":"text","text":"中主要包含兩個id Block:"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"current block:當前生成id使用的block"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"next block:double buffer中的另一個已經準備好的block"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"爲什麼要有兩個block呢?"},{"type":"text","text":" "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"主要是如果只有一個block的話,當我們在使用完當前的block時,需要阻塞等待區獲取下一個block,這樣便會導致分佈式id生成較長時間的阻塞等待block的獲取;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"怎麼優化上述問題呢? "},{"type":"codeinline","content":[{"type":"text","text":"double buffer"}]},{"type":"text","text":"; "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除了當前使用的block,我們再存儲一個"},{"type":"codeinline","content":[{"type":"text","text":"next block"}]},{"type":"text","text":";當正在使用的block假設已經使用了50%,觸發"},{"type":"codeinline","content":[{"type":"text","text":"next block"}]},{"type":"text","text":"的異步獲取,如上圖的藍色部分所示;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這樣當"},{"type":"codeinline","content":[{"type":"text","text":"current block"}]},{"type":"text","text":"使用完成後可以直接無延遲的切換到"},{"type":"codeinline","content":[{"type":"text","text":"next block"}]},{"type":"text","text":"如上圖中綠色部分所示; "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"在執行過程中可能會因爲一些異常導致節點id獲取失敗,則會進行重試;重試次數默認爲1000次;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":"private static final int MAX_PARTITION_RENEW_ATTEMPTS = 1000;\nfor (int attempt = 0; attempt < MAX_PARTITION_RENEW_ATTEMPTS; attempt++) {\n // 獲取id的過程\n}"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"ps:上述所說的IDPool和block是基於當前"},{"type":"codeinline","content":[{"type":"text","text":"圖實例"}]},{"type":"text","text":"維度共用的!"}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"三:源碼分析"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在JanusGraph的源碼中,主要包含兩大部分和其他的一些組件:"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Graph相關類:用於對節點、屬性、邊的操作"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Transaction相關類:用於在對數據或者Schema進行CURD時,進行事務處理"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其他一些:分佈式節點id生成類;序列化類;第三方索引操作類等等"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Graph和Transaction相關類的類圖如下所示:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c8/c8656968eb85ef0a325b3eb49314c62e.png","alt":"在這裏插入圖片描述","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分佈式id涉及到id生成的類圖如下所示:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/0f/0fcb50f0c85fac9e310ab8c78fe8f438.png","alt":"在這裏插入圖片描述","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"初始數據:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"java"},"content":[{"type":"text","text":" @Test\n public void addVertexTest(){\n List
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.