AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题

问题[sharding](dba)

Martin Hope
Raghu
Asked: 2019-12-30 08:26:34 +0800 CST

Ranged Sharding - 形成十六进制字符串范围背后的逻辑

  • 0

我有一个分片集合,其中分片键是一个名为“uuid”的字段。该字段的值是字符串类型,表示十六进制值,即十六进制字符串。对于每个文档,这个“uuid”字段是唯一的。

数据由 MongoDB 自动划分为块。我无法弄清楚 MongoDB 是如何将此十六进制字符串划分为连续范围的。没有文件可以解释 Mongo 如何形成这些范围

你能帮我理解这些范围是如何形成的吗?

作为示例,我插入了 3025357 个具有上述十六进制值的文档。与它们相关的块和范围是,

{    
    "_id" : "database.sha_shard-uuid_MinKey",
    "lastmod" : Timestamp(2, 0),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : { "$minKey" : 1 }
    },
    "max" : {
        "uuid" : "000043c071f23fc889275f77f950c649faac92e0"
    },
    "shard" : "shardRpSet2",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577632842, 37),
            "shard" : "shardRpSet2"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"5b935a89d91977490d04f740a86bccc2b3cc2bfb\"",
    "lastmod" : Timestamp(3, 5),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "5b935a89d91977490d04f740a86bccc2b3cc2bfb"
    },
    "max" : {
        "uuid" : "7a25fa7aa3a86ed259f646d7890db370e8b43ae7"
    },
    "shard" : "shardRpSet1",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577632856, 21509),
            "shard" : "shardRpSet1"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"7a25fa7aa3a86ed259f646d7890db370e8b43ae7\"",
    "lastmod" : Timestamp(3, 6),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "7a25fa7aa3a86ed259f646d7890db370e8b43ae7"
    },
    "max" : {
        "uuid" : "810b573464d4894fc40b428ec82ec54d9a681bf6"
    },
    "shard" : "shardRpSet1",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577632856, 21509),
            "shard" : "shardRpSet1"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"000043c071f23fc889275f77f950c649faac92e0\"",
    "lastmod" : Timestamp(4, 0),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "000043c071f23fc889275f77f950c649faac92e0"
    },
    "max" : {
        "uuid" : "1e8421c5d4f3eb45a82c2785bccc81fa7abfbfc7"
    },
    "shard" : "shardRpSet2",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577635896, 15268),
            "shard" : "shardRpSet2"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"1e8421c5d4f3eb45a82c2785bccc81fa7abfbfc7\"",
    "lastmod" : Timestamp(5, 0),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "1e8421c5d4f3eb45a82c2785bccc81fa7abfbfc7"
    },
    "max" : {
        "uuid" : "3d165990d2969bbaf79b6b0d790080b46ca5f056"
    },
    "shard" : "shardRpSet",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577635906, 26457),
            "shard" : "shardRpSet"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"3d165990d2969bbaf79b6b0d790080b46ca5f056\"",
    "lastmod" : Timestamp(5, 1),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "3d165990d2969bbaf79b6b0d790080b46ca5f056"
    },
    "max" : {
        "uuid" : "5b935a89d91977490d04f740a86bccc2b3cc2bfb"
    },
    "shard" : "shardRpSet1",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577632856, 21509),
            "shard" : "shardRpSet1"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"c1788722a31a5a5a5caa00816ad85aeeda26e581\"",
    "lastmod" : Timestamp(5, 2),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "c1788722a31a5a5a5caa00816ad85aeeda26e581"
    },
    "max" : {
        "uuid" : "dcbd245e03d425aa14a85b51befde274856fc5f3"
    },
    "shard" : "shardRpSet",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577630416, 3),
            "shard" : "shardRpSet"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"dcbd245e03d425aa14a85b51befde274856fc5f3\"",
    "lastmod" : Timestamp(5, 3),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "dcbd245e03d425aa14a85b51befde274856fc5f3"
    },
    "max" : {
        "uuid" : "fffff8c5e160711fb48f0d38ce01a98880e869e2"
    },
    "shard" : "shardRpSet",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577630416, 3),
            "shard" : "shardRpSet"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"fffff8c5e160711fb48f0d38ce01a98880e869e2\"",
    "lastmod" : Timestamp(6, 0),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "fffff8c5e160711fb48f0d38ce01a98880e869e2"
    },
    "max" : {
        "uuid" : { "$maxKey" : 1 }
    },
    "shard" : "shardRpSet2",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577636268, 67),
            "shard" : "shardRpSet2"
        }
    ]
},{
    "_id" : "database.sha_shard-uuid_\"810b573464d4894fc40b428ec82ec54d9a681bf6\"",
    "lastmod" : Timestamp(6, 1),
    "lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
    "ns" : "database.sha_shard",
    "min" : {
        "uuid" : "810b573464d4894fc40b428ec82ec54d9a681bf6"
    },
    "max" : {
        "uuid" : "c1788722a31a5a5a5caa00816ad85aeeda26e581"
    },
    "shard" : "shardRpSet",
    "history" : [ 
        {
            "validAfter" : Timestamp(1577630416, 3),
            "shard" : "shardRpSet"
        }
    ]
}
mongodb sharding
  • 1 个回答
  • 263 Views
Martin Hope
Channa
Asked: 2019-11-26 03:12:16 +0800 CST

FDW 在 postgres 中的使用

  • 0

我需要创建一个序列,并且需要将序列用于 2 个单独服务器上的 2 个以上数据库的自动增量 ID。我指的是下面的文档(出于测试目的):https ://paquier.xyz/postgresql-2/global-sequences-with-postgres_fdw-and-postgres-core/

我已按照以下步骤操作:

    Server 1: 
CREATE DATABASE
postgres=# \c a1
You are now connected to database "a1" as user "postgres".
a1=# CREATE SEQUENCE seq;
CREATE SEQUENCE
a1=# CREATE VIEW seq_view AS SELECT nextval('seq') as a;
CREATE VIEW
a1=# \c postgres
You are now connected to database "postgres" as user "postgres".

postgres=# create database a2;
 CREATE DATABASE
 postgres=# \c a2;
You are now connected to database "a2" as user "postgres".
a2=# CREATE EXTENSION postgres_fdw;
CREATE EXTENSION
a2=# CREATE SERVER postgres_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS
a2-# (host '192.168.xx.xxx', port '5432', dbname 'a1');
CREATE SERVER
a2=# CREATE USER MAPPING FOR PUBLIC SERVER postgres_server OPTIONS (password 
'');
CREATE USER MAPPING
a2=# CREATE FOREIGN TABLE foreign_seq_table (a bigint) SERVER
a2-# postgres_server
a2-# OPTIONS (table_name 'seq_view');
CREATE FOREIGN TABLE
a2=# select * from foreign_seq_table;
 a
---
 1
(1 row)

a2=# select * from foreign_seq_table;
a
---
2
(1 row)

从上面的示例可以看出,它在同一台服务器上的 2 个数据库上正常工作。但是,当我继续使用另一台服务器时,我在那里执行了以下步骤:

    postgres=# create database kbc;
CREATE DATABASE
 postgres=# \c kbc
You are now connected to database "kbc" as user "postgres".
kbc=#  CREATE EXTENSION postgres_fdw;
CREATE EXTENSION
kbc=# CREATE SERVER postgres_server FOREIGN DATA WRAPPER postgres_fdw 
OPTIONS
kbc-# (host '192.168.xx.xxx', port '5432', dbname 'a1');
CREATE SERVER
kbc=# CREATE USER MAPPING FOR PUBLIC SERVER postgres_server OPTIONS 
(password '');
CREATE USER MAPPING
kbc=#
kbc=# CREATE FOREIGN TABLE foreign_seq_table (a bigint) SERVER 
postgres_server OPTIONS (table_name 'seq_view');
  CREATE FOREIGN TABLE
 kbc=# select * from foreign_seq_table;
  ERROR:  could not connect to server "postgres_server"
    DETAIL:  fe_sendauth: no password supplied

我终于收到了错误。我在这里缺少什么/任何步骤。我可以从新服务器(我想在其中使用该序列)轻松 ping 到旧服务器(我在其中创建序列)。两台服务器上的 pg_hba.conf 文件设置 -> 那里的条目是 md5 或仅信任。我需要添加到配置文件中的任何其他条目吗?任何跨不同服务器的 fdw 建议文档也将有所帮助。

提前致谢!

注意:由于某些应用程序要求,我不能使用 UUID。这就是我们需要一个自动递增数字列的原因。它选择最高的 id 值。

postgresql sharding
  • 1 个回答
  • 611 Views
Martin Hope
TommyBs
Asked: 2019-10-03 06:45:19 +0800 CST

PostgreSQL 自动递增到一定数量然后重置分片

  • 0

我最近读了一篇关于 Instgram 过去如何分片他们的 ID 的文章,他们使用一个独特的函数在他们的服务器上生成 ID https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c

但这让我很好奇是否可以将一个分片分配给特定用户而不是每个项目,以及它的性能如何。特别是在大型网站中。

因此,类似于以下的功能是否是一种有效的方法。

假设专用数据库上的用户表纯粹供用户使用。

用户-UID-名称-shardId

其中 shardId 是通过一个从 1 开始的函数计算的,对于每个新的插入,它都会递增 - 对于这个例子,最多为 n(比如 2048)。然后重置为 1。几乎充当循环法以在分片之间分发用户数据。

这种功能是否会对性能产生严重影响,尤其是在高负载期间?由于序列列只是从序列中选择一个 nextval,不是吗?这只是一个额外的步骤,一旦达到 n 就重置一个序列。还是我找错了树?

postgresql sharding
  • 1 个回答
  • 145 Views
Martin Hope
user3489820
Asked: 2019-09-11 02:06:53 +0800 CST

MongoDB使用相同的分片键对多个集合进行分片

  • 2

让我们想象一下我有两个 mongodb 分片集合:喜欢和评论。

两个集合都是分片的,两个集合都将 userId 作为分片键。

让我们想象一下,喜欢的收藏量很大,而评论的收藏量很小。我总共有 10 个分片,我们将它们命名为分片 A 到分片 G。

我可以假设如果某个特定用户的点赞在分片 A 中,那么他的评论也会在分片 A 中吗?

所以我想要实现的是将任何特定用户的数据放在同一个分片中。其他用户的点赞可能在 shard C 中,那么他的评论也应该在 shard C 中。

是否可以配置 MongoDB?(或者这是它默认的工作方式?)

mongodb sharding
  • 1 个回答
  • 666 Views
Martin Hope
Matthieu Brucher
Asked: 2019-07-23 08:38:53 +0800 CST

通过空间键和日期对 MongoDB 实例进行分片

  • 0

这可能比其他任何建议都更重要,但我正在设计一个应用程序,该应用程序存储在具有 2dsphere 索引并且它们也有日期(+时间)的表对象中,它们都是我查询的一部分正在检索其中一些对象。

这个数据库必须被分片,所以根据空间键分片听起来像是第一步。基本上,这个索引将成为分片键的一部分。另一个关键应该是时间,我很确定散列时间是不够的,因为查询正在寻找对象的日期间隔。所以散列将强制访问所有块(具有适当的空间约束),这是我不想要的。

所以我的问题是知道这是否可行,以及除非我手动要求,否则 mongodb 是否足够聪明,不会根据空间键进行拆分?

mongodb sharding
  • 1 个回答
  • 1008 Views
Martin Hope
gertvdijk
Asked: 2019-07-09 07:03:47 +0800 CST

如何让 PostgreSQL FDW 将 LIMIT 下推到(单个)后端服务器?

  • 3

我已经使用下表设置了一个 PostgreSQL FDW 服务器,由user_id四个以上的服务器分片:

CREATE TABLE my_big_table
(
    user_id bigint NOT NULL,
    serial bigint NOT NULL,         -- external, incrementing only
    some_object_id bigint NOT NULL,
    timestamp_ns bigint NOT NULL,
    object_type smallint NOT NULL,
    other_type smallint NOT NULL,
    data bytea
) PARTITION BY HASH (user_id) ;
CREATE SERVER shardA
    FOREIGN DATA WRAPPER postgres_fdw
    OPTIONS (host '192.168.200.11', port '5432', dbname 'postgres', fetch_size '10000');
 .
 .
 .
CREATE SERVER shardD
    FOREIGN DATA WRAPPER postgres_fdw
    OPTIONS (host '192.168.200.14', port '5432', dbname 'postgres', fetch_size '10000');
create foreign table my_big_table_mod4_s0 partition of my_big_table
    FOR VALUES WITH (MODULUS 4, REMAINDER 0) server shardA
    OPTIONS (table_name 'my_big_table_mod4_s0');
 .
 .
 .
create foreign table my_big_table_mod4_s3 partition of my_big_table
    FOR VALUES WITH (MODULUS 4, REMAINDER 3) server shardD
    OPTIONS (table_name 'my_big_table_mod4_s3');

在后端服务器上,我设置了一个包含多个索引的表,其数据(user_id, serial)跨多个分区聚集。不过,我不认为这些细节与我的实际问题非常相关。

针对我的集群的常见查询采用以下模式:

SELECT * from my_big_table
WHERE
  user_id = 12345     -- only 1 user, always! --> single foreign server.
ORDER BY serial DESC  -- get 'newest' 90% of the time, 10% ASC
LIMIT 1000;           -- max limit 1000, sometimes less

对于 < 1000 条记录的用户:一切正常,没问题。

对于具有 > 100.000 条记录的用户,我看到了导致性能不佳的问题:explain显示 LIMIT 和排序发生在 FDW 上,而不是下推。为什么?

 Limit  (cost=927393.08..927395.58 rows=1000 width=32)
   Output: my_big_table_mod4_s0.serial, my_big_table_mod4_s0.some_object_id, my_big_table_mod4_s0.timestamp_ns, my_big_table_mod4_s0.object_type, my_big_table_mod4_s0.other_type, (length(my_big_table_mod4_s0.data))
   ->  Sort  (cost=927393.08..931177.06 rows=1513592 width=32)
         Output: my_big_table_mod4_s0.serial, my_big_table_mod4_s0.some_object_id, my_big_table_mod4_s0.timestamp_ns, my_big_table_mod4_s0.object_type, my_big_table_mod4_s0.other_type, (length(my_big_table_mod4_s0.data))
         Sort Key: my_big_table_mod4_s0.serial DESC
         ->  Foreign Scan on public.my_big_table_mod4_s0  (cost=5318.35..844404.46 rows=1513592 width=32)
               Output: my_big_table_mod4_s0.serial, my_big_table_mod4_s0.some_object_id, my_big_table_mod4_s0.timestamp_ns, my_big_table_mod4_s0.object_type, my_big_table_mod4_s0.other_type, length(my_big_table_mod4_s0.data)
               Remote SQL: SELECT serial, some_object_id, timestamp_ns, object_type, other_type, data FROM public.my_big_table_mod4_s0 WHERE ((user_id = 4560084))
 JIT:
   Functions: 3
   Options: Inlining true, Optimization true, Expressions true, Deforming true

综上所述:

  • 已选择单个后端服务器:OK!(解决了这个)
  • Remote SQL: SELECT [...]表示没有 ORDER BY,没有 LIMIT。问题。

在后端服务器上执行直接显示:

 Limit  (cost=1.74..821.42 rows=1000 width=32)
   Output: my_big_table_mod4_s0_part123.serial, my_big_table_mod4_s0_part123.some_object_id, my_big_table_mod4_s0_part123.timestamp_ns, my_big_table_mod4_s0_part123.object_type, my_big_table_mod4_s0_part123.other_type, (length(my_big_table_mod4_s0_part123.data))
   ->  Append  (cost=1.74..1240669.45 rows=1513592 width=32)
         ->  Index Scan Backward using my_big_table_mod4_s0_part123_pkey on public.my_big_table_mod4_s0_part123  (cost=0.43..290535.67 rows=355620 width=32)
               Output: my_big_table_mod4_s0_part123.serial, my_big_table_mod4_s0_part123.some_object_id, my_big_table_mod4_s0_part123.timestamp_ns, my_big_table_mod4_s0_part123.object_type, my_big_table_mod4_s0_part123.other_type, length(my_big_table_mod4_s0_part123.data)
               Index Cond: (my_big_table_mod4_s0_part123.user_id = 4560084)
         ->  Index Scan Backward using [... other partitions ...]

我尝试了什么:

  • 由于 FDW 仍在开发中,我尝试使用更新的版本:FDW 和后端服务器都使用 11.4 和 12-beta2。没有观察到差异。
  • 针对外部表运行 ANALYZE(在 FDW 实例上)。花费大量时间;看起来它正在扫描远程表的全表?查询计划没有区别。
  • 更改fetch_size远程 SERVER 对象上的值。没有不同。
  • use_remote_estimate=true在远程 SERVER 对象上设置。没有不同。
  • fdw_tuple_cost=100在远程 SERVER 对象上设置。排序现在发生在远程服务器上,但 LIMIT 仍然没有被按下。
  • 在网上寻找其他人看到这个,只显示这个相关的帖子:Missed LIMIT Clause pushdown in FDW API

    但是这个线程提到在 9.7 中修复这个问题等等,但我使用的是 11.4 和 12-beta2。还是我误解了这一点?

    并发布:外部表的奇怪成本估算显示了调整 FDW 的一个很好的例子,但不幸的是,它没有涵盖我的 LIMITs 问题。

  • 快速浏览一下 PostgreSQL 源代码,我注意到这个语句,可能与 FDW 相关,也可能不相关(来源)。

    我们不能将包含 LIMIT/OFFSET 的子选择推送给工作人员,因为不能保证行顺序是完全确定的,并且应用 LIMIT/OFFSET 会导致顶层结果不一致。(在某些情况下,如果结果是有序的,我们可以放宽这个限制。但目前似乎不值得为此付出额外的努力。)

  • 再看一下源代码,我发现了这个有希望的提交(d50d172e51):

    这为 postgres_fdw 提供了处理 SELECT 命令的能力,以便它 1) 跳过 LockRows 步骤(如果有)(注意这是安全的,因为它执行早期锁定)和 2) 降低 LIMIT 和/或 OFFSET 限制(如果有) 到远端。这不处理 INSERT/UPDATE/DELETE 情况。

    它为我的案例添加了一个单元测试案例!

    -- and both ORDER BY and LIMIT can be shipped
    EXPLAIN (VERBOSE, COSTS OFF)
      SELECT * FROM ft1 t1 WHERE t1.c1 === t1.c2 order by t1.c2 limit 1;
                                                                            QUERY PLAN                                                                         
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    Foreign Scan on public.ft1 t1
      Output: c1, c2, c3, c4, c5, c6, c7, c8
      Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" OPERATOR(public.===) c2)) ORDER BY c2 ASC NULLS LAST LIMIT 1::bigint
    

    这应该是我已经运行的 12-beta2 的一部分...

我注意到我应该在这里按 DESC 顺序使用索引,但现在这不那么相关了。

performance sharding
  • 1 个回答
  • 2606 Views
Martin Hope
Ramraj Patel
Asked: 2019-06-08 01:26:04 +0800 CST

如何临时关闭 mongodb 分片集群

  • 1

我已经设置了具有以下拓扑的 mongodb 分片集群

  • 3x3 分片(每个分片有 2 个副本集)
  • 1x3 配置服务器副本集群
  • 2个mongos路由器

我想暂时关闭整个集群,保持数据完整性。我以后可能会使用这个设置,所以我不想放弃整个设置。

任何建议,将不胜感激。

mongodb sharding
  • 1 个回答
  • 873 Views
Martin Hope
Massimo Lavermicocca
Asked: 2019-03-21 10:55:11 +0800 CST

“单调改变分片键”是什么意思?

  • 2

我正在撰写我的第一篇关于 MongoDB 和更具体的 MongoDB 分片集群的文章。在文档中,我发现在远程分片的情况下,shard key 应该是“Non-Monotonically Changing Shard Keys”。

有人可以向我解释吗?示例将不胜感激。

谢谢。

mongodb sharding
  • 1 个回答
  • 448 Views
Martin Hope
tom dinh
Asked: 2019-03-10 13:16:39 +0800 CST

文档不进入新添加的分片

  • 0

我已将分片添加到现有集群,当我执行 db.printShardingStatus() 时,我看到了一个分布:

mongos> db.printShardingStatus()
--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5c84149e75f51a74e9796add")
  }
  shards:
        {  "_id" : "shard0000",  "host" : "127.0.0.1:27023",  "state" : 1 }
        {  "_id" : "shard0001",  "host" : "127.0.0.1:27024",  "state" : 1 }
        {  "_id" : "shard0002",  "host" : "localhost:27025",  "state" : 1 }
  active mongoses:
        "4.0.6" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  3
        Last reported error:  Error connecting to localhost:27025 (127.0.0.1:27025) :: caused by :: Connection refused
        Time of Reported error:  Sat Mar 09 2019 20:55:55 GMT+0000 (UTC)
        Migration Results for the last 24 hours: 
                8 : Success
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shard0000   1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0) 
        {  "_id" : "testdb",  "primary" : "shard0001",  "partitioned" : true,  "version" : {  "uuid" : UUID("68b7f8fe-17f6-4049-87ce-6c616c7746b7"),  "lastMod" : 1 } }
                testdb.testcollection
                        shard key: { "testkey" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                shard0000   3
                                shard0001   3
                                shard0002   1
                        { "testkey" : { "$minKey" : 1 } } -->> { "testkey" : "key0" } on : shard0002 Timestamp(9, 0) 
                        { "testkey" : "key0" } -->> { "testkey" : "key20968" } on : shard0000 Timestamp(7, 1) 
                        { "testkey" : "key20968" } -->> { "testkey" : "key4265" } on : shard0000 Timestamp(4, 0) 
                        { "testkey" : "key4265" } -->> { "testkey" : "key53621" } on : shard0000 Timestamp(6, 0) 
                        { "testkey" : "key53621" } -->> { "testkey" : "key64595" } on : shard0001 Timestamp(5, 1) 
                        { "testkey" : "key64595" } -->> { "testkey" : "key8552" } on : shard0001 Timestamp(9, 1) 
                        { "testkey" : "key8552" } -->> { "testkey" : { "$maxKey" : 1 } } on : shard0001 Timestamp(4, 1) 

但是当我访问新添加的分片(shard0002)时,集合是空的?有谁知道为什么?

mongodb sharding
  • 1 个回答
  • 118 Views
Martin Hope
tom dinh
Asked: 2019-03-09 14:41:07 +0800 CST

mongodb 分片集合

  • 1

我正在尝试拆分我的收藏。当我执行命令时:

sh.enableSharding("testdb")

我得到:

{
    "ok" : 1,
    "operationTime" : Timestamp(1552083125, 2),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1552083125, 2),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}

现在,当我尝试使用以下命令对我的集合进行分片时:“sh.shardCollection("testdb.testcollection", {testkey:1})”

我收到错误:

{
    "ok" : 0,
    "errmsg" : "Cannot accept sharding commands if not started with --shardsvr",
    "code" : 193,
    "codeName" : "NoShardingEnabled",
    "operationTime" : Timestamp(1552083136, 4),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1552083136, 4),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}

我检查了分片的状态,看起来它是成功的:

sh.status()
--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5c82df7b7a98360e9dd3c5da")
  }
  shards:
        {  "_id" : "shard0000",  "host" : "127.0.0.1:27023",  "state" : 1 }
        {  "_id" : "shard0001",  "host" : "127.0.0.1:27024",  "state" : 1 }
  active mongoses:
        "4.0.6" : 1
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours: 
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
        {  "_id" : "testdb",  "primary" : "shard0000",  "partitioned" : true,  "version" : {  "uuid" : UUID("ed327ab3-1de9-4a0a-89f5-8d0bf81015fc"),  "lastMod" : 1 } }

那么为什么当我尝试 shardCollection 时会出现该错误?我在 mongos 实例中运行所有这些

mongodb sharding
  • 1 个回答
  • 442 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve