Permalink
Browse files

added explicit read/write consistencies. columncontainer now uses the…

… model name as default if none defined
  • Loading branch information...
1 parent bbfbd50 commit 9c407113593bfe30d03ee6a4546e66f07f9d3ea9 @mjpearson committed Jul 13, 2010
Showing with 35 additions and 8 deletions.
  1. +6 −2 lib/ColumnContainer.class.php
  2. +29 −6 lib/Core.class.php
View
8 lib/ColumnContainer.class.php
@@ -86,8 +86,12 @@ public function __construct($keyID = NULL, $keySpace = NULL, $name = NULL, $cont
if ($containerType !== NULL) $this->setType($containerType);
if ($keyID !== NULL) $this->setKeyID($keyID);
if ($keySpace !== NULL) $this->setKeySpace($keySpace);
- if ($name !== NULL) $this->setName($name);
-
+ if ($name !== NULL) {
+ $this->setName($name);
+ } else if ($name === NULL && $this->getName() === NULL) {
+ // Fall back to the class name
+ $this->setName(get_class($this));
+ }
}
/**
View
35 lib/Core.class.php
@@ -24,8 +24,11 @@ class PandraCore {
/* @var string Last internal error */
static public $lastError = '';
- /* @var int default consistency level */
- static private $_consistencyLevel = cassandra_ConsistencyLevel::ONE;
+ /* @var int default write consistency level */
+ static private $_consistencyLevelWrite = cassandra_ConsistencyLevel::ONE;
+
+ /* @var int default read consistency level */
+ static private $_consistencyLevelRead = cassandra_ConsistencyLevel::ONE;
/* @var string currently selected node */
static private $_activePool = NULL;
@@ -48,6 +51,12 @@ class PandraCore {
/* @var int default write mode (active/round/random) */
static private $writeMode = self::MODE_RANDOM;
+ static private $_supportedReadConsistency = array(
+ cassandra_ConsistencyLevel::ONE,
+ cassandra_ConsistencyLevel::QUORUM,
+ cassandra_ConsistencyLevel::ALL
+ );
+
/* @var supported modes for this core version */
static private $_supportedModes = array(
self::MODE_ACTIVE,
@@ -326,6 +335,7 @@ static public function connectBySeed($host, $poolName = self::DEFAULT_POOL_NAME,
new TBinaryProtocolAccelerated($transport) :
new TBinaryProtocol($transport)));
+ // @todo this has been deprecated by 'describe_ring' 0.6.3
$tokenMap = $client->get_string_property('token map');
$transport->close();
unset($transport); unset($client);
@@ -498,23 +508,34 @@ static public function describeKeyspace($keySpace) {
/**
* consistency accessor
* @param int $consistencyLevel overrides the return, or returns default if NULL
+ * @param bool $readMode optional return the read mode consistency (default write)
* @return int consistency level
*/
- static public function getConsistency($consistencyLevel = NULL) {
- $consistency = self::$_consistencyLevel;
+ static public function getConsistency($consistencyLevel = NULL, $readMode = FALSE) {
+ $consistency = ($readMode) ? self::$_consistencyLevelRead : self::$_consistencyLevelWrite;
if ($consistencyLevel !== NULL) {
$consistency = $consistencyLevel;
}
+ // warn devs they should be setting proper consistency
+ if ($readMode && !in_array($consistencyLevel, self::$_supportedReadConsistency)) {
+ self::registerError("Unsupported Read Consistency", PandraLog::LOG_WARNING);
+ }
+
return $consistency;
}
/**
* consistency mutator
* @param int $consistencyLevel new consistency level
+ * @param bool $readMode optional set read consistency (default write)
*/
- static public function setConsistency($consistencyLevel) {
- self::$_consistencyLevel = $consistencyLevel;
+ static public function setConsistency($consistencyLevel, $readMode = FALSE) {
+ if ($readMode) {
+ self::$_consistencyLevelRead = $consistencyLevel;
+ } else {
+ self::$_consistencyLevelWrite = $consistencyLevel;
+ }
}
/**
@@ -758,6 +779,8 @@ static public function getColumnPath($keySpace,
$consistencyLevel = NULL) {
$client = self::getClient();
+
+
try {
return $client->get($keySpace, $keyID, $columnPath, self::getConsistency($consistencyLevel));
} catch (TException $te) {

0 comments on commit 9c40711

Please sign in to comment.