{"id":131208,"date":"2019-01-11T10:00:21","date_gmt":"2019-01-11T02:00:21","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=131208"},"modified":"2019-01-03T08:52:13","modified_gmt":"2019-01-03T00:52:13","slug":"mongodb-copy","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mongodb-copy.html","title":{"rendered":"MongoDB\u590d\u5236\u96c6\u5168\u91cf\u540c\u6b65\u6539\u8fdb"},"content":{"rendered":"
MongoDB\u526f\u672c\u96c6\u6570\u636e\u540c\u6b65\u65b9\u5f0f<\/strong><\/div>\n

intial sync\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u5168\u91cf\u540c\u6b65\u3002<\/p>\n

replication\uff0c\u8ffd\u540c\u6b65\u6e90\u7684oplog\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u589e\u91cf\u540c\u6b65\u3002<\/p>\n

\u4e0b\u9762\u4f1a\u8be6\u7ec6\u4ecb\u7ecdMongoDB\u6570\u636e\u540c\u6b65\u7684\u5b9e\u73b0\u539f\u7406\u3002<\/p>\n

initial sync<\/strong><\/span><\/div>\n

Secondary\u8282\u70b9\u5f53\u51fa\u73b0\u5982\u4e0b\u72b6\u51b5\u65f6\uff0c\u9700\u8981\u5148\u8fdb\u884c\u5168\u91cf\u540c\u6b65\u3002<\/p>\n

oplog\u4e3a\u7a7a\u3002<\/p>\n

local.replset.minvalid\u96c6\u5408\u91cc_initialSyncFlag\u5b57\u6bb5\u8bbe\u7f6e\u4e3atrue\u3002<\/p>\n

\u5185\u5b58\u6807\u8bb0initialSyncRequested\u8bbe\u7f6e\u4e3atrue\u3002<\/p>\n

\u8fd93\u4e2a\u573a\u666f\u5206\u522b\u5bf9\u5e94<\/p>\n

\r\n\u65b0\u8282\u70b9\u52a0\u5165\uff0c\u65e0\u4efb\u4f55oplog\uff0c\u6b64\u65f6\u9700\u5148\u8fdb\u6027initial sync\u3002\r\n\r\ninitial sync\u5f00\u59cb\u65f6\uff0c\u4f1a\u4e3b\u52a8\u5c06_initialSyncFlag\u5b57\u6bb5\u8bbe\u7f6e\u4e3atrue\uff0c\u6b63\u5e38\u7ed3\u675f\u540e\u518d\u8bbe\u7f6e\u4e3afalse\uff1b\u5982\u679c\u8282\u70b9\u91cd\u542f\u65f6\uff0c\u53d1\u73b0_initialSyncFlag\u4e3atrue\uff0c\u8bf4\u660e\u4e0a\u6b21\u5168\u91cf\u540c\u6b65\u4e2d\u9014\u5931\u8d25\u4e86\uff0c\u6b64\u65f6\u5e94\u8be5\u91cd\u65b0\u8fdb\u884cinitial sync\u3002\r\n\r\n\u5f53\u7528\u6237\u53d1\u9001resync\u547d\u4ee4\u65f6\uff0cinitialSyncRequested\u4f1a\u8bbe\u7f6e\u4e3atrue\uff0c\u6b64\u65f6\u4f1a\u91cd\u65b0\u5f00\u59cb\u4e00\u6b21initial sync\u3002\r\n<\/pre>\n
intial sync\u6d41\u7a0b<\/strong><\/span><\/div>\n
\r\n\u5168\u91cf\u540c\u6b65\u5f00\u59cb\uff0c\u8bbe\u7f6eminvalid\u96c6\u5408\u7684_initialSyncFlag\u3002\r\n\u83b7\u53d6\u540c\u6b65\u6e90\u4e0a\u6700\u65b0oplog\u65f6\u95f4\u6233\u4e3at1\u3002\r\n\u5168\u91cf\u540c\u6b65\u96c6\u5408\u6570\u636e \uff08\u8017\u65f6\uff09\u3002\r\n\u83b7\u53d6\u540c\u6b65\u6e90\u4e0a\u6700\u65b0oplog\u65f6\u95f4\u6233\u4e3at2\u3002\r\n\u91cd\u653e[t1, t2]\u8303\u56f4\u5185\u7684\u6240\u6709oplog\u3002\r\n\u83b7\u53d6\u540c\u6b65\u6e90\u4e0a\u6700\u65b0oplog\u65f6\u95f4\u6233\u4e3at3\u3002\r\n\u91cd\u653e[t2, t3]\u8303\u56f4\u5185\u6240\u6709\u7684oplog\u3002\r\n\u5efa\u7acb\u96c6\u5408\u6240\u6709\u7d22\u5f15 \uff08\u8017\u65f6\uff09\u3002\r\n\u83b7\u53d6\u540c\u6b65\u6e90\u4e0a\u6700\u65b0oplog\u65f6\u95f4\u6233\u4e3at4\u3002\r\n\u91cd\u653e[t3, t4]\u8303\u56f4\u5185\u6240\u6709\u7684oplog\u3002\r\n\u5168\u91cf\u540c\u6b65\u7ed3\u675f\uff0c\u6e05\u9664minvalid\u96c6\u5408\u7684_initialSyncFlag\u3002\r\n<\/pre>\n
Replication<\/strong><\/span><\/div>\n

initial sync\u7ed3\u675f\u540e\uff0c\u63a5\u4e0b\u6765Secondary\u5c31\u4f1a\u300e\u4e0d\u65ad\u62c9\u53d6\u4e3b\u4e0a\u65b0\u4ea7\u751f\u7684oplog\u5e76\u91cd\u653e\u300f\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5728Secondary\u540c\u6b65\u6162\u95ee\u9898\u5206\u6790\u4e5f\u4ecb\u7ecd\u8fc7\uff0c\u8fd9\u91cc\u4ece\u53e6\u4e00\u4e2a\u89d2\u5ea6\u518d\u5206\u6790\u4e0b\u3002<\/p>\n

\"\"<\/p>\n

producer thread\uff0c\u8fd9\u4e2a\u7ebf\u7a0b\u4e0d\u65ad\u7684\u4ece\u540c\u6b65\u6e90\u4e0a\u62c9\u53d6oplog\uff0c\u5e76\u52a0\u5165\u5230\u4e00\u4e2aBlockQueue\u7684\u961f\u5217\u91cc\u4fdd\u5b58\u7740\u3002<\/p>\n

replBatcher thread\uff0c\u8fd9\u4e2a\u7ebf\u7a0b\u8d1f\u8d23\u9010\u4e2a\u4eceproducer thread\u7684\u961f\u5217\u91cc\u53d6\u51faoplog\uff0c\u5e76\u653e\u5230\u81ea\u5df1\u7ef4\u62a4\u7684\u961f\u5217\u91cc\u3002<\/p>\n

sync\u7ebf\u7a0b\u5c06replBatcher thread\u7684\u961f\u5217\u5206\u53d1\u5230\u9ed8\u8ba416\u4e2areplWriter\u7ebf\u7a0b\uff0c\u7531replWriter thread\u6765\u6700\u7ec8\u91cd\u653e\u6bcf\u6761oplog\u3002<\/p>\n

\u95ee\u9898\u6765\u4e86\uff0c\u4e3a\u4ec0\u4e48\u4e00\u4e2a\u7b80\u5355\u7684\u300e\u62c9\u53d6oplog\u5e76\u91cd\u653e\u300f\u7684\u52a8\u4f5c\u8981\u641e\u5f97\u8fd9\u4e48\u590d\u6742\uff1f<\/p>\n

\u6027\u80fd\u8003\u8651\uff0c\u62c9\u53d6oplog\u662f\u5355\u7ebf\u7a0b\u8fdb\u884c\uff0c\u5982\u679c\u628a\u91cd\u653e\u4e5f\u653e\u5230\u62c9\u53d6\u7684\u7ebf\u7a0b\u91cc\uff0c\u540c\u6b65\u52bf\u5fc5\u4f1a\u5f88\u6162\uff1b\u6240\u4ee5\u8bbe\u8ba1\u4e0aproducer thread\u53ea\u5e72\u4e00\u4ef6\u4e8b\u3002<\/p>\n

\u4e3a\u4ec0\u4e48\u4e0d\u5c06\u62c9\u53d6\u7684oplog\u76f4\u63a5\u5206\u53d1\u7ed9replWriter thread\uff0c\u800c\u8981\u591a\u4e00\u4e2areplBatcher\u7ebf\u7a0b\u6765\u4e2d\u8f6c\uff1f<\/p>\n

oplog\u91cd\u653e\u65f6\uff0c\u8981\u4fdd\u6301\u987a\u5e8f\u6027\uff0c\u800c\u4e14\u9047\u5230createCollection\u3001dropCollection\u7b49DDL\u547d\u4ee4\u65f6\uff0c\u8fd9\u4e9b\u547d\u4ee4\u4e0e\u5176\u4ed6\u7684\u589e\u5220\u6539\u67e5\u547d\u4ee4\u662f\u4e0d\u80fd\u5e76\u884c\u6267\u884c\u7684\uff0c\u800c\u8fd9\u4e9b\u63a7\u5236\u5c31\u662f\u7531replBatcher\u6765\u5b8c\u6210\u7684\u3002<\/p>\n

\u6ce8\u610f\u4e8b\u9879<\/strong><\/span><\/div>\n

initial sync\u5355\u7ebf\u7a0b\u590d\u5236\u6570\u636e\uff0c\u6548\u7387\u6bd4\u8f83\u4f4e\uff0c\u751f\u4ea7\u73af\u5883\u5e94\u8be5\u5c3d\u91cf\u907f\u514dinitial sync\u51fa\u73b0\uff0c\u9700\u5408\u7406\u914d\u7f6eoplog\uff0c\u6309\u9ed8\u8ba4\u300e5%\u7684\u53ef\u7528\u78c1\u76d8\u7a7a\u95f4\u300f\u6765\u914d\u7f6eoplog\u5728\u7edd\u5927\u90e8\u5206\u573a\u666f\u4e0b\u90fd\u80fd\u6ee1\u8db3\u9700\u6c42\uff0c\u7279\u6b8a\u7684case(case1, case2)\u53ef\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8bbe\u7f6e\u66f4\u5927\u7684oplog\u3002<\/p>\n

\u65b0\u52a0\u5165\u8282\u70b9\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u7269\u7406\u590d\u5236\u7684\u65b9\u5f0f\u6765\u907f\u514dinitial sync\uff0c\u5c06Primary\u4e0a\u7684dbpath\u62f7\u8d1d\u5230\u65b0\u7684\u8282\u70b9\uff0c\u76f4\u63a5\u542f\u52a8\uff0c\u8fd9\u6837\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n

\u5f53Secondary\u4e0a\u9700\u8981\u7684oplog\u5728\u540c\u6b65\u6e90\u4e0a\u5df2\u7ecf\u6eda\u6389\u65f6\uff0cSecondary\u7684\u540c\u6b65\u5c06\u65e0\u6cd5\u6b63\u5e38\u8fdb\u884c\uff0c\u4f1a\u8fdb\u5165RECOVERING\u7684\u72b6\u6001\uff0c\u9700\u5411Secondary\u4e3b\u52a8\u53d1\u9001resyc\u547d\u4ee4\u91cd\u65b0\u540c\u6b65\u30023.2\u7248\u672c\u76ee\u524d\u6709\u4e2abug\uff0c\u53ef\u80fd\u5bfc\u81f4resync\u4e0d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u5fc5\u987b\u5f3a\u5236(kill -9)\u91cd\u542f\u8282\u70b9\uff0c\u8be6\u60c5\u53c2\u8003SERVER-24773\u3002<\/p>\n

\u751f\u4ea7\u73af\u5883\uff0c\u6700\u597d\u901a\u8fc7db.printSlaveReplicationInfo()\u6765\u76d1\u63a7\u4e3b\u5907\u540c\u6b65\u6ede\u540e\u7684\u60c5\u51b5\uff0c\u5f53Secondary\u843d\u540e\u592a\u591a\u65f6\uff0c\u8981\u53ca\u65f6\u8c03\u67e5\u6e05\u695a\u539f\u56e0\u3002<\/p>\n

\u5f53Secondary\u540c\u6b65\u6ede\u540e\u662f\u56e0\u4e3a\u4e3b\u4e0a\u5e76\u53d1\u5199\u5165\u592a\u9ad8\u5bfc\u81f4\uff0c\uff08db.serverStatus().metrics.repl.buffer.sizeBytes\u6301\u7eed\u63a5\u8fd1db.serverStatus().metrics.repl.buffer.maxSizeBytes\uff09\uff0c\u53ef\u901a\u8fc7\u8c03\u6574Secondary\u4e0areplWriter\u5e76\u53d1\u7ebf\u7a0b\u6570\u6765\u63d0\u5347\u3002<\/p>\n

MongoDB 3.4\u590d\u5236\u96c6\u5168\u91cf\u540c\u6b65\u6539\u8fdb<\/strong><\/div>\n

MongoDB 3.2\u7248\u672c\u590d\u5236\u96c6\u540c\u6b65\u7684\u8fc7\u7a0b\u53c2\u8003\u4e0a\u9762\uff0c\u5728MongoDB 3.4\u7248\u672c\u91ccMongoDB\u5bf9\u590d\u5236\u96c6\u540c\u6b65\u7684\u5168\u91cf\u540c\u6b65\u9636\u6bb5\u505a\u4e862\u4e2a\u6539\u8fdb\uff1a<\/p>\n

\u5728\u62f7\u8d1d\u6570\u636e\u7684\u65f6\u5019\u540c\u65f6\u5efa\u7acb\u6240\u6709\u7684\u7d22\u5f15\uff0c\u5728\u4e4b\u524d\u7684\u7248\u672c\u91cc\uff0c\u62f7\u8d1d\u6570\u636e\u65f6\u4f1a\u5148\u5efa\u7acb_id\u7d22\u5f15\uff0c\u5176\u4f59\u7684\u7d22\u5f15\u5728\u6570\u636e\u62f7\u8d1d\u5b8c\u4e4b\u540e\u96c6\u4e2d\u5efa\u7acb\u3002<\/p>\n

\u5728\u62f7\u8d1d\u6570\u636e\u7684\u540c\u65f6\uff0c\u4f1a\u628a\u540c\u6b65\u6e90\u4e0a\u65b0\u4ea7\u751f\u7684oplog\u62c9\u53d6\u5230\u672c\u5730local\u6570\u636e\u5e93\u7684\u4e34\u65f6\u96c6\u5408\u5b58\u50a8\u7740\uff0c\u7b49\u6570\u636e\u5168\u91cf\u62f7\u8d1d\u5b8c\uff0c\u76f4\u63a5\u8bfb\u53d6\u672c\u5730\u4e34\u65f6\u96c6\u5408\u7684oplog\u6765\u5e94\u7528\uff0c\u63d0\u5347\u4e86\u8ffd\u589e\u91cf\u7684\u6548\u7387\uff0c\u540c\u65f6\u4e5f\u907f\u514d\u4e86\u540c\u6b65\u6e90\u4e0aoplog\u4e0d\u8db3\u5bfc\u81f4\u65e0\u6cd5\u540c\u6b65\u7684\u95ee\u9898\u3002<\/p>\n

\"\"<\/p>\n

\u4e0a\u56fe\u63cf\u8ff0\u4e86\u8fd92\u4e2a\u6539\u8fdb\u7684\u6548\u679c\uff0c\u5b9e\u6d4b\u4e86\u300e10GB\u7684\u6570\u636e\uff0c\u5305\u542b64\u4e2a\u96c6\u5408\uff0c\u6bcf\u4e2a\u96c6\u5408\u5305\u542b2\u4e2a\u7d22\u5f15\u5b57\u6bb5\uff0c\u6587\u6863\u5e73\u57471KB\uff0c3.4\u7248\u672c\u7684\u5168\u91cf\u540c\u6b65\u6027\u80fd\u7ea6\u670920%\u7684\u63d0\u5347\uff0c\u5982\u679c\u6570\u636e\u96c6\u5f88\u5927\uff0c\u5e76\u4e14\u5728\u540c\u6b65\u7684\u8fc7\u7a0b\u4e2d\u6709\u5199\u5165\uff0c\u63d0\u5347\u7684\u6548\u679c\u4f1a\u66f4\u660e\u663e\uff0c\u5e76\u4e14\u5f7b\u5e95\u89e3\u51b3\u4e86\u56e0\u540c\u6b65\u6e90oplog\u4e0d\u8db3\u800c\u5bfc\u81f4\u8fdb\u5165RECOVERING\u72b6\u6001\u65e0\u6cd5\u540c\u6b65\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

intial sync\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u5168\u91cf\u540c\u6b65\u3002 replication\uff0c\u8ffd\u540c\u6b65\u6e90\u7684oplog\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u589e\u91cf\u540c\u6b65 […]<\/p>\n","protected":false},"author":1479,"featured_media":95922,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-131208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=131208"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131208\/revisions"}],"predecessor-version":[{"id":133062,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/131208\/revisions\/133062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/95922"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=131208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=131208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=131208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}