MongoDB 等待複製超時
为情所困
为情所困 2017-04-28 09:06:14
0
0
1621
  1. 問題描述
    三台Windows Server 2012 R2 安裝MongoDB 3.0.8 做複製集,批次upsert有時報「waiting for replication timed out(64):stdClass::__set_state(array('wtimeout' => true)) ” 錯誤。

  2. 相關代碼

$mongoManager = new MongoDB\Driver\Manager( 'mongodb://test:test123@192.168.100.101:27017,192.168.100.102:27017,192.168.100.103:27017/test' ); $mongoWriteConcern = new MongoDB\Driver\WriteConcern( MongoDB\Driver\WriteConcern :: MAJORITY, 1000 ); $bulk = new MongoDB\Driver\BulkWrite(); foreach( $data as $i ) { $i = (array)$i; $bulk->update( array('unique' => $i['unique']), array('$set' => $i), array('upsert' => true, 'multi' => true) ); } try { $mongoResult = $mongoManager->executeBulkWrite( 'test.data', $bulk, $mongoWriteConcern ); } catch ( MongoDB\Driver\Exception\BulkWriteException $e ) { $mongoResult = $e->getWriteResult(); // Check if the write concern could not be fulfilled if ( $writeConcernError = $mongoResult->getWriteConcernError() ) { printf( "%s(%d):%s\n", $writeConcernError->getMessage(), $writeConcernError->getCode(), var_export( $writeConcernError->getInfo(), true ) ); } // Check if any write operations did not complete at all foreach ( $mongoResult->getWriteErrors() as $writeError ) { printf( "Write #%d:%s(%d)\n", $writeError->getIndex(), $writeError->getMessage(), $writeError->getCode() ); } } catch ( MongoDB\Driver\Exception\Exception $e ) { printf( "Other errors:%s\n", $e->getMessage() ); }
  1. 報錯訊息

waiting for replication timed out(64):stdClass::__set_state(array( 'wtimeout' => true, ))
  1. 複製集資訊

test:PRIMARY> rs.status() { "set" : "test", "date" : ISODate("2016-01-19T01:01:09.279Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "192.168.100.101:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 57786, "optime" : Timestamp(1453165025, 125), "optimeDate" : ISODate("2016-01-19T00:57:05Z"), "electionTime" : Timestamp(1453108221, 1), "electionDate" : ISODate("2016-01-18T09:10:21Z"), "configVersion" : 2, "self" : true }, { "_id" : 1, "name" : "192.168.100.102:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 56945, "optime" : Timestamp(1453165025, 125), "optimeDate" : ISODate("2016-01-19T00:57:05Z"), "lastHeartbeat" : ISODate("2016-01-19T01:01:07.726Z"), "lastHeartbeatRecv" : ISODate("2016-01-19T01:01:08.781Z"), "pingMs" : 1, "syncingTo" : "192.168.100.101:27017", "configVersion" : 2 }, { "_id" : 2, "name" : "192.168.100.103:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 56018, "optime" : Timestamp(1453165025, 125), "optimeDate" : ISODate("2016-01-19T00:57:05Z"), "lastHeartbeat" : ISODate("2016-01-19T01:01:07.847Z"), "lastHeartbeatRecv" : ISODate("2016-01-19T01:01:07.581Z"), "pingMs" : 1, "syncingTo" : "192.168.100.101:27017", "configVersion" : 2 } ], "ok" : 1 }
为情所困
为情所困

全部回覆 (0)
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!