public function check_consistency(EtvaNode $etva_node, $sync_node_lvs, $sync_node_dtable, $sync_bulk_dtable) { $errors = array(); $etva_node->getId(); $etva_cluster = $etva_node->getEtvaCluster(); // get node database LVs $node_lvs = $etva_node->getEtvaLogicalvolumes(); $node_inconsistent = 0; foreach ($node_lvs as $lv) { $error = array(); $uuid = $lv->getUuid(); $device = $lv->getLvdevice(); $etva_vg = $lv->getEtvaVolumegroup(); $vgname = $etva_vg->getVg(); $is_FileDiskVG = $vgname == sfConfig::get('app_volgroup_disk_flag') ? true : false; // init $inconsistent = 0; // look at logical volumes list $found_lvm = 0; foreach ($sync_node_lvs as $hlv) { $arr_hlv = (array) $hlv; if ($arr_hlv[EtvaLogicalvolume::STORAGE_TYPE_MAP] == $lv->getStorageType()) { if ($arr_hlv[EtvaLogicalvolume::UUID_MAP]) { if ($arr_hlv[EtvaLogicalvolume::UUID_MAP] == $uuid) { $found_lvm = 1; } } else { if ($arr_hlv[EtvaLogicalvolume::LVDEVICE_MAP] == $device) { $found_lvm = 1; } } } } $inconsistent = $inconsistent || !$found_lvm; if (!$found_lvm) { $error['not_found_lvm'] = 1; } if (!$is_FileDiskVG) { // if not file disk volume // look at devices table $clvdev = $device; $clvdev = str_replace("/dev/", "", $clvdev); $clvdev = str_replace("-", "--", $clvdev); $clvdev = str_replace("/", "-", $clvdev); $re_clvdev = "/" . $clvdev . ":/"; // found device table of node $node_lv_dtable_aux = preg_grep($re_clvdev, $sync_node_dtable); // ignore snapshots $node_lv_dtable = preg_grep("/(?:(?! snapshot ).)/", $node_lv_dtable_aux); // check if found $found_node_dt = empty($node_lv_dtable) ? 0 : 1; $inconsistent = $inconsistent || !$found_node_dt; if (!$found_node_dt) { $error['not_found_node_device_table'] = 1; } } // update data-base $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByNodeTypeUUIDLv($etva_node->getId(), $lv->getStorageType(), $lv->getUuid(), $lv->getLv()); if ($etva_logicalvol) { $etva_logicalvol->setInconsistent($inconsistent); $etva_logicalvol->save(); } $etva_node_logicalvol = EtvaNodeLogicalvolumePeer::retrieveByPK($etva_node->getId(), $lv->getId()); if ($etva_node_logicalvol) { $etva_node_logicalvol->setInconsistent($inconsistent); $etva_node_logicalvol->save(); } if ($inconsistent) { $message = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_INCONSISTENT_, array('%info%' => sprintf('device "%s" with uuid "%s"', $lv->getLvdevice(), $lv->getUuid()))); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); $error['node'] = array('name' => $etva_node->getName(), 'id' => $etva_node->getId(), 'uuid' => $etva_node->getUuid()); $error['device'] = $lv->getLvdevice(); $error['uuid'] = $lv->getUuid(); $error['message'] = $message; } if (!empty($error)) { $errors[] = $error; } $node_inconsistent = $node_inconsistent || $inconsistent; } // get shared database LVs $shared_lvs = $etva_cluster->getSharedLvs(); // check consistency for shared LVs foreach ($shared_lvs as $lv) { $error = array(); $uuid = $lv->getUuid(); $device = $lv->getLvdevice(); $etva_vg = $lv->getEtvaVolumegroup(); $vgname = $etva_vg->getVg(); // init $inconsistent = 0; // look at logical volumes list $found_lvm = 0; foreach ($sync_node_lvs as $hlv) { $arr_hlv = (array) $hlv; if ($arr_hlv[EtvaLogicalvolume::STORAGE_TYPE_MAP] == $lv->getStorageType()) { if (isset($arr_hlv[EtvaLogicalvolume::UUID_MAP])) { if ($arr_hlv[EtvaLogicalvolume::UUID_MAP] == $uuid) { $found_lvm = 1; } } else { if ($arr_hlv[EtvaLogicalvolume::LVDEVICE_MAP] == $device) { $found_lvm = 1; } } } } $inconsistent = $inconsistent || !$found_lvm; if (!$found_lvm) { $error['not_found_lvm'] = 1; } // look at devices table $clvdev = $device; $clvdev = str_replace("/dev/", "", $clvdev); $clvdev = str_replace("-", "--", $clvdev); $clvdev = str_replace("/", "-", $clvdev); $re_clvdev = "/" . $clvdev . ":/"; // found device table of node $node_lv_dtable_aux = preg_grep($re_clvdev, $sync_node_dtable); // ignore snapshots $node_lv_dtable = preg_grep("/(?:(?! snapshot ).)/", $node_lv_dtable_aux); // check if found $found_node_dt = empty($node_lv_dtable) ? 0 : 1; $inconsistent = $inconsistent || !$found_node_dt; if (!$found_node_dt) { $error['not_found_node_device_table'] = 1; } // look at all nodes devices table $found_all_nodes_dt = 1; foreach ($sync_bulk_dtable as $e_id => $e_response) { if ($e_response['success']) { //response received ok $dtable = (array) $e_response['response']; // found device table of node $lv_dtable = preg_grep($re_clvdev, $dtable); $found = empty($lv_dtable) ? 0 : 1; $is_eq = count($lv_dtable) == count($node_lv_dtable) ? 1 : 0; if ($is_eq) { foreach ($lv_dtable as $e_line) { // TODO fix this if (!in_array($e_line, $node_lv_dtable)) { $is_eq = 0; } } } $found_all_nodes_dt = $found_all_nodes_dt && $found && $is_eq; } } $inconsistent = $inconsistent || !$found_all_nodes_dt; if (!$found_all_nodes_dt) { $error['not_found_all_nodes_device_table'] = 1; } // update data-base $etva_logicalvol = EtvaLogicalvolumePeer::retrieveByNodeTypeUUIDLv($etva_node->getId(), $lv->getStorageType(), $lv->getUuid(), $lv->getLv()); if ($etva_logicalvol) { $etva_logicalvol->setInconsistent($inconsistent); $etva_logicalvol->save(); } $etva_node_logicalvol = EtvaNodeLogicalvolumePeer::retrieveByPK($etva_node->getId(), $lv->getId()); if ($etva_node_logicalvol) { $etva_node_logicalvol->setInconsistent($inconsistent); $etva_node_logicalvol->save(); } if ($inconsistent) { $message = sfContext::getInstance()->getI18N()->__(EtvaLogicalvolumePeer::_ERR_SHARED_INCONSISTENT_, array('%info%' => sprintf('device "%s" with uuid "%s"', $lv->getLvdevice(), $lv->getUuid()))); sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($etva_node->getName(), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); $error['node'] = array('name' => $etva_node->getName(), 'id' => $etva_node->getId(), 'uuid' => $etva_node->getUuid()); $error['device'] = $lv->getLvdevice(); $error['uuid'] = $lv->getUuid(); $error['message'] = $message; } if (!empty($error)) { $errors[] = $error; } $node_inconsistent = $node_inconsistent || $inconsistent; } $return = array(); if ($node_inconsistent) { $etva_node->setErrorMessage(self::LVINIT); $return = array('success' => false, 'errors' => $errors); } else { $etva_node->clearErrorMessage(self::LVINIT); $return = array('success' => true); } return $return; }