Some more performance improvements and caching
This commit is contained in:
@@ -36,19 +36,84 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
* Get all the NODES in this DOMAIN
|
||||
*/
|
||||
private function _nodes() {
|
||||
$result = array();
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
// In the interest of performance, we load all the records and get PHP to process it.
|
||||
// Our ORM caching we reduce the hit on TSM.
|
||||
foreach (ORM::factory('NODE')->find_all() as $o)
|
||||
if ($o->DOMAIN_NAME == $this->DOMAIN_NAME)
|
||||
array_push($result,$o);
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
// In the interest of performance, we load all the records and get PHP to process it.
|
||||
// Our ORM caching we reduce the hit on TSM.
|
||||
foreach (ORM::factory('NODE')->find_all() as $o)
|
||||
if ($o->DOMAIN_NAME == $this->DOMAIN_NAME)
|
||||
array_push($result,$o);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function nodes() {
|
||||
return $this->_nodes();
|
||||
private function _node_int($method,$data) {
|
||||
$k = sprintf('%s-%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$method,$data);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
$result += $no->{$method}($data);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function _node_bypoolbybtype($pool,$method,$type) {
|
||||
$k = sprintf('%s-%s-%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool,$method,$type);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
$result += $no->{$method}($pool,$type);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BACKUP TYPES used by NODES in this DOMAIN
|
||||
* ie: Bkup/Arch/SpMg
|
||||
*/
|
||||
public function btypes() {
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
$result = array_merge($result,$no->btypes());
|
||||
|
||||
$result = array_unique($result);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function file_bybtype($type) {
|
||||
return $this->_node_int('file_bybtype',$type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,20 +121,19 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
*/
|
||||
public function file_bypool($pool) {
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
return $this->_node_int('file_bypool',$pool);
|
||||
}
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = 0;
|
||||
public function file_bypoolbybtype($pool,$type) {
|
||||
return $this->_node_bypoolbybtype($pool,'file_bypoolbybtype',$type);
|
||||
}
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
$result += $no->file_bypool($pool);
|
||||
public function file_byptype($type) {
|
||||
return $this->_node_int('file_byptype',$type);
|
||||
}
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
return $result;
|
||||
public function logmb_bybtype($type) {
|
||||
return $this->_node_int('logmb_bybtype',$type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,19 +141,27 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
*/
|
||||
public function logmb_bypool($pool) {
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
return $this->_node_int('logmb_bypool',$pool);
|
||||
}
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = 0;
|
||||
public function logmb_bypoolbybtype($pool,$type) {
|
||||
return $this->_node_bypoolbybtype($pool,'logmb_bypoolbybtype',$type);
|
||||
}
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
$result += $no->logmb_bypool($pool);
|
||||
public function logmb_byptype($type) {
|
||||
return $this->_node_int('logmb_byptype',$type);
|
||||
}
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
public function nodes() {
|
||||
return $this->_nodes();
|
||||
}
|
||||
|
||||
public function nodes_bybtype($type) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
if ($no->file_bybtype($type))
|
||||
array_push($result,$no);
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -107,6 +179,26 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function nodes_bypoolbybtype($pool,$type) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
if ($no->file_bypoolbybtype($pool,$type))
|
||||
array_push($result,$no);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function nodes_byptype($type) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
if ($no->file_byptype($type) AND ! in_array($no,$result))
|
||||
array_push($result,$no);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the STORAGE POOLS used by NODES in this DOMAIN
|
||||
*/
|
||||
@@ -117,7 +209,7 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->nodes() as $no)
|
||||
foreach ($this->_nodes() as $no)
|
||||
foreach ($no->stgpools() as $spo)
|
||||
if (! in_array($spo,$result))
|
||||
array_push($result,$spo);
|
||||
@@ -129,29 +221,6 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the STORAGE POOL TYPES used by NODES in this DOMAIN
|
||||
* ie: ACTIVE/PRIMARY/COPY
|
||||
* @todo This should be sorted by PRIMARY/ACTIVE/COPY
|
||||
*/
|
||||
public function stgpooltypes() {
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->stgpools() as $spo)
|
||||
if (! in_array($spo->POOLTYPE,$result))
|
||||
array_push($result,$spo->POOLTYPE);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the STORAGE POOLS that NODES in this DOMAIN uses by BACKUP TYPE
|
||||
* @param $type is Bkup/Arch/SpMg
|
||||
@@ -200,22 +269,21 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that NODES in this DOMAIN use
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
* Return the STORAGE POOL TYPES used by NODES in this DOMAIN
|
||||
* ie: ACTIVE/PRIMARY/COPY
|
||||
* @todo This should be sorted by PRIMARY/ACTIVE/COPY
|
||||
*/
|
||||
public function vols_bypool($pool) {
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
|
||||
public function stgpooltypes() {
|
||||
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$x = $result = array();
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
foreach ($no->vols_bypool($pool) as $vuo)
|
||||
if (! in_array($vuo->VOLUME_NAME,$x)) {
|
||||
array_push($result,$vuo);
|
||||
array_push($x,$vuo->VOLUME_NAME);
|
||||
}
|
||||
$result = array_merge($result,$no->stgpooltypes());
|
||||
|
||||
$result = array_unique($result);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
@@ -224,6 +292,10 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function vols_bybtype($type) {
|
||||
return $this->vols_byctype($this->datatypemap($type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that NODES in this DOMAIN uses by BACKUP TYPE
|
||||
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
|
||||
@@ -232,15 +304,13 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$type);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (TRUE OR is_null($result = Cache::instance($c)->get($k))) {
|
||||
$x = $result = array();
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
foreach ($no->vols_byctype($type) as $vuo)
|
||||
if (! in_array($vuo->VOLUME_NAME,$x)) {
|
||||
array_push($result,$vuo);
|
||||
array_push($x,$vuo->VOLUME_NAME);
|
||||
}
|
||||
foreach ($no->vols_byctype($type) as $vo)
|
||||
if (! in_array($vo->VOLUME_NAME,$result))
|
||||
array_push($result,$vo);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
@@ -249,6 +319,33 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that NODES in this DOMAIN use
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
*/
|
||||
public function vols_bypool($pool) {
|
||||
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
|
||||
$c = Kohana::$config->load('config')->cache;
|
||||
|
||||
if (is_null($result = Cache::instance($c)->get($k))) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
foreach ($no->vols_bypool($pool) as $vo)
|
||||
if (! in_array($vo->VOLUME_NAME,$result))
|
||||
array_push($result,$vo);
|
||||
|
||||
// @todo Cache time should be configurble
|
||||
Cache::instance($c)->set($k,$result,300);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function vols_bypoolbybtype($pool,$type) {
|
||||
return $this->vols_bypoolbyctype($pool,$this->datatypemap($type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the VOLUMES that this NODE uses by pool and BACKUP TYPE
|
||||
* @param $pool is STORAGE POOL NAME
|
||||
@@ -257,11 +354,23 @@ class Model_DOMAIN extends ORM_TSM {
|
||||
public function vols_bypoolbyctype($pool,$type) {
|
||||
$x = $result = array();
|
||||
|
||||
foreach ($this->vols_bypool($pool) as $vuo)
|
||||
if ($vuo->COPY_TYPE == $type AND ! in_array($vuo->VOLUME_NAME,$x)) {
|
||||
array_push($result,$vuo);
|
||||
array_push($x,$vuo->VOLUME_NAME);
|
||||
}
|
||||
foreach ($this->_nodes() as $no)
|
||||
foreach ($no->vols_bypoolbyctype($pool,$type) as $vo)
|
||||
if (! in_array($vo->VOLUME_NAME,$result))
|
||||
array_push($result,$vo);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function vols_byptype($type) {
|
||||
$x = $result = array();
|
||||
|
||||
foreach ($this->_nodes() as $no)
|
||||
foreach ($no->vols_byptype($type) as $vuo)
|
||||
if (! in_array($vuo->VOLUME_NAME,$x)) {
|
||||
array_push($result,$vuo);
|
||||
array_push($x,$vuo->VOLUME_NAME);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user