шардинг с mongodb 3.2.22 не работает - PullRequest
0 голосов
/ 10 мая 2019

я использую windows и mongodb 3.2.22 Я хочу запустить шардинг в localhost Я выполнил эти команды на терминале cmd

mongod --replSet s0 --dbpath C:\Users\Marco\Desktop\mongo3sharding\1 --port 37017 --shardsvr --smallfiles
mongod --replSet s0 --dbpath C:\Users\Marco\Desktop\mongo3sharding\2 --port 37018 --shardsvr --smallfiles
mongod --replSet s0 --dbpath C:\Users\Marco\Desktop\mongo3sharding\3 --port 37019 --shardsvr --smallfiles

mongo 127.0.0.1:37017
config = { _id: "s0", members:[
          { _id : 0, host : "localhost:37017" },
          { _id : 1, host : "localhost:37018" },
          { _id : 2, host : "localhost:37019" }]};
rs.initiate(config)


mongod --replSet s1 --dbpath C:\Users\Marco\Desktop\mongo3sharding\4 --port 47017 --shardsvr --smallfiles
mongod --replSet s1 --dbpath C:\Users\Marco\Desktop\mongo3sharding\5 --port 47018 --shardsvr --smallfiles
mongod --replSet s1 --dbpath C:\Users\Marco\Desktop\mongo3sharding\6 --port 47019 --shardsvr --smallfiles

mongo --port 47017 
config = { _id: "s1", members:[
          { _id : 0, host : "localhost:47017" },
          { _id : 1, host : "localhost:47018" },
          { _id : 2, host : "localhost:47019" }]};
rs.initiate(config)


mongod --replSet s2 --dbpath C:\Users\Marco\Desktop\mongo3sharding\7 --port 57017 --shardsvr --smallfiles
mongod --replSet s2 --dbpath C:\Users\Marco\Desktop\mongo3sharding\8 --port 57018 --shardsvr --smallfiles
mongod --replSet s2 --dbpath C:\Users\Marco\Desktop\mongo3sharding\9 --port 57019 --shardsvr --smallfiles

mongo --port 57017
config = { _id: "s2", members:[
          { _id : 0, host : "localhost:57017" },
          { _id : 1, host : "localhost:57018" },
          { _id : 2, host : "localhost:57019" }]};
rs.initiate(config)


mongod --dbpath C:\Users\Marco\Desktop\mongo3sharding\c1 --port 57040 --configsvr --smallfiles
mongod --dbpath C:\Users\Marco\Desktop\mongo3sharding\c2 --port 57041 --configsvr --smallfiles
mongod --dbpath C:\Users\Marco\Desktop\mongo3sharding\c3 --port 57042 --configsvr --smallfiles


mongos --configdb localhost:57040,localhost:57041,localhost:57042


mongo
db.adminCommand( { addshard : "s0/localhost:37017" } );
db.adminCommand( { addshard : "s1/localhost:47017" } );
db.adminCommand( { addshard : "s2/localhost:57017" } );

sh.addShardTag('s0','shard0')
sh.addShardTag('s1','shard1')
sh.addShardTag('s2','shard2')

sh.addTagRange("mydatabase.parole",{sentiment:"anger"},{sentiment:"disgust"}, "shard0")
sh.addTagRange("mydatabase.parole",{sentiment:"fear"},{sentiment:"sadness"}, "shard1")
sh.addTagRange("mydatabase.parole",{sentiment:"surprise"},{sentiment:"trust"}, "shard2")

вывод команды sh.status () такой:

--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5cd57e16918759db47284d69")
  }
  shards:
        {  "_id" : "s0",  "host" : "s0/localhost:37017,localhost:37018,localhost:37019",  "tags" : [ "shard0" ] }
        {  "_id" : "s1",  "host" : "s1/localhost:47017,localhost:47018,localhost:47019",  "tags" : [ "shard1" ] }
        {  "_id" : "s2",  "host" : "s2/localhost:57017,localhost:57018,localhost:57019",  "tags" : [ "shard2" ] }
  active mongoses:
        "3.2.22" : 1
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                2 : Success
  databases:
        {  "_id" : "mydatabase",  "primary" : "s0",  "partitioned" : true }
                mydatabase.parole
                        shard key: { "sentiment" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                s0      2
                                s1      1
                                s2      1
                        { "sentiment" : { "$minKey" : 1 } } -->> { "sentiment" : "anger" } on : s0 Timestamp(3, 1)
                        { "sentiment" : "anger" } -->> { "sentiment" : "fear" } on : s0 Timestamp(1, 3)
                        { "sentiment" : "fear" } -->> { "sentiment" : "surprise" } on : s1 Timestamp(2, 0)
                        { "sentiment" : "surprise" } -->> { "sentiment" : { "$maxKey" : 1 } } on : s2 Timestamp(3, 0)
                         tag: shard0  { "sentiment" : "anger" } -->> { "sentiment" : "disgust" }
                         tag: shard1  { "sentiment" : "fear" } -->> { "sentiment" : "sadness" }
                         tag: shard2  { "sentiment" : "surprise" } -->> { "sentiment" : "trust" }

Я пытался вставить много данных, используя этот код Python

import pymongo
from pymongo import MongoClient
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["parole"]

a=b=c=0
while a < 10000:
    dic={"sentiment" : "anger" , "test" : a}
    mycol.insert_one(dic)

    dic={"sentiment" : "fear" , "test" : a}
    mycol.insert_one(dic)

    dic={"sentiment" : "surprise" , "test" : a}
    mycol.insert_one(dic) 
    a+=1 

вставка и репликация работают, но шардинг не работает. Я понимаю это, потому что папки 1,2,3 увеличивают свой размер, а папки 4,5,6,7,8,9 не меняют их размер.

что я могу сделать? благодарю вас! Привет

1 Ответ

1 голос
/ 14 июля 2019

Я отвечаю на свой вопрос сам. шардинг не работал, потому что данных было недостаточно. используйте команду

db.settings.save ({_id: "chunksize", value: 1})

чтобы уменьшить размер куска

больше информации об этой команде в https://docs.mongodb.com/manual/tutorial/modify-chunk-size-in-sharded-cluster/

...