2016-04-29 13 views
3

私はCouchBaseサーバーを持っています。 CouchBase例外です。ドキュメントに変異がありました

と疑問を持っている程度 同時文書変異:Couchbaseの中にセーブデータと http://developer.couchbase.com/documentation/server/4.0/developer-guide/cas-concurrency.html


コード例:

try { 
    Yii::$app->Couch->set($key, $data, 0, '', 1); 

} catch (\Exception $e) { 

    $already_saved = Yii::$app->Couch->get($key); 

    Yii::$app->Logger->alert(
     'CouchBase exception', 
     [ 
      'exception' => $e->getMessage(), 
      'key' => $key, 
      'need_saved' => $data, 
      'already_saved' => $already_saved, 
      'equal' => md5($already_saved)==md5(json_encode($data)) 
     ] 
    ); 
} 

/** 
* Store a document in the cluster. 
* 
* The set operation stores a document in the cluster. It differs from 
* add and replace in that it does not care for the presence of 
* the identifier in the cluster. 
* 
* If the $cas field is specified, set will <b>only</b> succeed if the 
* identifier exists in the cluster with the <b>exact</b> same cas value 
* as the one specified in this request. 
* 
* @param string $id the identifier to store the document under 
* @param object|string $document the document to store 
* @param integer $expiry the lifetime of the document (0 == infinite) 
* @param string $cas a cas identifier to restrict the store operation 
* @param integer $persist_to wait until the document is persisted to (at least) 
*       this many nodes 
* @param integer $replicate_to wait until the document is replicated to (at least) 
*       this many nodes 
* @return string the cas value of the object if success 
* @throws CouchbaseException if an error occurs 
*/ 
function set($id, $document, $expiry = 0, $cas = "", $persist_to = 0, $replicate_to = 0) { 

} 

しかし、0.002%未満から私が受け取るすべてのメッセージ例外:

CouchBase例外。その文書は突然変異した。

ドキュメントでこれを検索:

は、CASは、比較とスワップの頭字語であり、かつ 楽観的ロックの形として知られています。 CASは、アプリケーションによって 突然変異操作(挿入、アップサート、置換)に供給することができます。 2 CAS値が一致する(彼らが正常に比較)、その後、突然変異操作が成功した場合

  • :アプリケーション はCASを提供する場合、サーバはCASの独自のバージョンに対する CASのアプリケーションが提供するバージョンを確認します。

  • 2つのCASの値が異なる場合には、突然変異操作は


を失敗した。しかし、まだこの変異が何を意味するのか、理解できないのですか?

  • CAS値が一致するならば、なぜ、その変異操作は成功し、それだけでメッセージデータを書き換えないのですか?

  • なぜ値が異なる場合、突然変異操作は失敗するのですか?

  • なぜこの例外が表示されますか?

+0

誰でも助けてくれますか? –

+0

誰も知っていますか? –

答えて

0

あなたは文書を記述する「リビジョン番号」としてCASについて考えることができますが、これらの「リビジョン番号が」注文されていない、次の2つのリビジョンが同じかそうでない場合にのみ伝えることができました。ドキュメントを変更するたびに、サーバは新しいCAS値を生成します(同じ内容の本文を書き換えたり、有効期限を設定したり、鍵をロックしたとしても)。

文書が変更されたときにCASの不一致エラーが発生することがありますが、内容は同じですが、CASなしで本文からmd5を計算する方法から推測できます。

関連する問題