Fixed bug when collecting session knobs; for LHS sessions, remove all pre-generated configs if the session knobs are modified

This commit is contained in:
dvanaken 2019-12-05 04:21:55 -05:00 committed by Dana Van Aken
parent 1250732add
commit 9e9c9c7510
4 changed files with 20 additions and 19 deletions

View File

@ -146,7 +146,7 @@ class TaskMetaAdmin(admin.ModelAdmin):
def task_result(self, instance): def task_result(self, instance):
res = self.format_field(instance.result) res = self.format_field(instance.result)
return self.color_field(res, instance.status) return res
task_result.short_description = 'Result' task_result.short_description = 'Result'

View File

@ -184,15 +184,15 @@ class SessionKnobManager(models.Manager):
@staticmethod @staticmethod
def get_knobs_for_session(session): def get_knobs_for_session(session):
# Returns a dict of the knob # Returns a dict of the knob
knobs = KnobCatalog.objects.filter(dbms=session.dbms) session_knobs = SessionKnob.objects.filter(
knob_dicts = list(knobs.values()) session=session, tunable=True).prefetch_related('knob')
for i, _ in enumerate(knob_dicts): session_knobs = {s.knob.pk: s for s in session_knobs}
if SessionKnob.objects.filter(session=session, knob=knobs[i]).exists(): knob_dicts = list(KnobCatalog.objects.filter(id__in=session_knobs.keys()).values())
new_knob = SessionKnob.objects.filter(session=session, knob=knobs[i])[0] for knob_dict in knob_dicts:
knob_dicts[i]["minval"] = new_knob.minval sess_knob = session_knobs[knob_dict['id']]
knob_dicts[i]["maxval"] = new_knob.maxval knob_dict['minval'] = sess_knob.minval
knob_dicts[i]["tunable"] = new_knob.tunable knob_dict['maxval'] = sess_knob.maxval
knob_dicts = [knob for knob in knob_dicts if knob["tunable"]] knob_dict['tunable'] = sess_knob.tunable
return knob_dicts return knob_dicts
@staticmethod @staticmethod

View File

@ -107,6 +107,7 @@ class ConfigurationRecommendation(UpdateTask): # pylint: disable=abstract-metho
def on_success(self, retval, task_id, args, kwargs): def on_success(self, retval, task_id, args, kwargs):
super(ConfigurationRecommendation, self).on_success(retval, task_id, args, kwargs) super(ConfigurationRecommendation, self).on_success(retval, task_id, args, kwargs)
LOG.info("NEXT CONFIG: %s", retval['recommendation'])
result_id = retval['result_id'] result_id = retval['result_id']
result = Result.objects.get(pk=result_id) result = Result.objects.get(pk=result_id)

View File

@ -360,18 +360,13 @@ def edit_knobs(request, project_id, session_id):
instance.save() instance.save()
return HttpResponse(status=204) return HttpResponse(status=204)
else: else:
# knobs = KnobCatalog.objects.filter(dbms=session.dbms).order_by('-tunable') knobs = SessionKnob.objects.filter(session=session).prefetch_related(
knobs = SessionKnob.objects.filter(session=session).order_by('-tunable', 'knob__name') 'knob').order_by('-tunable', 'knob__name')
forms = [] forms = []
for knob in knobs: for knob in knobs:
knob_values = model_to_dict(knob) knob_values = model_to_dict(knob)
knob_values['session'] = session knob_values['session'] = session
knob_values['name'] = KnobCatalog.objects.get(pk=knob.knob.pk).name knob_values['name'] = knob.knob.name
# if SessionKnob.objects.filter(session=session, knob=knob).exists():
# new_knob = SessionKnob.objects.filter(session=session, knob=knob)[0]
# knob_values["minval"] = new_knob.minval
# knob_values["maxval"] = new_knob.maxval
# knob_values["tunable"] = new_knob.tunable
forms.append(SessionKnobForm(initial=knob_values)) forms.append(SessionKnobForm(initial=knob_values))
context = { context = {
'project': project, 'project': project,
@ -1314,6 +1309,12 @@ def alt_create_or_edit_session(request):
session = get_object_or_404(Session, name=session_name, project=project, user=user) session = get_object_or_404(Session, name=session_name, project=project, user=user)
for k, v in data.items(): for k, v in data.items():
setattr(session, k, v) setattr(session, k, v)
# Corner case: when running LHS, when the tunable knobs and/or their ranges change
# then we must delete the pre-generated configs since they are no longer valid.
if session_knobs and session.tuning_session == 'lhs':
session.lhs_samples = '[]'
session.last_update = ts session.last_update = ts
session.save() session.save()
@ -1321,7 +1322,6 @@ def alt_create_or_edit_session(request):
session_knobs = JSONUtil.loads(session_knobs) session_knobs = JSONUtil.loads(session_knobs)
SessionKnob.objects.set_knob_min_max_tunability(session, session_knobs, SessionKnob.objects.set_knob_min_max_tunability(session, session_knobs,
disable_others=disable_others) disable_others=disable_others)
res = model_to_dict(session) res = model_to_dict(session)
res['dbms_id'] = res['dbms'] res['dbms_id'] = res['dbms']
res['dbms'] = session.dbms.full_name res['dbms'] = session.dbms.full_name