{"id":18445734,"url":"https://github.com/voronenko/mongo_shards","last_synced_at":"2025-04-15T01:15:58.177Z","repository":{"id":145345639,"uuid":"65906988","full_name":"Voronenko/mongo_shards","owner":"Voronenko","description":"Laboratory repository for creating test shards \u0026 replica sets","archived":false,"fork":false,"pushed_at":"2016-08-18T19:23:20.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T01:15:38.960Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Voronenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-17T12:46:43.000Z","updated_at":"2016-08-17T15:51:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"9bfd350d-d888-4d45-b521-3ed372454fc9","html_url":"https://github.com/Voronenko/mongo_shards","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voronenko%2Fmongo_shards","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voronenko%2Fmongo_shards/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voronenko%2Fmongo_shards/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Voronenko%2Fmongo_shards/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Voronenko","download_url":"https://codeload.github.com/Voronenko/mongo_shards/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986315,"owners_count":21194025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T07:07:02.543Z","updated_at":"2025-04-15T01:15:58.169Z","avatar_url":"https://github.com/Voronenko.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"Initial state:\n```\nMongoDB shell version: 3.2.9\nconnecting to: 127.0.0.1:27018/test\nmongos\u003e sh.status()\n--- Sharding Status ---\n  sharding version: {\n\t\"_id\" : 1,\n\t\"minCompatibleVersion\" : 5,\n\t\"currentVersion\" : 6,\n\t\"clusterId\" : ObjectId(\"57b5fefbd85b57c5c9ff041f\")\n}\n  shards:\n\t{  \"_id\" : \"alshard1\",  \"host\" : \"alshard1/192.168.0.21:37107\" }\n\t{  \"_id\" : \"alshard2\",  \"host\" : \"alshard2/192.168.0.21:37207\" }\n\t{  \"_id\" : \"alshard3\",  \"host\" : \"alshard3/192.168.0.21:37307\" }\n\t{  \"_id\" : \"alshard4\",  \"host\" : \"alshard4/192.168.0.21:37407\" }\n  active mongoses:\n\t\"3.2.9\" : 1\n  balancer:\n\tCurrently enabled:  yes\n\tCurrently running:  no\n\tFailed balancer rounds in last 5 attempts:  0\n\tMigration Results for the last 24 hours:\n\t\tNo recent migrations\n  databases:\n\t{  \"_id\" : \"test\",  \"primary\" : \"alshard1\",  \"partitioned\" : true }\n```\n\nEach shard consists of one primary in replica set.\n```\nmongo --port 37107\n\nalshard1:PRIMARY\u003e rs.status()\n{\n\t\"set\" : \"alshard1\",\n\t\"date\" : ISODate(\"2016-08-18T18:33:48.195Z\"),\n\t\"myState\" : 1,\n\t\"term\" : NumberLong(1),\n\t\"heartbeatIntervalMillis\" : NumberLong(2000),\n\t\"members\" : [\n\t\t{\n\t\t\t\"_id\" : 0,\n\t\t\t\"name\" : \"192.168.0.21:37107\",\n\t\t\t\"health\" : 1,\n\t\t\t\"state\" : 1,\n\t\t\t\"stateStr\" : \"PRIMARY\",\n\t\t\t\"uptime\" : 155,\n\t\t\t\"optime\" : {\n\t\t\t\t\"ts\" : Timestamp(1471545083, 1),\n\t\t\t\t\"t\" : NumberLong(1)\n\t\t\t},\n\t\t\t\"optimeDate\" : ISODate(\"2016-08-18T18:31:23Z\"),\n\t\t\t\"electionTime\" : Timestamp(1471545082, 2),\n\t\t\t\"electionDate\" : ISODate(\"2016-08-18T18:31:22Z\"),\n\t\t\t\"configVersion\" : 1,\n\t\t\t\"self\" : true\n\t\t}\n\t],\n\t\"ok\" : 1\n}\nalshard1:PRIMARY\u003e\n```\n==============================================\n\nExpanding  each shard to M-S-A replica set\n\nSlave\n\nBefore adding a new member to an existing replica set, prepare the new member’s data directory using one of the following strategies:\n\nMake sure the new member’s data directory does not contain data. The new member will copy the data from an existing member.\nIf the new member is in a recovering state, it must exit and become a secondary before MongoDB can copy all data as part of the replication process. This process takes time but does not require administrator intervention.\nManually copy the data directory from an existing member. The new member becomes a secondary member and will catch up to the current state of the replica set. Copying the data over may shorten the amount of time for the new member to become current.\nEnsure that you can copy the data directory to the new member and begin replication within the window allowed by the oplog. Otherwise, the new instance will have to perform an initial sync, which completely resynchronizes the data, as described in Resync a Member of a Replica Set.\nUse rs.printReplicationInfo() to check the current state of replica set members with regards to the oplog.\n\nStrategy 1\n\nNote on shard name:\n```\nrm -rf db/alshard1/shardsvr_1\nmkdir -p db/alshard1/shardsvr_1\nmongod --replSet alshard1 --logpath \"log/shardsvr_alshard1_1.log\" --dbpath db/alshard1/shardsvr_1 --port 37108 --fork --shardsvr --smallfiles\n```\nconnect to primary:  add newly added member\n```\nalshard1:PRIMARY\u003e rs.add({_id:1, host:\"192.168.0.21:37108\", priority:0})\n{ \"ok\" : 1 }\n```\n\nCheck result:\n```\nalshard1:PRIMARY\u003e rs.conf()\n{\n\t\"_id\" : \"alshard1\",\n\t\"version\" : 2,\n\t\"protocolVersion\" : NumberLong(1),\n\t\"members\" : [\n\t\t{\n\t\t\t\"_id\" : 0,\n\t\t\t\"host\" : \"192.168.0.21:37107\",\n\t\t\t\"arbiterOnly\" : false,\n\t\t\t\"buildIndexes\" : true,\n\t\t\t\"hidden\" : false,\n\t\t\t\"priority\" : 1,\n\t\t\t\"tags\" : {\n\n\t\t\t},\n\t\t\t\"slaveDelay\" : NumberLong(0),\n\t\t\t\"votes\" : 1\n\t\t},\n\t\t{\n\t\t\t\"_id\" : 1,\n\t\t\t\"host\" : \"192.168.0.21:37108\",\n\t\t\t\"arbiterOnly\" : false,\n\t\t\t\"buildIndexes\" : true,\n\t\t\t\"hidden\" : false,\n\t\t\t\"priority\" : 0,\n\t\t\t\"tags\" : {\n\n\t\t\t},\n\t\t\t\"slaveDelay\" : NumberLong(0),\n\t\t\t\"votes\" : 1\n\t\t}\n\t],\n```\nChecking operation status:  rs.status() , or in more details\n```\nalshard1:PRIMARY\u003e use admin\nswitched to db admin\n\n\nalshard1:PRIMARY\u003e db.runCommand( { replSetGetStatus : 1 } )\n```\n\npay attention to myState (log:  https://docs.mongodb.com/manual/reference/replica-states/)\ngood values are 1,2,7\n\n```\n{\n\t\"set\" : \"alshard1\",\n\t\"date\" : ISODate(\"2016-08-18T19:00:28.831Z\"),\n\t\"myState\" : 1,\n\t\"term\" : NumberLong(1),\n\t\"heartbeatIntervalMillis\" : NumberLong(2000),\n\t\"members\" : [\n\t\t{\n\t\t\t\"_id\" : 0,\n\t\t\t\"name\" : \"192.168.0.21:37107\",\n\t\t\t\"health\" : 1,\n\t\t\t\"state\" : 1,\n\t\t\t\"stateStr\" : \"PRIMARY\",\n\t\t\t\"uptime\" : 1755,\n\t\t\t\"optime\" : {\n\t\t\t\t\"ts\" : Timestamp(1471546634, 1),\n\t\t\t\t\"t\" : NumberLong(1)\n\t\t\t},\n\t\t\t\"optimeDate\" : ISODate(\"2016-08-18T18:57:14Z\"),\n\t\t\t\"electionTime\" : Timestamp(1471545082, 2),\n\t\t\t\"electionDate\" : ISODate(\"2016-08-18T18:31:22Z\"),\n\t\t\t\"configVersion\" : 2,\n\t\t\t\"self\" : true\n\t\t},\n\t\t{\n\t\t\t\"_id\" : 1,\n\t\t\t\"name\" : \"192.168.0.21:37108\",\n\t\t\t\"health\" : 1,\n\t\t\t\"state\" : 2,\n\t\t\t\"stateStr\" : \"SECONDARY\",\n\t\t\t\"uptime\" : 194,\n\t\t\t\"optime\" : {\n\t\t\t\t\"ts\" : Timestamp(1471546634, 1),\n\t\t\t\t\"t\" : NumberLong(1)\n\t\t\t},\n\t\t\t\"optimeDate\" : ISODate(\"2016-08-18T18:57:14Z\"),\n\t\t\t\"lastHeartbeat\" : ISODate(\"2016-08-18T19:00:28.445Z\"),\n\t\t\t\"lastHeartbeatRecv\" : ISODate(\"2016-08-18T19:00:26.448Z\"),\n\t\t\t\"pingMs\" : NumberLong(0),\n\t\t\t\"configVersion\" : 2\n\t\t}\n\t],\n\t\"ok\" : 1\n}\nalshard1:PRIMARY\u003e\n```\n\n===================================================\n\nAdding the arbiter:\n\nAn arbiter does not store data, but until the arbiter’s mongod process is added to the replica set, the arbiter will act like any other mongod process and start up with a set of data files and with a full-sized journal.\n\nTo minimize the default creation of data, set the following in the arbiter’s configuration file:\n\nstorage.journal.enabled to false\nWARNING\nNever set storage.journal.enabled to false on a data-bearing node.\nFor MMAPv1 storage engine, storage.mmapv1.smallFiles to true\nThese settings are specific to arbiters. Do not set storage.journal.enabled to false on a data-bearing node. Similarly, do not set storage.mmapv1.smallFiles unless specifically indicated.\n\n```\nrm -rf db/alshard1/shardsvr_2\nmkdir -p db/alshard1/shardsvr_2\nmongod --replSet alshard1 --logpath \"log/shardsvr_alshard1_2.log\" --dbpath db/alshard1/shardsvr_2 --port 37109 --fork --shardsvr --smallfiles\n```\n\n\nConnect to the primary\n```\nalshard1:PRIMARY\u003e rs.addArb(\"192.168.0.21:37109\")\n{ \"ok\" : 1 }\n\n\n\nStatus after update:\n\n{\n    \"_id\" : 0,\n    \"name\" : \"192.168.0.21:37107\",\n    \"health\" : 1,\n    \"state\" : 1,\n    \"stateStr\" : \"PRIMARY\",\n    \"uptime\" : 2588,\n    \"optime\" : {\n      \"ts\" : Timestamp(1471547621, 1),\n      \"t\" : NumberLong(1)\n    },\n    \"optimeDate\" : ISODate(\"2016-08-18T19:13:41Z\"),\n    \"electionTime\" : Timestamp(1471545082, 2),\n    \"electionDate\" : ISODate(\"2016-08-18T18:31:22Z\"),\n    \"configVersion\" : 3,\n    \"self\" : true\n  },\n  {\n    \"_id\" : 1,\n    \"name\" : \"192.168.0.21:37108\",\n    \"health\" : 1,\n    \"state\" : 2,\n    \"stateStr\" : \"SECONDARY\",\n    \"uptime\" : 1027,\n    \"optime\" : {\n      \"ts\" : Timestamp(1471547621, 1),\n      \"t\" : NumberLong(1)\n    },\n    \"optimeDate\" : ISODate(\"2016-08-18T19:13:41Z\"),\n    \"lastHeartbeat\" : ISODate(\"2016-08-18T19:14:21.124Z\"),\n    \"lastHeartbeatRecv\" : ISODate(\"2016-08-18T19:14:20.124Z\"),\n    \"pingMs\" : NumberLong(0),\n    \"syncingTo\" : \"192.168.0.21:37107\",\n    \"configVersion\" : 3\n  },\n  {\n    \"_id\" : 2,\n    \"name\" : \"192.168.0.21:37109\",\n    \"health\" : 1,\n    \"state\" : 7,\n    \"stateStr\" : \"ARBITER\",\n    \"uptime\" : 40,\n    \"lastHeartbeat\" : ISODate(\"2016-08-18T19:14:21.124Z\"),\n    \"lastHeartbeatRecv\" : ISODate(\"2016-08-18T19:14:21.124Z\"),\n    \"pingMs\" : NumberLong(0),\n    \"configVersion\" : 3\n  }\n],\n```\n\nChecking the replication state:\n\n```\nalshard1:PRIMARY\u003e rs.printSlaveReplicationInfo()\nsource: 192.168.0.21:37108\n\tsyncedTo: Thu Aug 18 2016 22:13:41 GMT+0300 (EEST)\n\t0 secs (0 hrs) behind the primary\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoronenko%2Fmongo_shards","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoronenko%2Fmongo_shards","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoronenko%2Fmongo_shards/lists"}