Mongo DB:使用最小/最大哈希键将块拆分为上下边界 [英] Mongo DB: Splitting Chunk with Minimum/Maximum Hashed Key as Lower/Upper Bound

查看:73
本文介绍了Mongo DB:使用最小/最大哈希键将块拆分为上下边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,答案很明显,但是如何分割带有最小/最大哈希键作为下限/上限的块?

This might be a silly question with obvious answer, but how do I split a chunk with minimum/maximum hashed key as lower/upper bound?

例如,我有一个要分割的块:

For example I have this chunk that I want to split:

{
    "_id" : "database-name.collectionName-_id_5232174760913548110",
    "lastmod" : Timestamp(5, 1),
    "lastmodEpoch" : ObjectId("5474796988a23861ead5dc60"),
    "ns" : "database-name.collectionName",
    "min" : {
        "_id" : NumberLong("5232174760913548110")
    },
    "max" : {
        "_id" : { "$maxKey" : 1 }
    },
    "shard" : "dimA"
}

我尝试用以下方式分割它:

I tried splitting it with:

db.adminCommand( {
    split: "database-name.collectionName",
    bounds: [{_id: NumberLong("5232174760913548110")}, {{_id: {"$maxKey" : 1}}}] } )

,但失败,并显示错误消息在给定的上下限中未找到任何块".

, but failed with error message "no chunk found from the given upper and lower bounds".

该命令适用于没有最大/最小关键点的块,因此我认为我不应该使用{_id: {"$maxKey" : 1}}作为上限.

The command works for chunks that are not at max/min key, so I think I'm not supposed to use {_id: {"$maxKey" : 1}} as the upper bound.

有什么主意吗?

谢谢

尼娜.

推荐答案

基本上,这与$maxKey的显示方式以及将其传递到shell中以在命令中使用它的方式有关.最简单的方法是显示一个工作示例,所以这是我的测试集合(foo.bar)的原始布局:

This is basically just about how $maxKey is displayed versus how you pass it into the shell to use it in a command. Easiest thing to do is show a working example, so here's my original layout of my test collection (foo.bar):

foo.bar
        shard key: { "_id" : "hashed" }
        chunks:
            shard0000   3
        { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("-4097713469691957209") } on : shard0000 Timestamp(1, 3) 
        { "_id" : NumberLong("-4097713469691957209") } -->> { "_id" : NumberLong("1468066378930898747") } on : shard0000 Timestamp(1, 4) 
        { "_id" : NumberLong("1468066378930898747") } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 2)

要在最后一块分割,只需执行以下操作:

To split on that last chunk just do this:

db.adminCommand( {
    split: "foo.bar",
    bounds: [{_id: NumberLong("1468066378930898747")}, {_id: MaxKey}] } )
{ "ok" : 1 }

现在,要证明它发生了,布局看起来像这样:

Now, to prove it happened the layout looks like this:

foo.bar
        shard key: { "_id" : "hashed" }
        chunks:
            shard0000   4
        { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("-4097713469691957209") } on : shard0000 Timestamp(1, 3) 
        { "_id" : NumberLong("-4097713469691957209") } -->> { "_id" : NumberLong("1468066378930898747") } on : shard0000 Timestamp(1, 4) 
        { "_id" : NumberLong("1468066378930898747") } -->> { "_id" : NumberLong("5350365356528563634") } on : shard0000 Timestamp(1, 5) 
        { "_id" : NumberLong("5350365356528563634") } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 6) 

这篇关于Mongo DB:使用最小/最大哈希键将块拆分为上下边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆