MarcF
MarcF

Reputation: 3299

Shard Balancing In Different Collections

Query regarding how chunk distribution might look in a sharded cluster that has 2 collections, that have the same 'top level' indexes and therefore shard key:

Collection one sharded by x:

{ x: 1 }

has a document structure equivalent to:

{ 
  x : integer,
  y : integer,
  z : integer
}

Collection two sharded by x:

{ x: 1 }

has a document structure equivalent to:

{ 
  x : integer,
  v : integer,
  w : integer
}

x has a cardinality of approx 100K. x is the same in both collections and a large number of documents for a given value of x in collection 1 will also have a proportional number in collection 2.

I would like to know, for the given cardinality of x, if it's likely for chunks from separate collections, containing similar ranges of x, to be on the same node? i.e. will documents with x=5 from collection 1, be on the same node as documents with x=5 from collection 2?

Upvotes: 0

Views: 166

Answers (1)

kevinadi
kevinadi

Reputation: 13815

There is no guarantee that both collections will be distributed the same way, even though x has the same cardinality on both collections (or even if x is the same field).

The balancer tries to distribute the chunks evenly across all shards. This is done without it needing to know about the actual shard key. From the balancer's point of view, there is no relation between the two collections (or between any sharded collections).

You can read about the balancer in this page: https://docs.mongodb.com/v3.2/core/sharding-balancer-administration/. Please note that there is no mention about shard keys at all in that page, only chunks.

Upvotes: 1

Related Questions