Skip to content

Commit

Permalink
errors triggering by default is turned on
Browse files Browse the repository at this point in the history
  • Loading branch information
e-oz committed Dec 4, 2011
1 parent 2a873d1 commit df3266f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 41 deletions.
10 changes: 5 additions & 5 deletions APCObject.php
Expand Up @@ -119,7 +119,7 @@ public function getKeyTTL($key)
{
$i = new \APCIterator('user', '/^'.preg_quote($this->prefix.$key).'$/', APC_ITER_TTL+APC_ITER_CTIME, 1);
$item = $i->current();
if (empty($item)) $this->ReportError('key '.$key.' not found'.count($i), __LINE__);
if (empty($item)) return NULL;
if ($item[self::apc_arr_ttl]!=0) return (($item[self::apc_arr_ctime]+$item[self::apc_arr_ttl])-time());
else return self::max_ttl;
}
Expand All @@ -135,7 +135,7 @@ public function read($k, &$ttl_left = -1)
{
if (empty($k))
{
$this->ReportError('empty key are not allowed', __LINE__);
$this->ReportError('empty keys are not allowed', __LINE__);
return NULL;
}
if (is_array($k))
Expand Down Expand Up @@ -197,7 +197,7 @@ public function del($k)
{
if (empty($k))
{
$this->ReportError('empty key are not allowed', __LINE__);
$this->ReportError('empty keys are not allowed', __LINE__);
return false;
}

Expand Down Expand Up @@ -352,7 +352,7 @@ public function increment($key, $by_value = 1, $limit_keys_count = 0, $ttl = 259
return false;
}

if (!$this->acquire_key($key, $auto_unlocker)) return $this->ReportError('Can not acquire key', __LINE__);
if (!$this->acquire_key($key, $auto_unlocker)) return false;

$value = apc_fetch($this->prefix.$key, $success);
if (!$success)
Expand Down Expand Up @@ -407,7 +407,7 @@ public function unlock_key(KeyAutoUnlocker $auto_unlocker)
$key = $auto_unlocker->getKey();
if (empty($key))
{
$this->ReportError('autoUnlocker should be passed', __LINE__);
$this->ReportError('Empty name of key in the AutoUnlocker', __LINE__);
return false;
}
$auto_unlocker->revoke();
Expand Down
11 changes: 5 additions & 6 deletions MemcacheObject.php
Expand Up @@ -33,7 +33,7 @@ protected function setMemcacheObject($host = 'localhost', $port = 11211)
$this->memcache = new \Memcache();
if (!$this->memcache->connect($host, $port))
{
$this->ReportError('memcache not connected', __LINE__);
$this->ReportError('memcache connection error', __LINE__);
}
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public function del($key)
{
if (empty($key))
{
$this->ReportError('empty key are not allowed', __LINE__);
$this->ReportError('empty keys are not allowed', __LINE__);
return false;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public function increment($key, $by_value = 1, $limit_keys_count = 0, $ttl = 259
return false;
}

if (!$this->acquire_key($key, $auto_unlocker)) return $this->ReportError('Can not acquire key', __LINE__);
if (!$this->acquire_key($key, $auto_unlocker)) return false;

$value = $this->memcache->get($this->prefix.$key);
if (empty($value))
Expand Down Expand Up @@ -288,7 +288,7 @@ public function read($k, &$ttl_left = -1)
{
if (empty($k))
{
$this->ReportError('empty key are not allowed', __LINE__);
$this->ReportError('empty keys are not allowed', __LINE__);
return NULL;
}
if (is_array($k))
Expand Down Expand Up @@ -362,7 +362,6 @@ public function save($k, $v, $ttl = 259200, $tags = NULL)
$reason = $this->prefix.$k;
if (strlen($this->prefix.$k) > 250) $reason = 'key length should be <250';
elseif (strlen(serialize($v)) > 1048576) $reason = 'size of value should be <1Mb';
$this->ReportError('can not add key: '.$reason, __LINE__);
$this->ReportError('memcache can not store key: '.$reason, __LINE__);
return false;
}
Expand Down Expand Up @@ -416,7 +415,7 @@ public function unlock_key(KeyAutoUnlocker $auto_unlocker)
$key = $auto_unlocker->getKey();
if (empty($key))
{
$this->ReportError('autoUnlocker should be passed', __LINE__);
$this->ReportError('Empty key in the AutoUnlocker', __LINE__);
return false;
}
$auto_unlocker->revoke();
Expand Down
2 changes: 1 addition & 1 deletion MemoryObject.php
Expand Up @@ -9,7 +9,7 @@ abstract class MemoryObject implements IMemoryStorage

private $last_err;
private $err_log;
private $errors_triggering = false;
private $errors_triggering = true;

public function getLastErr()
{
Expand Down
4 changes: 2 additions & 2 deletions RedisObject.php
Expand Up @@ -191,7 +191,7 @@ public function increment($key, $by_value = 1, $limit_keys_count = 0, $ttl = 259
return false;
}

if (!$this->acquire_key($key, $auto_unlocker)) return $this->ReportError('Can not acquire key', __LINE__);
if (!$this->acquire_key($key, $auto_unlocker)) return false;

$value = $this->read($key);
if ($value===null || $value===false) return $this->save($key, $by_value, $ttl);
Expand Down Expand Up @@ -239,7 +239,7 @@ public function unlock_key(KeyAutoUnlocker $auto_unlocker)
$key = $auto_unlocker->getKey();
if (empty($key))
{
$this->ReportError('autoUnlocker should be passed', __LINE__);
$this->ReportError('Empty key in the AutoUnlocker', __LINE__);
return false;
}
$auto_unlocker->revoke();
Expand Down
13 changes: 1 addition & 12 deletions Shm/SHMObject.php
Expand Up @@ -53,13 +53,11 @@ public function add($k, $v, $ttl = 259200, $tags = NULL)
$auto_unlocker = NULL;
if (!$this->mutex->get_access_write($auto_unlocker))
{
$this->ReportError('write mutex not acquired', __LINE__);
return false;
}
$map = $this->mem_object->read('map');
if (isset($map[$k]))
{
$this->ReportError('key already exists', __LINE__);
return false;
}
return $this->save($k, $v, $ttl, $tags);
Expand Down Expand Up @@ -109,7 +107,6 @@ public function save($k, $v, $ttl = 259200, $tags = NULL)
$auto_unlocker = NULL;
if (!$this->mutex->get_access_write($auto_unlocker))
{
$this->ReportError('write mutex not acquired', __LINE__);
return false;
}
$map = $this->mem_object->read('map');
Expand Down Expand Up @@ -241,7 +238,6 @@ public function read($k, &$ttl_left = -1)
$auto_unlocker = NULL;
if (!$this->mutex->get_access_read($auto_unlocker))
{
$this->ReportError('read access mutex not acquired', __LINE__);
return NULL;
}
$map = $this->mem_object->read('map');
Expand Down Expand Up @@ -291,7 +287,6 @@ public function read($k, &$ttl_left = -1)
$k = (string)$k;
if (!array_key_exists($k, $map))
{
$this->ReportError('key are not in map', __LINE__);
return NULL;
}
$ttl_left = self::max_ttl;
Expand All @@ -300,7 +295,6 @@ public function read($k, &$ttl_left = -1)
$ttl_left = $map[$k][self::map_key_ttl]-time();
if ($ttl_left <= 0)
{
$this->ReportError('ttl expired', __LINE__);
$this->del($k);
return NULL;
}
Expand Down Expand Up @@ -387,7 +381,6 @@ public function del($k)
$auto_unlocker = NULL;
if (!$this->mutex->get_access_write($auto_unlocker))
{
$this->ReportError('write mutex not acquired', __LINE__);
return false;
}
$map = $this->mem_object->read('map');
Expand Down Expand Up @@ -422,7 +415,6 @@ public function del_old()
$auto_unlocker = NULL;
if (!$this->mutex->get_access_write($auto_unlocker))
{
$this->ReportError('write mutex was not acquired', __LINE__);
return false;
}
$r = 0;
Expand Down Expand Up @@ -452,7 +444,6 @@ public function del_by_tags($tag)
$auto_unlocker = NULL;
if (!$this->mutex->get_access_write($auto_unlocker))
{
$this->ReportError('write mutex not acquired', __LINE__);
return false;
}
$mem_tags = $this->mem_object->read('tags');
Expand All @@ -478,7 +469,6 @@ public function select_fx($fx, $get_array = false)
$auto_unlocker = NULL;
if (!$this->mutex->get_access_read($auto_unlocker))
{
$this->ReportError('read mutex not acquired', __LINE__);
return false;
}
$map = $this->mem_object->read('map');
Expand Down Expand Up @@ -519,7 +509,6 @@ public function increment($key, $by_value = 1, $limit_keys_count = 0, $ttl = 259
$auto_unlocker = NULL;
if (!$this->mutex->get_access_write($auto_unlocker))
{
$this->ReportError('write mutex not acquired', __LINE__);
return false;
}
$map = $this->mem_object->read('map');
Expand Down Expand Up @@ -608,7 +597,7 @@ public function unlock_key(\Jamm\Memory\KeyAutoUnlocker $auto_unlocker)
$key = $auto_unlocker->getKey();
if (empty($key))
{
$this->ReportError('autoUnlocker should be passed', __LINE__);
$this->ReportError('Empty key in the AutoUnlocker', __LINE__);
return false;
}
$auto_unlocker->revoke();
Expand Down
18 changes: 3 additions & 15 deletions Shm/SingleMemory.php
Expand Up @@ -27,14 +27,13 @@ public function save($k, $v, $ttl = 2592000, $tags = NULL)
{
if (empty($k) || $v===NULL)
{
$this->ReportError('empty key and null value are not allowed', __LINE__);
$this->ReportError('empty keys and null values are not allowed', __LINE__);
return false;
}
$k = (string)$k;
$auto_unlocker = NULL;
if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}

Expand Down Expand Up @@ -69,7 +68,7 @@ public function read($k, &$ttl_left = -1)
{
if (empty($k))
{
$this->ReportError('empty key are not allowed', __LINE__);
$this->ReportError('empty keys are not allowed', __LINE__);
return false;
}

Expand Down Expand Up @@ -136,13 +135,11 @@ public function del($k)
$auto_unlocker = NULL;
if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}
$this->readmemory();
if (empty($this->mem))
{
$this->ReportError('memory are empty', __LINE__);
return false;
}

Expand Down Expand Up @@ -185,15 +182,13 @@ public function add($key, $value, $ttl = 2592000, $tags = NULL)
$auto_unlocker = NULL;
if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}

$key = (string)$key;
$this->readmemory();
if (isset($this->mem[self::map_keys][$key]))
{
$this->ReportError('key already exists', __LINE__);
return false;
}

Expand Down Expand Up @@ -238,14 +233,12 @@ public function del_by_tags($tags)
$auto_unlocker = NULL;
if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}

$this->readmemory();
if (empty($this->mem[self::map_key_tags]))
{
$this->ReportError('tags was not found', __LINE__);
return false;
}

Expand All @@ -266,7 +259,6 @@ public function del_old()
$auto_unlocker = NULL;
if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}

Expand Down Expand Up @@ -317,7 +309,6 @@ public function increment($key, $by_value = 1, $limit_keys_count = 0, $ttl = 259
$auto_unlocker = NULL;
if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}

Expand Down Expand Up @@ -356,15 +347,13 @@ public function lock_key($key, &$auto_unlocker_variable)
$auto_unlocker = NULL;
if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}
$this->readmemory();
$key = (string)$key;

if (isset($this->mem[self::map_key_locks][$key]))
{
$this->ReportError('key locked', __LINE__);
return false;
}

Expand All @@ -388,14 +377,13 @@ public function unlock_key(\Jamm\Memory\KeyAutoUnlocker $key_auto_unlocker)
$key = $key_auto_unlocker->getKey();
if (empty($key))
{
$this->ReportError('autoUnlocker should be passed', __LINE__);
$this->ReportError('Empty key in the AutoUnlocker', __LINE__);
return false;
}
$key_auto_unlocker->revoke();

if (!$this->sem->get_access_write($auto_unlocker))
{
$this->ReportError('can not acquire writers mutex', __LINE__);
return false;
}
$this->readmemory();
Expand Down

0 comments on commit df3266f

Please sign in to comment.