Skip to content
Snippets Groups Projects
Unverified Commit ddabe6c3 authored by roadscape's avatar roadscape Committed by GitHub
Browse files

Merge pull request #224 from steemit/173-missing-cache-entries

retry insert when get_content fails
parents 752008d3 d5dfd201
No related branches found
No related tags found
No related merge requests found
...@@ -177,8 +177,8 @@ class Db: ...@@ -177,8 +177,8 @@ class Db:
Stats.log_db(sql, perf() - start) Stats.log_db(sql, perf() - start)
return result return result
except Exception as e: except Exception as e:
log.info("[SQL-ERR] %s in query %s (%s)", log.warning("[SQL-ERR] %s in query %s (%s)",
e.__class__.__name__, sql, kwargs) e.__class__.__name__, sql, kwargs)
raise e raise e
@staticmethod @staticmethod
......
...@@ -95,7 +95,6 @@ class Accounts: ...@@ -95,7 +95,6 @@ class Accounts:
@classmethod @classmethod
def dirty_oldest(cls, limit=50000): def dirty_oldest(cls, limit=50000):
"""Flag `limit` least-recently updated accounts for update.""" """Flag `limit` least-recently updated accounts for update."""
log.info("[HIVE] flagging %d oldest accounts for update", limit)
sql = "SELECT name FROM hive_accounts ORDER BY cached_at LIMIT :limit" sql = "SELECT name FROM hive_accounts ORDER BY cached_at LIMIT :limit"
return cls.dirty(set(DB.query_col(sql, limit=limit))) return cls.dirty(set(DB.query_col(sql, limit=limit)))
......
...@@ -337,10 +337,17 @@ class CachedPost: ...@@ -337,10 +337,17 @@ class CachedPost:
sql = """SELECT id, author, permlink, is_deleted sql = """SELECT id, author, permlink, is_deleted
FROM hive_posts WHERE id = :id""" FROM hive_posts WHERE id = :id"""
row = DB.query_row(sql, id=pid) row = DB.query_row(sql, id=pid)
if level == 'insert' and not row['is_deleted']: if row['is_deleted']:
log.warning("couldnt load post for %s: %s", level, row) log.info("found deleted post for %s: %s", level, row)
if level == 'payout':
log.warning("force delete %s", row)
cls.delete(pid, row['author'], row['permlink'])
elif level == 'insert':
log.error("insert post not found -- DEFER %s", row)
cls.insert(row['author'], row['permlink'], pid)
else: else:
log.info("couldnt load post for %s: %s", level, row) log.warning("%s post not found -- DEFER %s", level, row)
cls._dirty(level, row['author'], row['permlink'], pid)
cls._bump_last_id(pid) cls._bump_last_id(pid)
......
...@@ -60,7 +60,7 @@ class Sync: ...@@ -60,7 +60,7 @@ class Sync:
if self._conf.get('test_max_block'): if self._conf.get('test_max_block'):
# debug mode: partial sync # debug mode: partial sync
return self.from_steemd() return self.from_steemd()
elif self._conf.get('test_disable_sync'): if self._conf.get('test_disable_sync'):
# debug mode: no sync, just stream # debug mode: no sync, just stream
return self.listen() return self.listen()
...@@ -193,8 +193,8 @@ class Sync: ...@@ -193,8 +193,8 @@ class Sync:
if num % 1200 == 0: #1hr if num % 1200 == 0: #1hr
Accounts.fetch_ranks() Accounts.fetch_ranks()
if num % 100 == 0: #5min if num % 100 == 0: #5min
log.info("[LIVE] flag 500 oldest accounts for update")
Accounts.dirty_oldest(500) Accounts.dirty_oldest(500)
Accounts.flush(steemd, trx=True)
if num % 20 == 0: #1min if num % 20 == 0: #1min
self._update_chain_state() self._update_chain_state()
......
...@@ -73,7 +73,7 @@ async def load_posts(db, ids, truncate_body=0): ...@@ -73,7 +73,7 @@ async def load_posts(db, ids, truncate_body=0):
# in rare cases of cache inconsistency, recover and warn # in rare cases of cache inconsistency, recover and warn
missed = set(ids) - posts_by_id.keys() missed = set(ids) - posts_by_id.keys()
if missed: if missed:
log.warning("get_posts do not exist in cache: %s", repr(missed)) log.info("get_posts do not exist in cache: %s", repr(missed))
for _id in missed: for _id in missed:
ids.remove(_id) ids.remove(_id)
sql = ("SELECT id, author, permlink, depth, created_at, is_deleted " sql = ("SELECT id, author, permlink, depth, created_at, is_deleted "
...@@ -81,12 +81,9 @@ async def load_posts(db, ids, truncate_body=0): ...@@ -81,12 +81,9 @@ async def load_posts(db, ids, truncate_body=0):
post = await db.query_row(sql, id=_id) post = await db.query_row(sql, id=_id)
if not post['is_deleted']: if not post['is_deleted']:
# TODO: This should never happen. See #173 for analysis # TODO: This should never happen. See #173 for analysis
log.error("missing post -- force insert %s", dict(post)) log.error("missing post -- %s", dict(post))
sql = """INSERT INTO hive_posts_cache (post_id, author, permlink)
VALUES (:id, :author, :permlink)"""
await db.query(sql, **post)
else: else:
log.warning("requested deleted post: %s", dict(post)) log.info("requested deleted post: %s", dict(post))
return [posts_by_id[_id] for _id in ids] return [posts_by_id[_id] for _id in ids]
...@@ -94,7 +91,7 @@ async def _query_author_rep_map(db, posts): ...@@ -94,7 +91,7 @@ async def _query_author_rep_map(db, posts):
"""Given a list of posts, returns an author->reputation map.""" """Given a list of posts, returns an author->reputation map."""
if not posts: if not posts:
return {} return {}
names = tuple(set([post['author'] for post in posts])) names = tuple({post['author'] for post in posts})
sql = "SELECT name, reputation FROM hive_accounts WHERE name IN :names" sql = "SELECT name, reputation FROM hive_accounts WHERE name IN :names"
return {r['name']: r['reputation'] for r in await db.query_all(sql, names=names)} return {r['name']: r['reputation'] for r in await db.query_all(sql, names=names)}
......
...@@ -97,8 +97,8 @@ class Db: ...@@ -97,8 +97,8 @@ class Db:
try: try:
return await conn.execute(self._sql_text(sql), **kwargs) return await conn.execute(self._sql_text(sql), **kwargs)
except Exception as e: except Exception as e:
log.info("[SQL-ERR] %s in query %s (%s)", log.warning("[SQL-ERR] %s in query %s (%s)",
e.__class__.__name__, sql, kwargs) e.__class__.__name__, sql, kwargs)
raise e raise e
def _sql_text(self, sql): def _sql_text(self, sql):
......
...@@ -164,7 +164,7 @@ class HttpClient(object): ...@@ -164,7 +164,7 @@ class HttpClient(object):
if secs > 5: if secs > 5:
log.warning('%s took %.1fs %s', what, secs, info) log.warning('%s took %.1fs %s', what, secs, info)
if tries > 2: if tries > 1:
log.warning('%s took %d tries %s', what, tries, info) log.warning('%s took %d tries %s', what, tries, info)
return result return result
...@@ -176,8 +176,12 @@ class HttpClient(object): ...@@ -176,8 +176,12 @@ class HttpClient(object):
if secs < 0: # request failed if secs < 0: # request failed
secs = perf() - start secs = perf() - start
info = {'secs': round(secs, 3), 'try': tries} info = {'secs': round(secs, 3), 'try': tries}
log.error('%s failed in %.1fs. try %d. %s - %s', if tries > 1:
what, secs, tries, info, repr(e)) log.warning('%s failed in %.1fs. try %d. %s - %s',
what, secs, tries, info, repr(e))
else:
log.info('%s failed in %.1fs. try %d. %s - %s',
what, secs, tries, info, repr(e))
if tries % 2 == 0: if tries % 2 == 0:
self.next_node() self.next_node()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment