04-27 00:08
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[MongoDB] Sharding / Sharding Administration 본문

Data Science/MongoDB

[MongoDB] Sharding / Sharding Administration

cinema4dr12 2014. 4. 25. 00:12

by Geol Choi | April

이번 글은 샤딩에 대한 마지막 글로써 샤딩 관리에 대한 내용을 다루도록 하겠다.

Sharding / Production Configuration에서 실행했던 mongos 인스턴스가 여전히 실행 중인 것을 가정하고 진행하도록 하겠다. (만약 실행 중인 mongos 인스턴스가 없다면 하나 실행하도록 하자.)


Config 컬렉션

샤드에 대한 정보는 config db에서 얻을 수 있다. db를 config로 이동하자:

mongos> use config
switched to db config


config의 컬렉션 리스트를 출력하면 다음과 같다:

mongos> db.getCollectionNames()
[
	"changelog",
	"chunks",
	"databases",
	"lockpings",
	"locks",
	"mongos",
	"settings",
	"shards",
	"system.indexes",
	"version"
]


shards 컬렉션

샤드 목록을 조회하려면 shard 컬렉션의 내용을 살펴보도록 한다:

mongos> db.shards.find()
{ "_id" : "shard0000", "host" : "192.168.10.103:40001" }
{ "_id" : "shard0001", "host" : "192.168.10.101:40002" }

위의 내용을 살펴보면, "shard0000"과 "shard0001"이라는 두 개의 샤드가 설정되어 있으며 이에 대한 각각의 hostname과 port 정보가 함께 표시되는 것을 확인할 수 있다.


databases 컬렉션

databases 컬렉션은 샤드에 존재하는 데이터베이스 항목과 이들에 대한 정보를 담고있다.

mongos> db.databases.find().pretty()
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "jobs", "partitioned" : true, "primary" : "shard0001" }
{ "_id" : "users", "partitioned" : false, "primary" : "shard0000" }

"_id" : string

데이터베이스의 이름이다.

"partitioned" : boolean

true일 경우 이 데이터베이스 상에서 enableSharding 명령이 실행 중임을 의미한다.

"primary" : string

이 값은 해당 데이터의 "home"이 어디인지 알려준다. 데이터베이스는 샤드가 되든 안 되든 언제나 home을 가지고 있다. 샤드 설정에서 새 데이터베이스는 임의의 샤드 상에 생성된다. 이 home은 데이터 생성이 시작하는 장소이다. 샤딩이 완료되면 다른 서버들도 사용하겠지만 데이터베이스는 이 샤드 상에 시작될 것이다.


chunks 컬렉션

chunk 정보가 저장되어 있는 컬렉션이며, 클러스터 상에서 데이터가 어떻게 분할되어 저장되어 있는지에 대한 정보를 담고 있다.


Shard 명령어

이미 샤드에 관련된 기본적인 명령어들(enableSharding, addShard 등)을 익힌 바 있다. 클러스터 관리에 대한 기타 유용한 명령어들에 대해 알아보도록 하자.


shard 상태 정보 출력하기

db.printShardingStatus() 명령은 샤드 및 이와 연관된 데이터베이스에 대한 전체적인 정보를 제공한다.

mongos> db.printShardingStatus()
--- Sharding Status --- 
  sharding version: {
	"_id" : 1,
	"version" : 4,
	"minCompatibleVersion" : 4,
	"currentVersion" : 5,
	"clusterId" : ObjectId("5359f02b8a8822103e5e8796")
}
  shards:
	{  "_id" : "shard0000",  "host" : "localhost:40001" }
	{  "_id" : "shard0001",  "host" : "localhost:40002" }
	{  "_id" : "shard0002",  "host" : "localhost:40003" }
	{  "_id" : "shard0003",  "host" : "localhost:40004" }
  databases:
	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
	{  "_id" : "jobs",  "partitioned" : false,  "primary" : "shard0000" }


shard 제거하기

removeShard 명령을 이용하여 샤드를 제거할 수 있으며, 제거된 샤드의 모든 데이터 chunk는 다른 샤드로 이전된다. 예를 들어 localhost의 port 번호 40004로 할당된 샤드의 제거는 다음과 같다:

mongos> db.runCommand({removeshard : "localhost:40004"});
{
	"msg" : "draining started successfully",
	"state" : "started",
	"shard" : "shard0003",
	"ok" : 1
}


샤드가 제거됨에 따라 removeShard 명령은 데이터 이전에 대한 상태를 표시해준다:

mongos> db.runCommand({removeshard : "localhost:40004"});
{
	"msg" : "draining started successfully",
	"state" : "started",
	"shard" : "shard0003",
	"ok" : 1
}


데이터 이전이 완료되되면 다음과 같이 메시지가 출력된다:

mongos> db.runCommand({removeshard : "localhost:40004"});
{
	"msg" : "removeshard completed successfully",
	"state" : "completed",
	"shard" : "shard0003",
	"ok" : 1
}


이상으로 샤딩에 대한 내용을 모두 마무리하도록 하겠다. 다음 글에서는 MongoDB를 응용한 실제 어플리케이션 개발과 관련된 내용으로 진행하도록 하겠다.

Comments