multiple improvements to migration algo

migration_mirror 3.7.1.10
idziubenko 2 years ago
parent 98c4deae97
commit 96874fe0ea

@ -1548,7 +1548,7 @@ class Update(MethodsInterface):
return True
@variable_module("update")
def _search_best_binhost(self, binhosts_data, stabilization):
def _search_best_binhost(self, binhosts_data, stabilization, ignore_level=False):
if not self.clVars.Get('cl_ebuild_phase'):
logger = self._get_binhost_logger()
if logger:
@ -1558,6 +1558,7 @@ class Update(MethodsInterface):
retval = []
skip_check_status = False
actual_reason = self.Reason.UnknownError
# highest_level_found = int(self.clVars.Get('update.cl_update_level'))
for binhost in sorted(binhosts_data.get_binhosts(), reverse=True):
host = binhost.host
if not binhost.valid:
@ -1579,8 +1580,10 @@ class Update(MethodsInterface):
else:
# SUCCESS
if not binhost.downgraded or stabilization:
if not self.is_binhost_level_valid(binhost):
if not ignore_level and not self.is_binhost_level_valid(binhost):
reason = self.Reason.LevelWrong
# if highest_level_found < binhost.level:
# highest_level_found = binhost.level
else:
host = "-> %s" % host
reason = self.Reason.Success
@ -1594,7 +1597,8 @@ class Update(MethodsInterface):
if reason == self.Reason.Success:
retval.append([binhost.host, binhost.data,
str(binhost.timestamp),
str(binhost.duration)])
str(binhost.duration),
str(binhost.level)])
skip_check_status = True
if reason < actual_reason:
actual_reason = reason
@ -1610,7 +1614,8 @@ class Update(MethodsInterface):
self.Reason.Updating):
raise UpdateError(_("Failed to find the server with appropriate updates"))
elif actual_reason is self.Reason.LevelWrong:
self.set_migration_mode()
# self.clVars.Set('cl_update_max_level_found', highest_level_found)#TODO change to write
self.set_migration_mode(True)
#TODO add translation
raise UpdateError(_("Failed to find the server with appropriate level of updates"))
else:
@ -1643,7 +1648,8 @@ class Update(MethodsInterface):
self.clVars.Set('update.cl_update_binhost_data',
[[binhost.host, binhost.data,
str(binhost.timestamp),
str(binhost.duration)]],
str(binhost.duration),
str(binhost.level)]],
force=True)
self.endTask()
else:
@ -1657,15 +1663,17 @@ class Update(MethodsInterface):
raise UpdateError(
_("Binary packages on the current binhost {} "
"are older than local").format(binhost_url))
elif not self.is_binhost_level_valid(binhost):
self.stashBinhost(binhost_url)
self.set_migration_mode(True)
#TODO translate
raise UpdateError(
_("Current binhost {} has a wrong update level. Current level: {} Binhost level: {}").\
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level, ))
elif self.check_current_level():
if not self.is_binhost_level_valid(binhost):
# self.stash_binhost(binhost_url)
self.set_migration_mode(True)
#TODO translate
raise UpdateError(
_("Current binhost {} has a wrong update level. Current level: {} Binhost level: {}").\
format(binhost_url, self.clVars.Get("update.cl_update_level"), binhost.level, ))
else:
self.pull_level_from_binhost(binhost)
if self.binhosts_data.gpg:
packages_fn = self.clVars.Get('update.cl_update_package_cache')
packages_sign_fn = self.clVars.Get('update.cl_update_package_cache_sign')
@ -1697,16 +1705,20 @@ class Update(MethodsInterface):
@variable_module("update")
def detect_best_binhost(self):
# выполняется переход с серверов unstable обновлней на stable
# выполняется переход с серверов unstable обновлении на stable
# в этом случае не важно, что бинари могут старее текущих
if (self.clVars.GetBool('cl_update_binhost_stable_opt_set') and
not self.clVars.GetBool('cl_update_binhost_stable_set')):
stabilization = True
else:
stabilization = False
current_level_is_valid = self.check_current_level()
self.startTask(_("Searching new binhost"))
retval = self._search_best_binhost(self.binhosts_data, stabilization)
retval = self._search_best_binhost(self.binhosts_data,
stabilization,
ignore_level = not current_level_is_valid)
self.clVars.Set('update.cl_update_binhost_data',
retval or Variable.EmptyTable, force=True)
@ -1715,7 +1727,7 @@ class Update(MethodsInterface):
def set_migration_mode(self, val=True):
val_to_write = Variable.On if val else Variable.Off
self.clVars.Write("update.cl_update_use_migration_host", val_to_write, location="system")
self.clVars.Write("cl_update_use_migration_host", val_to_write, location="system")
def set_migration_host(self):
#TODO translate
@ -1723,28 +1735,35 @@ class Update(MethodsInterface):
dv = self.clVars
last_ts = dv.Get('cl_update_last_timestamp')
binhost_list = dv.Get('cl_update_binhost_migration_list')
level = self.clVars.Get('update.cl_update_level')
level = int(dv.Get('update.cl_update_level'))
# max_level = int(dv.Get('cl_update_max_level_found'))
migration_host = None
migr_binhost_data = []
while level < 20: #TODO set a const var? or just while true?
migration_host_candidate = self._choose_migration_host(level, binhost_list, last_ts)
if not migration_host_candidate:
break
elif migration_host_candidate.downgraded:
self._update_increment_current_level()
level += 1
else:
migration_host = migration_host_candidate
break
# level_did_increase = False
# one cl-update - one update_level increase max?
# while level < max_level:
# while True:
migration_host_candidate = self._choose_migration_host(level, binhost_list, last_ts)
if migration_host_candidate.bad_sign or \
migration_host_candidate.status != 0:
pass
# break
# elif migration_host_candidate.downgraded:
# self._update_increment_current_level()
# level += 1
# level_did_increase = True
else:
migration_host = migration_host_candidate
# break
if migration_host:
migr_binhost_data = [migration_host.host, migration_host.data,
migr_binhost_data = [[migration_host.host, migration_host.data,
str(migration_host.timestamp),
str(migration_host.duration)]
str(migration_host.duration),
str(level)]]
self.clVars.Set('update.cl_update_binhost_data',
migr_binhost_data or Variable.EmptyTable, force=True)
if not migr_binhost_data:
if not (migr_binhost_data):
#TODO translate
raise UpdateError(_("Failed to find the working migration server with appropriate level"))
self.endTask()
@ -1762,9 +1781,6 @@ class Update(MethodsInterface):
gpg=dv.Get('update.cl_update_gpg'))
return sorted(binhosts_data.get_binhosts(), reverse=True)[0]
def update_rep_list(self):
"""
Обновить список доступных репозиториев
@ -1856,6 +1872,7 @@ class Update(MethodsInterface):
self.startTask(_("Increasing update level"))
self._update_increment_current_level()
self.set_migration_mode(False)
self.unstash_binhost()
self.delete_binhost()
self.endTask()
return True
@ -1865,17 +1882,32 @@ class Update(MethodsInterface):
self.clVars.Write('cl_update_level',
str(current_level + 1), location="system")
def stashBinhost(self, binhost_url):
def check_current_level(self):
"""
Бекап адреса бинхоста
Возвращает True если есть значение в calculate.env
"""
self.clVars.Write("update.cl_update_binhost_stash", binhost_url, location="system")
return int(self.clVars.Get('cl_update_level')) >= 0
def unstashBinhost(self):
"""
Восстановление сохраненного бинхоста (если он есть)
"""
val_to_write = self.clVars.Get("update.cl_update_binhost_stash")
if val_to_write:
self.clVars.Write('cl_update_binhost', val_to_write, location="system")
def pull_level_from_binhost(self, binhost):
if binhost.level:
self.clVars.Write('cl_update_level',
str(binhost.level), location="system")
return True
else:
return False
# def stash_binhost(self, binhost_url):
# """
# Бекап адреса бинхоста
# """
# self.clVars.Write("cl_update_binhost_stash", binhost_url, location="system")
# def unstash_binhost(self):
# """
# Восстановление сохраненного бинхоста (если он есть)
# """
# val_to_write = self.clVars.Get("update.cl_update_binhost_stash")
# if val_to_write:
# self.clVars.Write('cl_update_binhost', val_to_write, location="system")

@ -312,7 +312,8 @@ class VariableClUpdateBinhostData(ReadonlyTableVariable):
source = ["cl_update_binhost_host",
"cl_update_binhost_revisions",
"cl_update_binhost_timestamp",
"cl_update_binhost_time"]
"cl_update_binhost_time",
"cl_update_binhost_level"]
def get(self, hr=HumanReadable.No):
return Variable.EmptyTable
@ -367,6 +368,14 @@ class VariableClUpdateBinhostTime(FieldValue, Variable):
source_variable = "cl_update_binhost_data"
column = 3
class VariableClUpdateBinhostLevel(FieldValue, Variable):
"""
Список имен прочих репозиториев
"""
type = "list"
source_variable = "cl_update_binhost_data"
column = 4
class VariableClUpdateLastTimestamp(ReadonlyVariable):
"""
@ -1858,7 +1867,7 @@ class VariableClUpdateLevel(Variable):
Используется для выбора зеркала
"""
type = "int"
value = "0"
value = "-1"
class VariableClUpdateUseMigrationHost(Variable):
"""
@ -1886,4 +1895,11 @@ class VariableClCheckUpdateLevel(Variable):
NOT IMPLEMENTED YET
"""
type = "bool"
value = "on"
value = "on"
class VariableClUpdateMaxLevelFound(Variable):
"""
Самый высокий уровень наиденный на зеркалах
"""
type = "int"
value = "0"
Loading…
Cancel
Save