{"id":21832,"date":"2024-01-02T16:03:27","date_gmt":"2024-01-02T16:03:27","guid":{"rendered":"https:\/\/server.hk\/blog\/21832\/"},"modified":"2024-11-14T10:26:22","modified_gmt":"2024-11-14T02:26:22","slug":"how-to-fix-mongodb-error-code-250-stalechunkhistory","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21832\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3 MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-250-stalechunkhistory-wROWjHQqdS\">\u5982\u4f55\u89e3\u51b3 MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory<\/h1>\n<p>MongoDB \u662f\u4e00\u6b3e\u6d41\u884c\u7684 NoSQL \u6570\u636e\u5e93\uff0c\u63d0\u4f9b\u9ad8\u5ea6\u7684\u53ef\u6269\u5c55\u6027\u548c\u7075\u6d3b\u6027\u3002\u7136\u800c\uff0c\u50cf\u4efb\u4f55\u5176\u4ed6\u8f6f\u4ef6\u4e00\u6837\uff0c\u5b83\u53ef\u80fd\u4f1a\u9047\u5230\u9700\u8981\u89e3\u51b3\u7684\u9519\u8bef\u3002\u5176\u4e2d\u4e00\u4e2a\u9519\u8bef\u5c31\u662f MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u8fd9\u4e2a\u9519\u8bef\u7684\u542b\u4e49\u4ee5\u53ca\u5982\u4f55\u4fee\u590d\u5b83\u3002<\/p>\n<h2 id=\"understanding-mongodb-error-code-250-stalechunkhistory-wROWjHQqdS\">\u7406\u89e3 MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory<\/h2>\n<p>MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory \u662f\u6307\u5206\u7247\u96c6\u7fa4\u4e2d\u6709\u5173\u5206\u5757\u7684\u5143\u6570\u636e\u53d8\u5f97\u4e0d\u4e00\u81f4\u6216\u8fc7\u65f6\u3002\u8fd9\u79cd\u4e0d\u4e00\u81f4\u53ef\u80fd\u7531\u5404\u79cd\u539f\u56e0\u5f15\u8d77\uff0c\u5982\u7f51\u7edc\u95ee\u9898\u3001\u786c\u4ef6\u6545\u969c\u6216\u4e0d\u5f53\u7684\u914d\u7f6e\u66f4\u6539\u3002<\/p>\n<p>\u5f53\u51fa\u73b0\u6b64\u9519\u8bef\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u5206\u7247\u96c6\u7fa4\u4e2d\u7684\u6570\u636e\u5206\u5e03\u548c\u5e73\u8861\u65b9\u9762\u7684\u95ee\u9898\u3002\u8fd9\u53ef\u80fd\u5bfc\u81f4\u67e5\u8be2\u6027\u80fd\u4e0b\u964d\uff0c\u5e76\u4e14\u5982\u679c\u4e0d\u53ca\u65f6\u89e3\u51b3\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u3002<\/p>\n<h2 id=\"steps-to-fix-mongodb-error-code-250-stalechunkhistory-wROWjHQqdS\">\u4fee\u590d MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory \u7684\u6b65\u9aa4<\/h2>\n<p>\u4fee\u590d MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory \u9700\u8981\u4e00\u7cfb\u5217\u6b65\u9aa4\u6765\u8bc6\u522b\u5e76\u89e3\u51b3\u6f5c\u5728\u539f\u56e0\u3002\u4ee5\u4e0b\u662f\u9010\u6b65\u6307\u5357\uff1a<\/p>\n<h3 id=\"step-1-identify-affected-shards-wROWjHQqdS\">\u6b65\u9aa4 1\uff1a\u786e\u5b9a\u53d7\u5f71\u54cd\u7684\u5206\u7247<\/h3>\n<p>\u9996\u5148\uff0c\u8981\u786e\u5b9a\u53d7\u5230 StaleChunkHistory \u9519\u8bef\u5f71\u54cd\u7684\u5206\u7247\u3002\u60a8\u53ef\u4ee5\u8fde\u63a5\u5230 MongoDB \u96c6\u7fa4\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>use config\r\ndb.shards.find({ \"staleEpoch\": { $exists: true } })\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u5217\u51fa\u6240\u6709\u5177\u6709\u8fc7\u65f6\u5206\u5757\u5386\u53f2\u8bb0\u5f55\u7684\u5206\u7247\u3002\u8bb0\u4e0b\u53d7\u5f71\u54cd\u7684\u5206\u7247\u4ee5\u8fdb\u884c\u8fdb\u4e00\u6b65\u6545\u969c\u6392\u9664\u3002<\/p>\n<h3 id=\"step-2-restart-affected-shards-wROWjHQqdS\">\u6b65\u9aa4 2\uff1a\u91cd\u65b0\u542f\u52a8\u53d7\u5f71\u54cd\u7684\u5206\u7247<\/h3>\n<p>\u786e\u5b9a\u4e86\u53d7\u5f71\u54cd\u7684\u5206\u7247\u540e\uff0c\u4e0b\u4e00\u6b65\u662f\u91cd\u65b0\u542f\u52a8\u5b83\u4eec\u3002\u91cd\u65b0\u542f\u52a8\u5206\u7247\u5c06\u6709\u52a9\u4e8e\u5237\u65b0\u5143\u6570\u636e\u5e76\u89e3\u51b3\u4efb\u4f55\u4e0d\u4e00\u81f4\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u91cd\u65b0\u542f\u52a8\u5206\u7247\uff1a<\/p>\n<pre><code>use admin\r\ndb.runCommand({ \"replSetStepDown\": 1, \"force\": true })\r\n<\/code><\/pre>\n<p>\u5bf9\u96c6\u7fa4\u4e2d\u7684\u6bcf\u4e2a\u53d7\u5f71\u54cd\u7684\u5206\u7247\u91cd\u590d\u6b64\u6b65\u9aa4\u3002<\/p>\n<h3 id=\"step-3-verify-shard-status-wROWjHQqdS\">\u6b65\u9aa4 3\uff1a\u9a8c\u8bc1\u5206\u7247\u72b6\u6001<\/h3>\n<p>\u91cd\u65b0\u542f\u52a8\u53d7\u5f71\u54cd\u7684\u5206\u7247\u540e\uff0c\u60a8\u9700\u8981\u9a8c\u8bc1\u5b83\u4eec\u7684\u72b6\u6001\u4ee5\u786e\u4fdd\u5176\u6b63\u5e38\u8fd0\u884c\u3002\u8fde\u63a5\u5230\u6bcf\u4e2a\u5206\u7247\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>use admin\r\ndb.runCommand({ \"replSetGetStatus\": 1 })\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u663e\u793a\u5206\u7247\u526f\u672c\u96c6\u7684\u72b6\u6001\u3002\u786e\u4fdd\u6240\u6709\u5206\u7247\u5728&#8221;PRIMARY&#8221;\u72b6\u6001\u4e0b\uff0c\u7136\u540e\u624d\u8fdb\u884c\u4e0b\u4e00\u6b65\u3002<\/p>\n<h3 id=\"step-4-trigger-chunk-migration-wROWjHQqdS\">\u6b65\u9aa4 4\uff1a\u89e6\u53d1\u5206\u5757\u8fc1\u79fb<\/h3>\n<p>\u4e00\u65e6\u5206\u7247\u6062\u590d\u5728\u7ebf\u5e76\u6b63\u5e38\u8fd0\u884c\uff0c\u60a8\u53ef\u4ee5\u89e6\u53d1\u5206\u5757\u8fc1\u79fb\u8fc7\u7a0b\uff0c\u5c06\u6570\u636e\u5747\u5300\u5730\u91cd\u65b0\u5206\u5e03\u5230\u96c6\u7fa4\u4e2d\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8\u8fc1\u79fb\uff1a<\/p>\n<pre><code>use admin\r\ndb.runCommand({ \"balancerStart\": 1 })\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u542f\u52a8\u5e73\u8861\u5668\u8fc7\u7a0b\uff0c\u5b83\u5c06\u81ea\u52a8\u79fb\u52a8\u5206\u5757\u4ee5\u5b9e\u73b0\u6570\u636e\u7684\u5e73\u8861\u5206\u5e03\u3002<\/p>\n<h3 id=\"step-5-monitor-the-balancing-process-wROWjHQqdS\">\u6b65\u9aa4 5\uff1a\u76d1\u63a7\u5e73\u8861\u8fc7\u7a0b<\/h3>\n<p>\u76d1\u63a7\u5e73\u8861\u8fc7\u7a0b\u975e\u5e38\u91cd\u8981\uff0c\u4ee5\u786e\u4fdd\u5176\u6210\u529f\u5b8c\u6210\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5\u8fdb\u5ea6\uff1a<\/p>\n<pre><code>use config\r\ndb.balancer.find()\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u663e\u793a\u5e73\u8861\u8fc7\u7a0b\u7684\u72b6\u6001\u3002\u7b49\u5f85\u8fc7\u7a0b\u5b8c\u6210\uff0c\u786e\u4fdd\u6240\u6709\u5206\u5757\u5747\u5300\u5730\u5206\u5e03\u5728\u5404\u4e2a\u5206\u7247\u4e0a\u3002<\/p>\n<h2 id=\"summary-wROWjHQqdS\">\u603b\u7ed3<\/h2>\n<p>MongoDB \u9519\u8bef\u4ee3\u7801 &#8211; 250 &#8211; StaleChunkHistory \u53ef\u80fd\u4f1a\u5f71\u54cd\u5206\u7247\u96c6\u7fa4\u7684\u6027\u80fd\u548c\u6570\u636e\u5206\u5e03\u3002\u9075\u5faa\u672c\u6587\u4e2d\u6982\u8ff0\u7684\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u6b64\u9519\u8bef\uff0c\u5e76\u6062\u590d MongoDB \u90e8\u7f72\u7684\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>\u5982\u9700\u53ef\u9760\u4e14\u9ad8\u6027\u80fd\u7684 VPS \u4e3b\u673a\u89e3\u51b3\u65b9\u6848\uff0c\u8bf7\u8003\u8651\u8bbf\u95ee <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u901a\u8fc7\u6211\u4eec\u4e00\u6d41\u7684\u57fa\u7840\u8bbe\u65bd\u548c\u51fa\u8272\u7684\u652f\u6301\uff0c\u6211\u4eec\u786e\u4fdd\u60a8\u7684 MongoDB \u548c\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u987a\u7545\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3 MongoDB \u9519\u8bef\u4ee3&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-21832","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=21832"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21832\/revisions"}],"predecessor-version":[{"id":23522,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21832\/revisions\/23522"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}