multiple improvements to migration algo

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

@ -1548,7 +1548,7 @@ class Update(MethodsInterface):
return True return True
@variable_module("update") @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'): if not self.clVars.Get('cl_ebuild_phase'):
logger = self._get_binhost_logger() logger = self._get_binhost_logger()
if logger: if logger:
@ -1558,6 +1558,7 @@ class Update(MethodsInterface):
retval = [] retval = []
skip_check_status = False skip_check_status = False
actual_reason = self.Reason.UnknownError 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): for binhost in sorted(binhosts_data.get_binhosts(), reverse=True):
host = binhost.host host = binhost.host
if not binhost.valid: if not binhost.valid:
@ -1579,8 +1580,10 @@ class Update(MethodsInterface):
else: else:
# SUCCESS # SUCCESS
if not binhost.downgraded or stabilization: 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 reason = self.Reason.LevelWrong
# if highest_level_found < binhost.level:
# highest_level_found = binhost.level
else: else:
host = "-> %s" % host host = "-> %s" % host
reason = self.Reason.Success reason = self.Reason.Success
@ -1594,7 +1597,8 @@ class Update(MethodsInterface):
if reason == self.Reason.Success: if reason == self.Reason.Success:
retval.append([binhost.host, binhost.data, retval.append([binhost.host, binhost.data,
str(binhost.timestamp), str(binhost.timestamp),
str(binhost.duration)]) str(binhost.duration),
str(binhost.level)])
skip_check_status = True skip_check_status = True
if reason < actual_reason: if reason < actual_reason:
actual_reason = reason actual_reason = reason
@ -1610,7 +1614,8 @@ class Update(MethodsInterface):
self.Reason.Updating): self.Reason.Updating):
raise UpdateError(_("Failed to find the server with appropriate updates")) raise UpdateError(_("Failed to find the server with appropriate updates"))
elif actual_reason is self.Reason.LevelWrong: 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 #TODO add translation
raise UpdateError(_("Failed to find the server with appropriate level of updates")) raise UpdateError(_("Failed to find the server with appropriate level of updates"))
else: else:
@ -1643,7 +1648,8 @@ class Update(MethodsInterface):
self.clVars.Set('update.cl_update_binhost_data', self.clVars.Set('update.cl_update_binhost_data',
[[binhost.host, binhost.data, [[binhost.host, binhost.data,
str(binhost.timestamp), str(binhost.timestamp),
str(binhost.duration)]], str(binhost.duration),
str(binhost.level)]],
force=True) force=True)
self.endTask() self.endTask()
else: else:
@ -1657,14 +1663,16 @@ class Update(MethodsInterface):
raise UpdateError( raise UpdateError(
_("Binary packages on the current binhost {} " _("Binary packages on the current binhost {} "
"are older than local").format(binhost_url)) "are older than local").format(binhost_url))
elif not self.is_binhost_level_valid(binhost): elif self.check_current_level():
self.stashBinhost(binhost_url) if not self.is_binhost_level_valid(binhost):
# self.stash_binhost(binhost_url)
self.set_migration_mode(True) self.set_migration_mode(True)
#TODO translate #TODO translate
raise UpdateError( raise UpdateError(
_("Current binhost {} has a wrong update level. Current level: {} Binhost level: {}").\ _("Current binhost {} has a wrong update level. Current level: {} Binhost level: {}").\
format(binhost_url, self.clVars.Get("update.cl_update_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: if self.binhosts_data.gpg:
packages_fn = self.clVars.Get('update.cl_update_package_cache') packages_fn = self.clVars.Get('update.cl_update_package_cache')
@ -1697,16 +1705,20 @@ class Update(MethodsInterface):
@variable_module("update") @variable_module("update")
def detect_best_binhost(self): def detect_best_binhost(self):
# выполняется переход с серверов unstable обновлней на stable # выполняется переход с серверов unstable обновлении на stable
# в этом случае не важно, что бинари могут старее текущих # в этом случае не важно, что бинари могут старее текущих
if (self.clVars.GetBool('cl_update_binhost_stable_opt_set') and if (self.clVars.GetBool('cl_update_binhost_stable_opt_set') and
not self.clVars.GetBool('cl_update_binhost_stable_set')): not self.clVars.GetBool('cl_update_binhost_stable_set')):
stabilization = True stabilization = True
else: else:
stabilization = False stabilization = False
current_level_is_valid = self.check_current_level()
self.startTask(_("Searching new binhost")) 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', self.clVars.Set('update.cl_update_binhost_data',
retval or Variable.EmptyTable, force=True) retval or Variable.EmptyTable, force=True)
@ -1715,7 +1727,7 @@ class Update(MethodsInterface):
def set_migration_mode(self, val=True): def set_migration_mode(self, val=True):
val_to_write = Variable.On if val else Variable.Off 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): def set_migration_host(self):
#TODO translate #TODO translate
@ -1723,28 +1735,35 @@ class Update(MethodsInterface):
dv = self.clVars dv = self.clVars
last_ts = dv.Get('cl_update_last_timestamp') last_ts = dv.Get('cl_update_last_timestamp')
binhost_list = dv.Get('cl_update_binhost_migration_list') 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 migration_host = None
migr_binhost_data = [] migr_binhost_data = []
while level < 20: #TODO set a const var? or just while true? # 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) migration_host_candidate = self._choose_migration_host(level, binhost_list, last_ts)
if not migration_host_candidate: if migration_host_candidate.bad_sign or \
break migration_host_candidate.status != 0:
elif migration_host_candidate.downgraded: pass
self._update_increment_current_level() # break
level += 1 # elif migration_host_candidate.downgraded:
# self._update_increment_current_level()
# level += 1
# level_did_increase = True
else: else:
migration_host = migration_host_candidate migration_host = migration_host_candidate
break # break
if migration_host: 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.timestamp),
str(migration_host.duration)] str(migration_host.duration),
str(level)]]
self.clVars.Set('update.cl_update_binhost_data', self.clVars.Set('update.cl_update_binhost_data',
migr_binhost_data or Variable.EmptyTable, force=True) migr_binhost_data or Variable.EmptyTable, force=True)
if not migr_binhost_data: if not (migr_binhost_data):
#TODO translate #TODO translate
raise UpdateError(_("Failed to find the working migration server with appropriate level")) raise UpdateError(_("Failed to find the working migration server with appropriate level"))
self.endTask() self.endTask()
@ -1762,9 +1781,6 @@ class Update(MethodsInterface):
gpg=dv.Get('update.cl_update_gpg')) gpg=dv.Get('update.cl_update_gpg'))
return sorted(binhosts_data.get_binhosts(), reverse=True)[0] return sorted(binhosts_data.get_binhosts(), reverse=True)[0]
def update_rep_list(self): def update_rep_list(self):
""" """
Обновить список доступных репозиториев Обновить список доступных репозиториев
@ -1856,6 +1872,7 @@ class Update(MethodsInterface):
self.startTask(_("Increasing update level")) self.startTask(_("Increasing update level"))
self._update_increment_current_level() self._update_increment_current_level()
self.set_migration_mode(False) self.set_migration_mode(False)
self.unstash_binhost()
self.delete_binhost() self.delete_binhost()
self.endTask() self.endTask()
return True return True
@ -1865,17 +1882,32 @@ class Update(MethodsInterface):
self.clVars.Write('cl_update_level', self.clVars.Write('cl_update_level',
str(current_level + 1), location="system") 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):
""" def pull_level_from_binhost(self, binhost):
Восстановление сохраненного бинхоста (если он есть) if binhost.level:
""" self.clVars.Write('cl_update_level',
val_to_write = self.clVars.Get("update.cl_update_binhost_stash") str(binhost.level), location="system")
if val_to_write: return True
self.clVars.Write('cl_update_binhost', val_to_write, location="system") 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", source = ["cl_update_binhost_host",
"cl_update_binhost_revisions", "cl_update_binhost_revisions",
"cl_update_binhost_timestamp", "cl_update_binhost_timestamp",
"cl_update_binhost_time"] "cl_update_binhost_time",
"cl_update_binhost_level"]
def get(self, hr=HumanReadable.No): def get(self, hr=HumanReadable.No):
return Variable.EmptyTable return Variable.EmptyTable
@ -367,6 +368,14 @@ class VariableClUpdateBinhostTime(FieldValue, Variable):
source_variable = "cl_update_binhost_data" source_variable = "cl_update_binhost_data"
column = 3 column = 3
class VariableClUpdateBinhostLevel(FieldValue, Variable):
"""
Список имен прочих репозиториев
"""
type = "list"
source_variable = "cl_update_binhost_data"
column = 4
class VariableClUpdateLastTimestamp(ReadonlyVariable): class VariableClUpdateLastTimestamp(ReadonlyVariable):
""" """
@ -1858,7 +1867,7 @@ class VariableClUpdateLevel(Variable):
Используется для выбора зеркала Используется для выбора зеркала
""" """
type = "int" type = "int"
value = "0" value = "-1"
class VariableClUpdateUseMigrationHost(Variable): class VariableClUpdateUseMigrationHost(Variable):
""" """
@ -1887,3 +1896,10 @@ class VariableClCheckUpdateLevel(Variable):
""" """
type = "bool" type = "bool"
value = "on" value = "on"
class VariableClUpdateMaxLevelFound(Variable):
"""
Самый высокий уровень наиденный на зеркалах
"""
type = "int"
value = "0"
Loading…
Cancel
Save