Skip to content

Commit

Permalink
moved extra loggers to pandra-contrib repo, columncontainer cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpearson committed Jul 14, 2010
1 parent 1bc509b commit 59719b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 228 deletions.
49 changes: 26 additions & 23 deletions lib/ColumnContainer.class.php
Expand Up @@ -437,9 +437,8 @@ public function getReversed() {
}

private function _setStartFinish($value, $attrib = '_start') {
if (($this->_containerType == self::TYPE_UUID) ) {
$this->$attrib = $this->typeConvert($value, self::CONTEXT_BIN);
} elseif (($this->_containerType == self::TYPE_LONG)) {
if ($this->_containerType == self::TYPE_UUID ||
$this->_containerType == self::TYPE_LONG) {
$this->$attrib = $this->typeConvert($value, self::CONTEXT_BIN);
} else {
$this->$attrib = $value;
Expand Down Expand Up @@ -475,21 +474,25 @@ public function getFinish() {
/**
* Converts the given column name to it's expected container type context (UUID or String)
*
* This stub can also potentially handle long and utf8 cf types
* This stub can also potentially handle utf8 cf types
*
* @param string $columnName column name
* @param int $toFmt convert to type CONTEXT_BIN OR CONTEXT_STRING
* @return mixed converted column name
*/
protected function typeConvert($columnName, $toFmt) {
// @todo move to generic helper
$bin = UUID::isBinary($columnName);

if (($this->_containerType == self::TYPE_UUID) ) {
// Save accidental double-conversions on binaries
if (($bin && $toFmt == self::CONTEXT_BIN) ||
(!$bin && $toFmt == self::CONTEXT_STRING)) {
// Save accidental double-conversions on binaries
if (($bin && $toFmt == self::CONTEXT_BIN) ||
(!$bin && $toFmt == self::CONTEXT_STRING)) {
return $columnName;
} elseif (!$bin && !UUID::validUUID($columnName)) {
}

if (($this->_containerType == self::TYPE_UUID) ) {

if (!$bin && !UUID::validUUID($columnName)) {
throw new RuntimeException('Column Name ('.$columnName.') cannot be converted');
}

Expand All @@ -500,20 +503,16 @@ protected function typeConvert($columnName, $toFmt) {
}

} else if ($this->_containerType == self::TYPE_LONG) {
// Save accidental double-conversions on binaries
if (($bin && $toFmt == self::CONTEXT_BIN) ||
(!$bin && $toFmt == self::CONTEXT_STRING)) {
return $columnName;

// unpack the long
} elseif ($bin && $toFmt == self::CONTEXT_STRING) {
// unpack the long
if ($bin && $toFmt == self::CONTEXT_STRING) {
$columnName = array_pop(unpack('N', $columnName));

// pack the long
// pack the long
} elseif (!$bin && $toFmt == self::CONTEXT_BIN) {
$columnName = pack('NN', $columnName, 0);
}
}

return $columnName;
}

Expand All @@ -526,11 +525,15 @@ protected function typeConvert($columnName, $toFmt) {
*/
public function addColumn($columnName, $typeDef = array(), $callbackOnSave = NULL) {

// can't use array_key_exists - it truncates floats on 32 bit systems
$foundKey = FALSE;
foreach ($this->_columns as $key => $value) {
$foundKey = ($key == $columnName);
if ($foundKey) break;
// can't use array_key_exists for longs - floats are truncated
if ($this->_containerType == self::TYPE_LONG) {
$foundKey = FALSE;
foreach ($this->_columns as $key => $value) {
$foundKey = ($key == $columnName);
if ($foundKey) break;
}
} else {
$foundKey = array_key_exists($columnName, $this->_columns);
}

if (!$foundKey) {
Expand All @@ -543,7 +546,7 @@ public function addColumn($columnName, $typeDef = array(), $callbackOnSave = NUL
// pre-save callback
if (!empty($callbackOnSave)) $this->getColumn($columnName)->setCallback($callbackOnSave);

// php sucks balls, lets lose our precision.
// @todo php sucks balls, lets lose our precision.
if (!PANDRA_64 && $this->_containerType == self::TYPE_LONG) {
$columnName = (int) $columnName;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Core.class.php
Expand Up @@ -214,7 +214,7 @@ static public function connect($connectionID, $host, $keySpace = self::DEFAULT_P
try {

// check connectionid hasn't been marked as down
if (self::priorFail($connectionID)) {
if (self::_priorFail($connectionID)) {
self::registerError($host.'/'.$port.' is marked DOWN', PandraLog::LOG_CRIT);
} else {
// if the connection exists but it is closed, return (getClient will open)
Expand Down Expand Up @@ -459,7 +459,7 @@ static public function getClient($writeMode = FALSE, $keySpace = self::DEFAULT_P
case self::MODE_ACTIVE :
default :
// If we're trying to use an explicit connection id and it's down, then bail
if (self::priorFail(self::$_activeNode)) {
if (self::_priorFail(self::$_activeNode)) {
return NULL;
}

Expand All @@ -476,7 +476,7 @@ static public function getClient($writeMode = FALSE, $keySpace = self::DEFAULT_P
} catch (TException $te) {

if (++self::$_socketPool[self::$_activePool][self::$_activeNode]['retries'] > self::$_maxRetries) {
self::setLastFail();
self::_setLastFail();
unset(self::$_socketPool[self::$_activePool][self::$_activeNode]);
}

Expand Down Expand Up @@ -507,7 +507,7 @@ static private function _authOpen(TBufferedTransport &$transport, $keySpace) {
* Stores the last failure time for a node in the cache (Memcached takes precedence)
* @param string $connectionID connection id
*/
static private function setLastFail($connectionID = NULL) {
static private function _setLastFail($connectionID = NULL) {
$key = 'lastfail_'.md5($connectionID === NULL ? self::$_activeNode : $connectionID);
if (self::$_memcachedAvailable && self::$_memCached instanceof Memcached) {
self::$_memcached->set($key, time(), self::$_retryCooldown);
Expand All @@ -521,7 +521,7 @@ static private function setLastFail($connectionID = NULL) {
* @param string $connectionID connection id
* @return bool node marked down
*/
static private function priorFail($connectionID = NULL) {
static private function _priorFail($connectionID = NULL) {
$key = 'lastfail_'.md5($connectionID === NULL ? self::$_activeNode : $connectionID);
$ok = FALSE;
if (self::$_memcachedAvailable && self::$_memCached instanceof Memcached) {
Expand Down
63 changes: 0 additions & 63 deletions lib/logging/LoggerFirePHP.class.php

This file was deleted.

137 changes: 0 additions & 137 deletions lib/logging/LoggerMail.class.php

This file was deleted.

0 comments on commit 59719b6

Please sign in to comment.