【正文】
at eliminates the possibility of duplicates! Clearly, you39。t permit crossshard querying, which means you have to go to extra lengths if you want to leverage two sets of data from different shards. (Interestingly, Amazon39。s likely that an identical primary key will show up across a set of databases. It39。ll need to map out your sharding strategy before you begin. Both primary keys and crossshard queries play a major role when sharding, mainly by defining what you can39。t support regular partitioning. The moary cost is also potentially lower. Sharding and strategy Like most technologies, sharding does entail some tradeoffs. Because sharding isn39。t resolve the reliability, or lack thereof, of your hardware. Thus, various smart people started looking for new ways to scale. Sharding is essentially partitioning at the database level: rather than divide a table39。s more, most partitioning implementations store data on the same physical machine, so you39。t always available (MySQL didn39。s now possible to assemble, test, run, and maintain Java applications quickly and inexpensively. In this series, Andrew Glover explores the spectrum of technologies and tools that make this new Java development paradigm possible. Sharding at a glance Database partitioning is an inherently relational process of dividing a table39。 in fact, coding for Hibernate Shards is the easy part. The real work is figuring out how and what you39。ll use this familiar example to introduce a practical sharding strategy, then implement it in Hibernate Shards. Note that the brunt of the work related to sharding isn39。t have to specifically map your POJOs to shards — you map them as you would any normal relational database in the Hibernate way. Hibernate Shards manages the lowlevel sharding stuff for you. So far in this series, I39。s Bigtable), NoSQL is a patently nonrelational approach. For the developer who prefers the ACIDity and solid structure of a relational database, or the project that requires it, sharding could be an exciting alternative. Sharding, an offshoot of database partitioning, isn39。 Reader174。s one way that relational systems can meet the demands of big data. For some shops, sharding means being able to keep a trusted RDBMS in place without sacrificing data scalability or system performance. In this installment of the Java development series, find out when sharding works, and when it doesn39。 外文原文資料信息 [1] 外文原文作者: [2] 外文原文所在書名或論文題目: [3] 外文原文來源: 出版社或刊物名稱、出版時(shí)間或刊號(hào)、譯文部分所在頁碼: 網(wǎng)頁地址: 二、外文原文資料: Java development : Sharding with Hibernate Shards Horizontal scalability for relational databases Andrew Glover, Author and developer, Beacon50 Summary: Sharding isn39。 配置好 Hibernate Shards 工作所需的三個(gè)接 口后,我們就可以對切分示例應(yīng)用程序的第二步進(jìn)行實(shí)現(xiàn)了。因此 Hibernate Shards 創(chuàng)造性地提供一個(gè) ID 生成器,名為 ShardedUUIDGenerator,它可以靈活地將切分 ID 信息嵌入到 UUID 中。 正如我之前所說的 ,sharding 迫使你對基本有敏銳的鑰匙 ,你可以管理之行。 隨著比賽應(yīng)用的增長,我所使用的 邏輯可能不靈活 ,但這行得通為執(zhí)行本示范 ! ShardResolutionStrategy 要找這個(gè)對象的關(guān)鍵 ,Hibernate Stards 需要一個(gè)辦法決定先 切分那個(gè) 。) 如果還保存了其他域?qū)ο?,現(xiàn)在將引發(fā)一個(gè)異常。 如果 Runner 被創(chuàng)建時(shí)參加了多場 Races,這名 Runner 將被持久化到尋找到的首場 Race 所屬的切分中。 如果持久化一個(gè) Runner 或其他對 象,情況會(huì)稍微復(fù)雜一些。 } } } 正如你可以看到 清單 1,如果該對象被保存的一 場 Race,那么它的距離確定,因此,而且(因此)選擇了一個(gè)切分。 } } private ShardId determineShardId(double distance){ if (distance ) { return new ShardId(1)。 } return (dist)。 for (Race rce : ()) { dist = ()。 if (().isEmpty()) { throw new IllegalArgumentException(runners must have at least one race)。 return (())。 import 。 清單 1。(我將稍候在 Race 對象中展示。 對于賽跑應(yīng)用程序,我需要提供根據(jù)比賽距離進(jìn)行切分的行為。因此,你必須實(shí)現(xiàn)這個(gè)接口和代碼邏輯的分片。 我們將很快配置。因此, Hibernate Shards 提供了兩種極具創(chuàng)意的邏輯實(shí)現(xiàn)方法:一種方法是根據(jù)序列機(jī)制(一次一個(gè))對切分 進(jìn)行查詢,直到獲得答案為止;另一種方法是并行訪問策略,這種方法使用一個(gè)線程模型一次對所有切分進(jìn)行查詢。 ShardAccessStrategy 執(zhí)行查詢時(shí), Hibernate Shards 需要一個(gè)決定首個(gè)切分、第二個(gè)切分及后續(xù)切分的機(jī)制。這些接 口,你必須執(zhí)行,盡管在某些情況下,你可以使用默認(rèn)的 。 唯一的缺點(diǎn)是, Hibernate 的碎片需要一些具體資料和你的行為。 為了簡便起見,我將創(chuàng)建兩個(gè)切分:一個(gè)用于 10 英里以下的比賽;另一個(gè)用于 10 英里以上的比賽。 請注意:在進(jìn)行上述決定時(shí),我已經(jīng)接受了一個(gè)妥協(xié):如果一個(gè)參賽者參加了不止一項(xiàng)比賽,他們分屬不同的切分,那該怎么辦呢? Hibernate Shards ( 像大多數(shù)切分實(shí)現(xiàn)一樣)不支持跨切分連接。因此,比賽是域的根。 回到比賽 —— 使用切分 ! 現(xiàn)在讓我們回到我經(jīng)常提到的賽跑應(yīng)用程序示例中,我可以根據(jù)比賽或參賽者進(jìn)行切分。您的碎片戰(zhàn)略應(yīng)當(dāng)指出,納入均勻分布的碎片之間的所有數(shù)據(jù)的一些方法。 對客戶來說,你可以根據(jù)位置碎片(歐洲,亞洲,非洲等),或者你可以在別的東西的碎片。在一個(gè)電子商務(wù)系統(tǒng)的情況下,主節(jié)點(diǎn)可以是一個(gè)命令或一個(gè)客戶。 一個(gè)策略的例子 由于分片結(jié)合你到一個(gè)線性數(shù)