Skip to content

Commit

Permalink
make gap check more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
roadscape committed Jan 25, 2019
1 parent 3c2e227 commit d9bb8d8
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions hive/indexer/cached_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,26 +352,22 @@ def _bump_last_id(cls, next_id):
if next_id <= last_id:
return

if next_id - last_id > 2:
gap = next_id - last_id - 1
if gap:
cls._ensure_safe_gap(last_id, next_id)
if next_id - last_id > 4:
# gap of 2 is common due to deletions. report on larger gaps.
log.warning("skipping post ids %d -> %d", last_id, next_id)
log.warning("skipped %d posts %d -> %d", gap, last_id, next_id)

cls._last_id = next_id

@classmethod
def _ensure_safe_gap(cls, last_id, next_id):
"""Paranoid check of important operating assumption."""
sql = """
SELECT COUNT(*) FROM hive_posts
WHERE id BETWEEN :x1 AND :x2 AND is_deleted = '0'
"""
sql = """SELECT COUNT(*) FROM hive_posts
WHERE id BETWEEN :x1 AND :x2 AND is_deleted = '0'"""
missing_posts = DB.query_one(sql, x1=(last_id + 1), x2=(next_id - 1))
if not missing_posts:
return
raise Exception("found large cache gap: %d --> %d (%d)"
% (last_id, next_id, missing_posts))
if missing_posts:
raise Exception("found cache gap: %d --> %d (%d)"
% (last_id, next_id, missing_posts))

@classmethod
def _sql(cls, pid, post, level=None):
Expand Down

0 comments on commit d9bb8d8

Please sign in to comment.