通过Mongolab申请免费的MongoDB测试实例

Mongolab目前提供的免费的MongoDB实例供广大用户测试使用,免费实例的限制是最大500MB。

 

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

 

mongdblab

 

 

首先到https://mongolab.com 注册一个帐号,之后Login登录, 点击create new

mongdblab1

 

plan中要选择single-node才可以看到free plan的sanbox , cloud provide直接选Amazon AWS

mongodb2

之后点击create new mongodb deployment即可

需要手动创建一个mongodb用户:

mongolab4

 

之后就可以利用该云端mongodb测试实例了:

 

 

例如 使用mongo shell连接



[root@ocm ~]# mongo ds041432.mongolab.com:41432/dbdao -u dbdao -p dbdao
MongoDB shell version: 3.0.3
connecting to: ds041432.mongolab.com:41432/dbdao
rs-ds041432:PRIMARY> 

rs-ds041432:PRIMARY> 
rs-ds041432:PRIMARY> 

rs-ds041432:PRIMARY> db.dbdao.insert({"hello":"world!"});
WriteResult({ "nInserted" : 1 })
rs-ds041432:PRIMARY> db.dbdao.find();
{ "_id" : ObjectId("55672f4076e23efacff7cc07"), "hello" : "world!" }

C100DBA认证讲解 MongoDB replication 原理

C100DBA认证讲解 MongoDB replication 原理

Screen Shot 2015-05-25 at 11.39.46 PM

 

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

题目正文:

which of following is true of mechanics of replication in MongoDB?

  1. Clients read from nearest member of a replica set by default
  2. Members of a replica set may replicate data from any other data-bearing member of set .
  3. Operations on the primary are recorded in a capped collection called oplog

翻译:

下面关于Mongodb的replication复制技术细节描述正确的是?

  1. 复制集成员会默认从复制集中最近的成员哪里读取数据
  2. replica set 复制集中的成员可能从其他任何承载数据的节点上复制数据
  3. 在primary上的操作将会被记录到一个capped collection(受限集合)中称之为oplong

 

Replica set members replicate data continuously after the initial sync. This process keeps the members up to date with all changes to the replica set’s data. In most cases, secondaries synchronize from the primary.

http://docs.mongodb.org/manual/core/replica-set-sync/

==>默认情况下从Primary同步数据,而不是复制集中最近的成员

For a member to sync from another, both members must have the same value for the buildIndexessetting.

Beginning in version 2.2, secondaries avoid syncing from delayed members and hidden members.

从2.2开始secondaries会避免从延迟成员和隐藏成员哪里同步数据,所以复制集中的成员可能从其他任何承载数据的节点上复制数据是错误的

 

The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. MongoDB applies database operations on the primary and then records the operations on the primary’s oplog. The secondary members then copy and apply these operations in an asynchronous process. All replica set members contain a copy of the oplog, in thelocal.oplog.rs collection, which allows them to maintain the current state of the database.

http://docs.mongodb.org/manual/core/replica-set-oplog/

选项Operations on the primary are recorded in a capped collection called oplog是正确的。

C100DBA认证讲解 MongoDB 讲解-quick initiating new replica set member?

C100DBA认证讲解 MongoDB 讲解-quick initiating new replica set member?

Screen Shot 2015-05-25 at 11.15.20 PM

 

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

 

题目正文

which of the following is the recommended method for quickly initiating a new replica set member?

  1. Empty the dbpath directory for the new member to force an initial sync
  2. Mongodump a existing replica set member’s data and then mongorestore it to the new member
  3. Use the seed command
  4. Step up the new member to be the replica set primary
  5. Use a recent file system snapshot of an existing member with journaling turned on ,assuming the data files in the snapshot are more recent than the oldest operation in the primary’s oplog .

 

翻译:

以下哪个选项是被推荐的初始化一个新的replica set 复制集成员的?

  1. 为新成员清空dbpath路径下的文件,强制一个初始化同步
  2. mongodump一个replica set Member复制集成员的数据,并mongorestore到新成员
  3. 使用seed 命令
  4. 将新成员配置成replica set中的primary
  5. 使用一个现有成员的文件系统快照且需要启用了journaling ,假设快照中的数据文件要比primary的oplog中的最老的操作更新

 

官方文档对应的解释:

  • Initial sync occurs when MongoDB creates new databases on a new or restored member, populating the member with the replica set’s data. When a new or restored member joins or rejoins a set, the member waits to receive heartbeats from other members. By default, the member syncs from theclosest member of the set that is either the primary or another secondary with more recent oplog entries. This prevents two secondaries from syncing from each other.
  • Replication occurs continually after initial sync and keeps the member updated with changes to the replica set’s data.

http://docs.mongodb.org/v2.2/core/replication-internals/

 

Initial Sync

Initial sync copies all the data from one member of the replica set to another member. A member uses initial sync when the member has no data, such as when the member is new, or when the member has data but is missing a history of the set’s replication.

When you perform an initial sync, MongoDB:

  1. Clones all databases. To clone, the mongod queries every collection in each source database and inserts all data into its own copies of these collections. At this time, _id indexes are also built. The clone process only copies valid data, omitting invalid documents.

  2. Applies all changes to the data set. Using the oplog from the source, the mongod updates its data set to reflect the current state of the replica set.

  3. Builds all indexes on all collections (except _id indexes, which were already completed).

    When the mongod finishes building all index builds, the member can transition to a normal state, i.e.secondary.

http://docs.mongodb.org/manual/core/replica-set-sync/

MongoDB replica set演示和实验服务

mongolab提供了一个flip-flop 正反器的replica set复制集演示,其通过一个真实的replica set来演示自动的failover。 该真实环境包括三个节点:replica member “flip”和”flop”。每60秒,primary将会自己让自己不可用”step-down”,之后集群将failover到另一个节点上,60秒后再反转回来。

 

URL: http://mongolab.org/flip-flop/

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

 

同时mongolab还提供了一个可视化的replica set  的election过程

Screen Shot 2015-05-25 at 12.07.29 PM

 

样例日志:

Logs will start streaming when there is replica set activity. Please wait...

arbiter: Sun May 24 20:43:03.373 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state SECONDARY
arbiter: Sun May 24 20:43:07.386 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state PRIMARY
arbiter: Sun May 24 20:44:03.460 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state SECONDARY
arbiter: Sun May 24 20:44:09.545 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state PRIMARY
arbiter: Sun May 24 20:45:03.641 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state SECONDARY
arbiter: Sun May 24 20:45:13.669 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state PRIMARY
arbiter: Sun May 24 20:46:01.764 [rsHealthPoll] DBClientCursor::init call() failed
arbiter: Sun May 24 20:46:01.804 [rsHealthPoll] replSet info flip.mongolab.com:53117 is down (or slow to respond): DBClientBase::findN: transport error: flip.mongolab.com:53117 ns: local.$cmd query: { getnonce: 1 }
arbiter: Sun May 24 20:46:01.805 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state DOWN
arbiter: Sun May 24 20:46:03.815 [rsHealthPoll] replSet member flip.mongolab.com:53117 is up
arbiter: Sun May 24 20:46:03.816 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state SECONDARY
arbiter: Sun May 24 20:46:07.774 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state PRIMARY
arbiter: Sun May 24 20:47:03.863 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state SECONDARY
Sun May 24 20:47:03.863 [rsMgr] replSet I don't see a primary and I can't elect myself
arbiter: Sun May 24 20:47:13.910 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state PRIMARY
arbiter: Sun May 24 20:48:03.990 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state SECONDARY
arbiter: Sun May 24 20:48:07.992 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state PRIMARY
arbiter: Sun May 24 20:49:04.080 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state SECONDARY
arbiter: Sun May 24 20:49:14.141 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state PRIMARY
arbiter: Sun May 24 20:50:04.252 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state SECONDARY
arbiter: Sun May 24 20:50:14.265 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state PRIMARY
arbiter: Sun May 24 20:51:04.350 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state SECONDARY
arbiter: Sun May 24 20:51:14.456 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state PRIMARY
arbiter: Sun May 24 20:52:04.569 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state SECONDARY
arbiter: Sun May 24 20:52:08.573 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state PRIMARY
arbiter: Sun May 24 20:53:02.660 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state SECONDARY
arbiter: Sun May 24 20:53:08.675 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state PRIMARY
arbiter: Sun May 24 20:54:02.839 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state SECONDARY
arbiter: Sun May 24 20:54:12.951 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state PRIMARY
arbiter: Sun May 24 20:55:03.255 [rsHealthPoll] replSet member flop.mongolab.com:54117 is now in state SECONDARY
arbiter: Sun May 24 20:55:08.948 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state PRIMARY
arbiter: Sun May 24 20:56:03.017 [rsHealthPoll] replSet member flip.mongolab.com:53117 is now in state SECONDARY
arbiter: Sun May 24 20:56:09.024 [rsMgr] replSet I don't see a primary and I can't elect myself


 

 

flip-flop 的初衷是为了可视化演示复制集的election过程,让开发者能更清楚了解这一过程,以便能写出更好的客户端连接代码。同时mongolab还给出了一个连接URL:

mongodb://testdbuser:testdbpass@flip.mongolab.com:53117,flop.mongolab.com:54117/testdb

Maclean出的oracle面试题

原帖在这里:http://tieba.baidu.com/p/3784873245

有同学在群里问能否提供一些oracle的技术面试题, maclean这里抛砖引玉一下列出一些自己关心的面试内容; 由于是想到哪里写到哪里,所以没什么章法,还请轻拍

  1. 在Oracle AWR中如何定位到大表扫描的情况?
  2. oracle中row lock和TX锁到底是什么关系?
  3. 说说你遇到过的几个oracle等待事件,并简单解释其原理
  4. 简单描述以下一致性读consistent read 和undo的关系
  5. 某数据库出现了hang的情况,甚至sqlplus也无法登陆,你如何收集数据?
  6. 你是如何观察执行计划的,常用几种方法,优缺点如何?
  7. 你是否了解Latch和mutex,可以教条地告诉我他们的原理吗? 不需要你很清楚,只要能背书即可
  8. 对于一个SQL的执行计划问题,你无法调整SQL语句,该如何调整其执行计划?
  9. 现场试验:随机抽一个12c最近处的特性 要求针对其做一个试验并给出试验报告
  10. 给oracle freelist发一封英文邮件,咨询一个随机的技术问题,要求能够用英文明确描述问题

 

C100DBA MongoDB 讲解 replica set vote

C100DBA MongoDB 讲解 replica set vote

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

题目中文:

Given a replica set with five data-bearing members, suppose the primary goes down with operations in its oplog that have been copied to only one secondary .

Assuming no other problems occur, which of the following describes what is most likely to happen?

  1. The primary will rollback the operations
  2. The secondary with the most recent oplog will be elected primary
  3. The most recent secondary will roll back the operations following the election
  4. Reads will stale until primary comes backup up

翻译:

对于一个有五个承载数据的成员的replica set 而言,假设primary服务器宕机了,且其oplog中最新的操作信息只成功拷贝到一个secondary上了。

假设没有其他问题发生,以下哪个选项是正确的?

  1. Primary将在恢复时回滚部分操作
  2. 拥有最新的oplog的这个secondary服务器将赢得election并成为primary
  3. 在election后最新的这个secondary会回滚部分操作
  4. 直到primary重新可用,之前读操作将读到过时的数据

 

关于此问题 官方文档有较明确解释:

A rollback does not occur if the write operations replicate to another member of the replica set before the primary steps down and if that member remains available and accessible to a majority of the replica set.     http://docs.mongodb.org/manual/core/replica-set-rollbacks/

只要primary上的写操作已经复制到某个secondary成员上,secondary成员可用,就可以保证rollback不会发生。

 

 

C100DBA MongoDB讲解-update in replication

C100DBA MongoDB讲解-update in replication

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

题目正文:

Support you execute the following query on the primary of a replica set and that this results in updates to 130 documents in the products collection :

 

db.products.update( { "year": "2012" } , { "discount" : 0.1} , { multi: true } )

 

which of the following best describes replication in this case?

  1. Each Secondary executes the same query
  2. Each Secondary executes one operation per document affected
  3. Each Secondary writes a byte-for-byte of data file changes on the primary to its own data files.
  4. It depends on the configuration of the replica set
  5. None of the above describes replication correctly

翻译:

假设你在一个replica set复制集的primary上执行了下面的语句,并更新了130个products collection中的document文档,那么:

 

db.products.update( { “year”: “2012” } , { “discount” : 0.1} , { multi: true } )

那么如下哪个选项关于在此场景中的replication描述是正确的?

  1. 所有secondary将执行同样的语句
  2. 所有secondary将针对受影响的document一个一个做更新操作(其实oracle的Streams、OGG也是这样)
  3. 所有的secondary都对primary上数据文件的修改一个个字节地做对应的修改 (其实相当于Oracle 物理备库 physical standby)
  4. 取决于实际replica set的配置
  5. 以上说的关于replication 都不对啊

 

官方文档对于secondary应用oplog的解释是:

Updates to Multiple Documents at Once

The oplog must translate multi-updates into individual operations in order to maintain idempotency. This can use a great deal of oplog space without a corresponding increase in data size or disk use.      http://docs.mongodb.org/manual/core/replica-set-oplog/

即oplog必须将多更新的操作转换成单独的操作 以便维护幂等性idempotency,idempotency的含义是一个操作保证了这个操作无论被执行多少次都降产生同样的结果。

显然答案B是正确的,具体验证需要通过TRACE Secondary 来证明。

但题目中给出的update语句是存在问题的:

 

> db.products.insert({ year:"2012"});
WriteResult({ "nInserted" : 1 })
> db.products.update( { "year": "2012" } , { "discount" : 0.1} , { multi: true } )
WriteResult({
 "nMatched" : 0,
 "nUpserted" : 0,
 "nModified" : 0,
 "writeError" : {
 "code" : 9,
 "errmsg" : "multi update only works with $ operators"
 }
})
> 

C100DBA MongoDB 讲解-advantage of having delayed replica set member?

C100DBA MongoDB 讲解-advantage of having delayed replica set member?

dbDao 百度贴吧:http://tieba.baidu.com/dbdao

MongoDB技术学习QQ群: 421431253

 

What is the principal advantage of having a delayed replica set member?

  1. It allows the load on the secondary severs to be more evenly spread
  2. It allows you to perform queries against historical versions of data
  3. It increases write speed to the primary
  4. It makes it easier to upgrade the system without downtime
  5. It provides a window of time to recover from operator error

翻译为:

部署一个有延迟的replica set member复制集成员的主要好处是什么?

  1. 其允许二级服务器上的负载能够被均衡覆盖
  2. 其允许用户查询历史版本的数据 , (注解:其实就相当于是延迟的dataguard standby ,可以查到过去某个时间点的数据)
  3. 其帮助primary节点提供写入的速度
  4. 其帮助系统升级而无需宕机时间更简单方便
  5. 其为操作错误后的恢复提供了一个时间窗口

显然答案是B 其允许用户查询历史版本的数据。

delayed replica set member的配置方法:

z

cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].hidden = true
cfg.members[0].slaveDelay = 3600
rs.reconfig(cfg)

详见 官方文档http://docs.mongodb.org/manual/tutorial/configure-a-delayed-replica-set-member/

主要参数为slaveDelay ,注意slaveDelay的长度必须小于oplog的窗口,如果oplog要比slaveDelay时间短,则延迟的成员将无法成功复制操作。

 

Because delayed members are a “rolling backup” or a running “historical” snapshot of the data set, they may help you recover from various kinds of human error. For example, a delayed member can make it possible to recover from unsuccessful application upgrades and operator errors including dropped databases and collections.

由于延迟节点是一个 “滚动的备份” 或一个保持着历史快照的数据集, 所以他们可以帮助你从各种人为故障中恢复出数据。 例如如果一个不成功的应用升级或其他操作失误(例如误drop database或collection)时,你可以直接从延迟节点中抽取数据来恢复。