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):
res = self.format_field(instance.result)
return self.color_field(res, instance.status)
return res
task_result.short_description = 'Result'

View File

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

View File

@ -107,6 +107,7 @@ class ConfigurationRecommendation(UpdateTask): # pylint: disable=abstract-metho
def on_success(self, 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 = Result.objects.get(pk=result_id)

View File

@ -360,18 +360,13 @@ def edit_knobs(request, project_id, session_id):
instance.save()
return HttpResponse(status=204)
else:
# knobs = KnobCatalog.objects.filter(dbms=session.dbms).order_by('-tunable')
knobs = SessionKnob.objects.filter(session=session).order_by('-tunable', 'knob__name')
knobs = SessionKnob.objects.filter(session=session).prefetch_related(
'knob').order_by('-tunable', 'knob__name')
forms = []
for knob in knobs:
knob_values = model_to_dict(knob)
knob_values['session'] = session
knob_values['name'] = KnobCatalog.objects.get(pk=knob.knob.pk).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
knob_values['name'] = knob.knob.name
forms.append(SessionKnobForm(initial=knob_values))
context = {
'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)
for k, v in data.items():
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.save()
@ -1321,7 +1322,6 @@ def alt_create_or_edit_session(request):
session_knobs = JSONUtil.loads(session_knobs)
SessionKnob.objects.set_knob_min_max_tunability(session, session_knobs,
disable_others=disable_others)
res = model_to_dict(session)
res['dbms_id'] = res['dbms']
res['dbms'] = session.dbms.full_name