Mongodb
-
Upload
gagan-gowda -
Category
Documents
-
view
1.396 -
download
1
description
Transcript of Mongodb
Gagan | Rohith | Sunil
“MongoDB (from "humongous") is a scalable, high-performance, open source, schema-free, document-oriented database.”
- mongodb.org
Created by 10gen
Features
• Document Oriented Storage• Querying• Auto Sharding• Replication Set
Document oriented storageDocument 1: FirstName=“raj", Address=“bogadi", Hobby=“stamp collection"
Document 2: FirstName=“raghu", Address=“25, kuvempu nagar", Children=(“ram,10", “hari,8", “ramya,5”)
• BSON• JSON
• JSON Notation• db.people.insert({FirstName:’raj’,Address=‘bogadi’,Hobby=‘stamp
collection’})
Querying
• Collections == Tables
• Documents/objects == Records/rows
SQL Statement Mongo Query Language Statement
CREATE TABLE USERS (a Number, b Number);
implicit; can be done explicitly
INSERT INTO USERS VALUES(1,1); db.users.insert({a:1,b:1})
SELECT * FROM users; db.users.find()
SELECT * FROM users WHERE age=33; db.users.find({age:33})
SELECT * FROM users WHERE age=33 ORDER BY name;
db.users.find({age:33}).sort({name:1})
SELECT * FROM users WHERE age>33; db.users.find({'age':{$gt:33}})
SELECT * FROM users WHERE age<33; db.users.find({'age':{$lt:33}})
DEMO (Part 1)
ShardingSharding is the partitioning of data among multiple machines in an order-preserving manner.
SHARDING IN MONGODB:Auto –Sharding (only needs shard key ).Automatic load Balancing.Scaling out to thousands of nodes.Availability and automated failover
Architectural Overview
OperationsThe config server => Meta-data
The mongos process =>Routing & Coordination
Mongod=> Mongo Demon(Mysqld)
Config server
Mongos
Shards
Architectural Overview
Operation Types
Operations on a sharded system fall into one of two categories. global Targeteddb.foo.find( { x : 300, age : 40 } ) (Targeted)db.foo.find( { age : 40 } ) (Global)
Flowchart
App ServerApp Server Client(Mongos)Client
(Mongos) Configuration ServerConfiguration Server
DECISIONGlobal
Targeted
DECISIONGlobal
Targeted
Shard3Shard3
Shard4Shard4
Shard2Shard2
Shard1Shard1
Sharding and Failover
NO SINGLE POINT FAILURE
Failure of->Mongos process->Single mongod server->Failure of all mongod servers comprising a shard.->Config server.
Master and Slave
REPLICA SETS
Shards Architecture Representation
Replication Set
A Set
A Set
A Set
A Set
Election Algorithm
Periodically exchange Maxappliedoptime with all other nodes using the following format(selfid,maxoptime) .If nodes maxoptime is more send NO or else send YES(Arbitrer).The node getting the majority of yes and see majority of nodes will be elected as Primary.The process is repeated periodically.
Election Algorithm(Flow)server-a: primary oplog: (a1,a2,a3,a4,a5)server-b: secondary oplog: (a1)server-c: secondary oplog: (a1,a2,a3)…// server-a goes down…server-b: secondary oplog: (a1)server-c: secondary oplog: (a1,a2,a3)...server-b: secondary oplog: (a1)server-c: primary oplog: (a1,a2,a3) // c has highest ord and becomes primary...server-b: secondary oplog: (a1,a2,a3)server-c: primary oplog: (a1,a2,a3,c4)...server-a resumes...server-a: recovering oplog: (a1,a2,a3,a4,a5)server-b: secondary oplog: (a1,a2,a3)server-c: primary oplog: (a1,a2,a3,c4)…server-a: recovering oplog: (a1,a2,a3,c4)server-b: secondary oplog: (a1,a2,a3,c4)server-c: primary oplog: (a1,a2,a3,c4)…server-a: secondary oplog: (a1,a2,a3,c4)server-b: secondary oplog: (a1,a2,a3,c4)server-c: primary oplog: (a1,a2,a3,c4,c5,c6,c7,c8)…server-a: secondary oplog: (a1,a2,a3,c4,c5,c6,c7,c8)server-b: secondary oplog: (a1,a2,a3,c4,c5,c6,c7,c8)server-c: primary oplog: (a1,a2,a3,c4,c5,c6,c7,c8)
DEMO
BIBLOGRAPHY
Www.mongodb.org Snails in Turtleneck.com