Mongodb

29
Gagan | Rohith | Sunil

description

best viewed in ubuntu (openoffice )

Transcript of Mongodb

Page 1: Mongodb

Gagan | Rohith | Sunil

Page 2: Mongodb

“MongoDB (from "humongous") is a scalable, high-performance, open source, schema-free, document-oriented database.”

- mongodb.org

Created by 10gen

Page 3: Mongodb

Features

• Document Oriented Storage• Querying• Auto Sharding• Replication Set

Page 4: Mongodb

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’})

Page 5: Mongodb
Page 6: Mongodb
Page 7: Mongodb

Querying

• Collections == Tables

• Documents/objects == Records/rows

Page 8: Mongodb

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}})

Page 9: Mongodb

DEMO (Part 1)

Page 10: Mongodb

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

Page 11: Mongodb
Page 12: Mongodb

Architectural Overview

Page 13: Mongodb

OperationsThe config server => Meta-data

The mongos process =>Routing & Coordination

Mongod=> Mongo Demon(Mysqld)

Page 14: Mongodb

Config server

Mongos

Shards

Page 15: Mongodb

Architectural Overview

Page 16: Mongodb

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)

Page 17: Mongodb

Flowchart

App ServerApp Server Client(Mongos)Client

(Mongos) Configuration ServerConfiguration Server

DECISIONGlobal

Targeted

DECISIONGlobal

Targeted

Shard3Shard3

Shard4Shard4

Shard2Shard2

Shard1Shard1

Page 18: Mongodb

Sharding and Failover

NO SINGLE POINT FAILURE

Failure of->Mongos process->Single mongod server->Failure of all mongod servers comprising a shard.->Config server.

Page 19: Mongodb

Master and Slave

Page 20: Mongodb

REPLICA SETS

Shards Architecture Representation

Page 21: Mongodb

Replication Set

Page 22: Mongodb

A Set

Page 23: Mongodb

A Set

Page 24: Mongodb

A Set

Page 25: Mongodb

A Set

Page 26: Mongodb

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.

Page 27: Mongodb

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)

Page 28: Mongodb

DEMO

Page 29: Mongodb

BIBLOGRAPHY

Www.mongodb.org Snails in Turtleneck.com