Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkin results in IntegrityError #90

Closed
sheagcraig opened this issue Dec 22, 2016 · 4 comments
Closed

Checkin results in IntegrityError #90

sheagcraig opened this issue Dec 22, 2016 · 4 comments

Comments

@sheagcraig
Copy link
Contributor

With the sal-scripts v2.0, I get these all day long:

[22/Dec/2016 08:52:57] ERROR [django.request:124] Internal Server Error: /checkin/
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/docker/sal/sal/decorators.py", line 119, in wrap
    return function(request, *args, **kwargs)
  File "/home/docker/sal/server/views.py", line 2022, in checkin
    UpdateHistoryItem.objects.bulk_create(update_history_item_to_save)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 449, in bulk_create
    self._batched_insert(objs_with_pk, fields, batch_size)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1060, in _batched_insert
    inserted_id = self._insert(item, fields=fields, using=self.db, return_id=True)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1043, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 1054, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
IntegrityError: duplicate key value violates unique constraint "server_updatehistoryite_update_history_id_78bcc0ce2c3b29f0_uniq"
DETAIL:  Key (update_history_id, recorded, status)=(236856, 2016-12-22 13:52:57.393286+00, pending) already exists.
@grahamgilbert
Copy link
Member

Update history tracking sucks in general (see #68) and needs to be rewritten. This is another example of that.

@sheagcraig
Copy link
Contributor Author

This is filling my logs. I have log rotation on, but I am definitely seeing that the dashboard takes progressively longer and longer to load over time. I'd love to rule this out as a reason.

If you have any directed suggestions, I could look into this since it is affecting me and I'm feeling motivated.

@grahamgilbert
Copy link
Member

Honestly, it needs to be burned and start again. I wrote it when we got significantly less info from the ManagedInstallsReport.plist, we should be able to get everything from that now. This didn't change from 2.7.x though.

@sheagcraig
Copy link
Contributor Author

Hmmm. I'll see if I can patch my production server to at least ignore those errors.

sheagcraig added a commit to sheagcraig/sal that referenced this issue Jan 6, 2017
As far as I can understand this, the problem was that an
UpdateHistoryItem was created, and then immediately had `.save()`
called. Then, on postgres, it would then later do a bulk_create on the
UpdateHistoryItem model. Since the model instance had already been
saved, the bulk create was failing when it tried to create a second
(conjecture...), duplicate UpdateHistoryItem, due to the uniqueness
constraints.

This commit moves the `save()` into the non-postgres block, and allows
the bulk_create action on the model to insert the objects for Postgres.

My understanding is that the update_history needs to get saved
regardless, since the `pending_recorded` attribute gets set. This
doesn't seem to trigger a save because the ForeignKey relationship goes
the other way.

This solves the massive exception logging that occurs in my environment
as a result of this problem, leading to maxed out memory and CPU usage
on the server. Whether it correctly handles the data involved, I'm not
clear enough on how this works to say with 100% certainty that this is
all it needs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants