failedToEnsureDocumentSharding() 공개 정적인 메소드

public static failedToEnsureDocumentSharding ( string $className, string $errorMessage ) : MongoDBException
$className string
$errorMessage string
리턴 MongoDBException
예제 #1
0
 /**
  * Ensure sharding for collection by document name.
  *
  * @param string $documentName
  * @param array  $indexOptions Options for `ensureIndex` command. It's performed on an existing collections.
  *
  * @throws MongoDBException
  */
 public function ensureDocumentSharding($documentName, array $indexOptions = array())
 {
     $class = $this->dm->getClassMetadata($documentName);
     if (!$class->isSharded()) {
         return;
     }
     $this->enableShardingForDbByDocumentName($documentName);
     do {
         $result = $this->runShardCollectionCommand($documentName);
         $done = true;
         $try = 0;
         if ($result['ok'] != 1 && isset($result['proposedKey'])) {
             $this->dm->getDocumentCollection($documentName)->ensureIndex($result['proposedKey'], $indexOptions);
             $done = false;
             $try++;
         }
     } while (!$done && $try < 2);
     if ($result['ok'] != 1 && $result['errmsg'] !== 'already sharded') {
         throw MongoDBException::failedToEnsureDocumentSharding($documentName, $result['errmsg']);
     }
 }
예제 #2
0
 /**
  * Ensure sharding for collection by document name.
  *
  * @param string $documentName
  * @param array  $indexOptions Options for `ensureIndex` command. It's performed on an existing collections.
  *
  * @throws MongoDBException
  */
 public function ensureDocumentSharding($documentName, array $indexOptions = array())
 {
     $class = $this->dm->getClassMetadata($documentName);
     if (!$class->isSharded()) {
         return;
     }
     $this->enableShardingForDbByDocumentName($documentName);
     $try = 0;
     do {
         $result = $this->runShardCollectionCommand($documentName);
         $done = true;
         // Need to check error message because MongoDB 3.0 does not return a code for this error
         if ($result['ok'] != 1 && strpos($result['errmsg'], 'please create an index that starts') !== false) {
             // The proposed key is not returned when using mongo-php-adapter with ext-mongodb.
             // See https://github.com/mongodb/mongo-php-driver/issues/296 for details
             if (isset($result['proposedKey'])) {
                 $key = $result['proposedKey'];
             } else {
                 $key = $this->dm->getClassMetadata($documentName)->getShardKey()['keys'];
             }
             $this->dm->getDocumentCollection($documentName)->ensureIndex($key, $indexOptions);
             $done = false;
             $try++;
         }
     } while (!$done && $try < 2);
     // Starting with MongoDB 3.2, this command returns code 20 when a collection is already sharded.
     // For older MongoDB versions, check the error message
     if ($result['ok'] == 1 || isset($result['code']) && $result['code'] == 20 || $result['errmsg'] == 'already sharded') {
         return;
     }
     throw MongoDBException::failedToEnsureDocumentSharding($documentName, $result['errmsg']);
 }