Permalink
Browse files

- batching flags for column update/deletes, columns can also be saved…

…/deleted individually based on parent ColumnFamily container

- new validator type definitions (bool, float, enum).
- round robin and random connection calls in getClient. added round-robin apc stub
- read/write mode config (active, random, round)
- refactored ColumnFamily towards polymorphic SuperColun container (can wrap ColumnFamilies and Columns congruent to Cassandra spec)
	towards data structures :
				  Keyspace > Key > ColumnFamily > Column(s)
				  Keyspace > Key > ColumnFamily > SuperColumn(s) [Column(s)]  and/or > Column(s)
				  Keyspace > Key > SuperColumn(s) > ColumnFamily > Column(s)
  • Loading branch information...
1 parent 930c671 commit 1ad0ba1b8a4cd59bb7f861b8541148e1570f4e31 @mjpearson committed Nov 25, 2009
Showing with 287 additions and 124 deletions.
  1. +11 −2 config.php
  2. +80 −7 lib/Column.class.php
  3. +79 −92 lib/ColumnFamily.class.php
  4. +66 −15 lib/Pandra.class.php
  5. +7 −0 lib/Slice.class.php
  6. +11 −0 lib/SuperColumn.class.php
  7. +33 −8 lib/Validator.class.php
View
@@ -18,7 +18,10 @@
The pandra homepage is :
http://www.phpgrease.net/projects/pandra
*/
-
+/**
+ *
+ * @package Pandra
+ */
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__).'/../thrift-php/';
require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/Cassandra.php';
@@ -27,10 +30,16 @@
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
+// Default Thrift port
define('PANDRA_PORT_DEFAULT', 9160);
+// read/write modes (can be configured independently)
+define('PANDRA_MODE_ACTIVE', 0); // Active client only
+define('PANDRA_MODE_ROUND', 1); // sequentially select configured clients
+define('PANDRA_MODE_ROUND_APC', 1); // sequentially select between interpreter instances w/APC
+define('PANDRA_MODE_RANDOM', 2); // select random node
+
function pandraAutoLoad($className) {
-// $className = strtolower($className);
if (!preg_match("/^pandra/i", $className)) return;
View
@@ -1,18 +1,46 @@
<?php
-
+/**
+ *
+ * @package Pandra
+ */
class PandraColumn {
-
+
+ /* @var string column name */
+ public $name = NULL;
+
+ /* @var string column value */
+ public $value = NULL;
+
+ /* @var int last changed timestamp */
+ public $timestamp = NULL;
+
+ /* @var array validator type definitions for this colun */
public $typeDef = array();
- public $lastError = array();
+ /* @var string last processing error */
+ public $lastError = NULL;
+ /* @var string callback function for this column pre-save */
public $callback = NULL;
- public $modified = FALSE;
+ /* @var bool column value has been modified since load() or init */
+ private $_modified = FALSE;
- public $name = NULL;
+ /* @var $delete column is marked for deletion */
+ private $_delete = FALSE;
- public $value = NULL;
+ /* @var PandraColumnFamily column family parent reference */
+ private $_parentCF = NULL;
+
+ public function __construct($name, &$parentCF) {
+ $this->name = $name;
+ $this->_parentCF = $parentCF;
+ }
+
+ public function bindTime($timeOverride = NULL) {
+ $this->timestamp = ($timeOverride === NULL) ? time() : $timeOverride;
+ return $timestamp;
+ }
public function setValue($value, $validate = TRUE) {
if ($validate && !empty($this->typeDef)) {
@@ -22,13 +50,58 @@ public function setValue($value, $validate = TRUE) {
}
$this->value = $value;
- $this->modified = TRUE;
+ $this->_modified = TRUE;
return TRUE;
}
+ public function reset() {
+ $this->_modified = FALSE;
+ $this->_delete = FALSE;
+ }
+
+ public function markDelete() {
+ $this->_delete = TRUE;
+ $this->_modified = TRUE;
+ }
+
public function callbackValue() {
$value = '';
eval('$value = '.$cObj->callback.'("'.$cObj->value.'");');
return $value;
}
+
+ public function save() {
+
+ if (!$this->_modified) return FALSE;
+
+ // @todo configurable consistency
+ $consistencyLevel = cassandra_ConsistencyLevel::ONE;
+
+ $this->_parentCF->checkCFState();
+
+ $client = Pandra::getClient(TRUE);
+
+ // build the column path
+ $columnPath = new cassandra_ColumnPath();
+ $columnPath->column_family = $this->_parentCF->columnFamily;
+ $columnPath->column = $this->name;
+
+ // @todo super writes
+ if ($this->_parentSuper !== NULL) {
+// $columnPath->super_column = $this->_parentSuper->name;
+ }
+
+ if ($this->_delete) {
+ $client->remove($this->_parentCF->keySpace, $this->_parentCF->keyID, $columnPath, $this->bindTime(), $consistencyLevel);
+ } else {
+ $client->insert($this->_parentCF->keySpace, $this->_parentCF->keyID, $columnPath, $this->value, $this->bindTime(), $consistencyLevel);
+ }
+
+ return TRUE;
+ }
+
+ public function delete() {
+ $this->markDelete();
+ $this->save();
+ }
}
Oops, something went wrong.

0 comments on commit 1ad0ba1

Please sign in to comment.