sharding - Relation between shard keys and chunks in MongoDB sharded cluster? -


i can't understand shard key concept in mongodb sharded cluster, i've started learning mongodb.

citing mongodb documentation:

a chunk contiguous range of shard key values assigned particular shard. when grow beyond configured chunk size, mongos splits chunk 2 chunks.

it seems chuck size related particular shard, not cluster itself. right?

speaking cardinality of shard key:

consider use of state field shard key:

the state key’s value holds state given address document. field has low cardinality documents have same value in state field must reside on same shard, if particular state’s chunk exceeds maximum chunk size.

since there limited number of possible values state field, mongodb may distribute data unevenly among small number of fixed chunks.

my question how shard key relates chunk size.

it seems me that, having 2 shard servers, wouldn't possible distribute data because same value in state field must reside on same shard. 3 documents states arizona, indiana , maine, how data distributed among 2 shards?

in order understand answer question need understand range based partitioning. if have n documents partitioned chunks - way split points determined based on shard key.

with shard key being field in document, possible values of shard key considered , documents (logically) split chunks/ranges, based on value each document's shard key is.

in example there 50 possible values "state" (okay, more 52) @ there can 52 chunks. default chunk size 64mb. imagine sharding collection ten million documents 1k each. each chunk should not contain more 65k documents. ten million documents should split more 150 chunks, have 52 distinct values shard key! chunks going large. why problem? well, in order auto-balance chunk among shards system needs migrate chunks between shards , if chunk big, can't moved. , since can't split, you'll stuck unbalanced cluster.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -