Skip to content
This repository has been archived by the owner on May 22, 2022. It is now read-only.

Commit

Permalink
vote_q proc pickle -> JSON msg migration part 1
Browse files Browse the repository at this point in the history
Part 1 of a multi-phase commit to migrate the message format
of the vote queues from pickle to JSON.

This first part updates the processor to be able to read from
both the pickle and the JSON formats.
  • Loading branch information
kemitche committed May 5, 2015
1 parent aa77243 commit a6b2801
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions r2/r2/lib/db/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# All portions of the code written by reddit are Copyright (c) 2006-2015 reddit
# Inc. All Rights Reserved.
###############################################################################
import json

from r2.models import Account, Link, Comment, Report, LinksByAccount
from r2.models.vote import cast_vote, get_votes, VotesByAccount
Expand Down Expand Up @@ -1852,12 +1853,26 @@ def _handle_vote(msg):
timer = stats.get_timer("service_time." + stats_qname)
timer.start()

#assert(len(msgs) == 1)
r = pickle.loads(msg.body)

uid, tid, dir, ip, vote_info, cheater = r
voter = Account._byID(uid, data=True)
votee = Thing._by_fullname(tid, data = True)
# Temporary shim: During queue message format transition,
# JSON payloads will be explicitly marked as such.
msg_headers = msg.properties.get("application_headers", {})
if msg_headers.get("format", "pickle") == "json":
vote = json.loads(msg.body)
else:
uid, tid, dir, ip, info, cheater = pickle.loads(msg.body)
vote = {
"uid": uid,
"tid": tid,
"dir": dir,
"ip": ip,
"info": info,
"cheater": cheater,
"event": None,
}
del uid, tid, dir, ip, info, cheater

voter = Account._byID(vote["uid"], data=True)
votee = Thing._by_fullname(vote["tid"], data=True)
timer.intermediate("preamble")

# Convert the naive timestamp we got from amqplib to a
Expand All @@ -1868,17 +1883,18 @@ def _handle_vote(msg):
# I don't know how, but somebody is sneaking in votes
# for subreddits
if isinstance(votee, (Link, Comment)):
print (voter, votee, dir, ip, vote_info, cheater)
handle_vote(voter, votee, dir, ip, vote_info,
cheater = cheater, foreground=True, timer=timer,
print (voter, votee, vote["dir"], vote["ip"], vote["info"],
vote["cheater"])
handle_vote(voter, votee, vote["dir"], vote["ip"], vote["info"],
cheater=vote["cheater"], foreground=True, timer=timer,
date=date)

if isinstance(votee, Comment):
update_comment_votes([votee])
timer.intermediate("update_comment_votes")

stats.simple_event('vote.total')
if cheater:
if vote["cheater"]:
stats.simple_event('vote.cheater')
timer.flush()

Expand Down

0 comments on commit a6b2801

Please sign in to comment.