Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
CORTX-33673: update lock unlock parameters with new improvment changes
Browse files Browse the repository at this point in the history
Signed-off-by: Tanuja Shinde <tanuja.shinde@seagate.com>
  • Loading branch information
tanujashinde0405 committed Aug 10, 2022
1 parent fcee94d commit e86fc5c
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/provisioner/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class CortxProvisioner:
_solution_index = "solution_conf"
_secrets_path = "/etc/cortx/solution/secret"
_rel_secret_path = "/solution/secret"
_lock_key = "consul_conf>lock"
_cortx_gconf_consul_index = "consul_index"
_lock_domain = "provisioner"
_timeout = 25
_duration = 20
_sleep = 2
cortx_release = Release(const.RELEASE_INFO_URL)

Expand Down Expand Up @@ -111,13 +112,13 @@ def config_apply(solution_config_url: str, cortx_conf_url: str = None,
CortxProvisioner.apply_cluster_config(cortx_conf, CortxProvisioner.cortx_release)

machine_id = CortxProvisioner._get_machine_id()
if not CortxProvisioner._wait_for_lock_to_be_released(cortx_conf, CortxProvisioner._timeout):
if not Conf.unlock(cortx_conf._conf_idx, lock_owner=machine_id, force = True, lock_key=CortxProvisioner._lock_key):
if not CortxProvisioner._wait_for_lock_to_be_released(cortx_conf, CortxProvisioner._timeout, machine_id):
if not Conf.unlock(cortx_conf._conf_idx, owner=machine_id, force = True, domain=CortxProvisioner._lock_domain):
raise CortxProvisionerError(errno.EINVAL, f"Force unlock failed for index {cortx_conf._conf_idx}")
# TODO: remove Conf.save once gconf is completly moved to consul
Conf.save(cortx_conf._conf_idx)
if cortx_conf.get('cortx>common>storage>local') is None and Conf.get(CortxProvisioner._solution_index, 'cortx') is not None:
if not Conf.lock(cortx_conf._conf_idx, lock_owner=machine_id, lock_key=CortxProvisioner._lock_key):
if not Conf.lock(cortx_conf._conf_idx, owner=machine_id, domain=CortxProvisioner._lock_domain, duration=CortxProvisioner._duration):
raise CortxProvisionerError(errno.EINVAL, f"locking failed for index {cortx_conf._conf_idx}")
# TODO: remove Conf.save once gconf is completly moved to consul
Conf.save(cortx_conf._conf_idx)
Expand Down Expand Up @@ -148,7 +149,7 @@ def config_apply(solution_config_url: str, cortx_conf_url: str = None,
# Adding array count key in conf
cortx_conf.add_num_keys()
Conf.save(cortx_conf._conf_idx)
if not Conf.unlock(cortx_conf._conf_idx, lock_owner=machine_id, lock_key=CortxProvisioner._lock_key):
if not Conf.unlock(cortx_conf._conf_idx, owner=machine_id, domain=CortxProvisioner._lock_domain):
raise CortxProvisionerError(errno.EINVAL, f"unlocking failed for index {cortx_conf._conf_idx}")
# TODO: remove Conf.save once gconf is completly moved to consul
Conf.save(cortx_conf._conf_idx)
Expand Down Expand Up @@ -189,23 +190,23 @@ def apply_cluster_config(cortx_conf, cortx_release):
solution_config_nodes = CortxCluster(nodes, cortx_release)
solution_config_nodes.save(cortx_conf)
machine_id = CortxProvisioner._get_machine_id()
if not CortxProvisioner._wait_for_lock_to_be_released(cortx_conf, CortxProvisioner._timeout):
if not Conf.unlock(cortx_conf._conf_idx, lock_owner=machine_id, force = True, lock_key=CortxProvisioner._lock_key):
if not CortxProvisioner._wait_for_lock_to_be_released(cortx_conf, CortxProvisioner._timeout, machine_id):
if not Conf.unlock(cortx_conf._conf_idx, owner=machine_id, force = True, domain=CortxProvisioner._lock_domain):
raise CortxProvisionerError(errno.EINVAL, f"Force unlock failed for index {cortx_conf._conf_idx}")
# TODO: remove Conf.save once gconf is completly moved to consul
Conf.save(cortx_conf._conf_idx)
if cortx_conf.get('cluster>id') is None:
cluster_keys = [('cluster>id', cluster_id),
('cluster>name', cluster_name)]
cortx_conf.set_kvs(cluster_keys)
if not Conf.lock(cortx_conf._conf_idx, lock_owner=machine_id, lock_key=CortxProvisioner._lock_key):
if not Conf.lock(cortx_conf._conf_idx, owner=machine_id, domain=CortxProvisioner._lock_domain, duration=CortxProvisioner._duration):
raise CortxProvisionerError(errno.EINVAL, f"locking failed for index {cortx_conf._conf_idx}")
# TODO: remove Conf.save once gconf is completly moved to consul
Conf.save(cortx_conf._conf_idx)
solution_config_storagesets = CortxStorageSet(storage_sets)
solution_config_storagesets.save(cortx_conf)
Conf.save(cortx_conf._conf_idx)
if not Conf.unlock(cortx_conf._conf_idx, lock_owner=machine_id, lock_key=CortxProvisioner._lock_key):
if not Conf.unlock(cortx_conf._conf_idx, owner=machine_id, domain=CortxProvisioner._lock_domain):
raise CortxProvisionerError(errno.EINVAL, f"unlocking failed for index {cortx_conf._conf_idx}")
# TODO: remove Conf.save once gconf is completly moved to consul
Conf.save(cortx_conf._conf_idx)
Expand All @@ -232,15 +233,15 @@ def _check_consul_connection(cortx_conf_url: str, timeout: int):
return False

@staticmethod
def _wait_for_lock_to_be_released(cortx_conf: MappedConf, timeout: int):
while True:
if not Conf.test_lock(cortx_conf._conf_idx, lock_key=CortxProvisioner._lock_key):
return True
lock_time = float(cortx_conf.get(f'{CortxProvisioner._lock_key}>time'))
if (lock_time + timeout) < float(datetime.timestamp(datetime.now())):
def _wait_for_lock_to_be_released(cortx_conf: MappedConf, timeout: int, machine_id: str):
rc = False
while timeout > 0:
if Conf.test_lock(cortx_conf._conf_idx, domain=CortxProvisioner._lock_domain, owner=machine_id):
rc = True
break
time.sleep(CortxProvisioner._sleep)
return False
timeout -=1
return rc

@staticmethod
def _get_machine_id():
Expand Down

0 comments on commit e86fc5c

Please sign in to comment.