Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Payday rewrite, part 5 #2579

Merged
merged 98 commits into from
Aug 12, 2014
Merged

Payday rewrite, part 5 #2579

merged 98 commits into from
Aug 12, 2014

Conversation

Changaco
Copy link
Contributor

Step 6 of #2508. Follow-on from #2541.

@chadwhitacre
Copy link
Contributor

I just ran the test suite for this branch. 449 passed, 2 xfailed in 27.92 seconds. 100% coverage on exchanges.py, 99% on payday.py. Looking good so far! :-)

@chadwhitacre
Copy link
Contributor

Hit an error:

[gittip] $ ./payday.sh foo
Rerun payday #foo? (y/N) y
Logging to ../paydays/test-foo.log.
[gittip] $ cat ../paydays/test-foo.log
Tue Jul 29 21:31:40 UTC 2014
pid-16089 thread-140735191843600 (MainThread) Traceback (most recent call last):
pid-16089 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gittip/cli.py", line 33, in payday
pid-16089 thread-140735191843600 (MainThread)     sync_with_balanced()
pid-16089 thread-140735191843600 (MainThread) TypeError: sync_with_balanced() takes exactly 1 argument (0 given)
[gittip] $

@chadwhitacre
Copy link
Contributor

IRC re: integration testing. Decided to do it manually.

else:
# The amount is too low, cancel the hold and make a new one
cancel_card_hold(holds.pop(p.id))
hold, error = create_card_hold(self.db, p, amount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_card_hold and ach_credit use two different error models. They raise exceptions, and they also return an error value. Here we're only handling the second of these strategies, with the result that an exception raised by create_card_hold will terminate payday, whereas it should result in a log message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like in payout, which calls ach_credit, both error models are handled. We have a try except block in there around ach_credit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should terminate payday, create_card_hold is not supposed to raise an exception here, if it does then something is wrong, like the fact that I forgot to add AND is_suspicious IS false in the query above.

@chadwhitacre
Copy link
Contributor

Should we change the few remaining uses of pachinko to takes?

@chadwhitacre
Copy link
Contributor

Looks like we're running afoul of the database_maxconn restriction?

Wed Jul 30 15:36:22 UTC 2014
pid-17348 thread-140735191843600 (MainThread) Picking up with an existing payday.
pid-17348 thread-140735191843600 (MainThread) Payday started at 2014-07-30 14:58:49.849785+00:00.
pid-17348 thread-140735191843600 (MainThread) Greetings, program! It's PAYDAY!!!!
pid-17348 thread-140735191843600 (MainThread) Prepared the DB.
pid-17348 thread-140735191843600 (MainThread) Holding 3636 cents ($35.00 + $1.36 fee = $36.36) on Balanc
pid-17348 thread-140735191843600 (MainThread) Traceback (most recent call last):
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gitt
pid-17348 thread-140735191843600 (MainThread)     Payday.start().run()
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gitt
pid-17348 thread-140735191843600 (MainThread)     self.payin()
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gitt
pid-17348 thread-140735191843600 (MainThread)     self.settle_card_holds(cursor, holds)
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gitt
pid-17348 thread-140735191843600 (MainThread)     capture_card_hold(self.db, p, amount, holds.pop(p.id))
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gitt
pid-17348 thread-140735191843600 (MainThread)     e_id = record_exchange(db, 'bill', amount, fee, partic
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gitt
pid-17348 thread-140735191843600 (MainThread)     with db.get_cursor() as cursor:
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/env/
pid-17348 thread-140735191843600 (MainThread)     self.conn = self.pool.getconn()
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/env/
pid-17348 thread-140735191843600 (MainThread)     return self._getconn(key)
pid-17348 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/env/
pid-17348 thread-140735191843600 (MainThread)     raise PoolError("connection pool exausted")
pid-17348 thread-140735191843600 (MainThread) PoolError: connection pool exausted

@chadwhitacre
Copy link
Contributor

By commenting out the maxconn restriction I was able to run a payday locally! 💃

Wed Jul 30 15:39:22 UTC 2014
pid-17376 thread-140735191843600 (MainThread) Picking up with an existing payday.
pid-17376 thread-140735191843600 (MainThread) Payday started at 2014-07-30 14:58:49.849785+00:00.
pid-17376 thread-140735191843600 (MainThread) Greetings, program! It's PAYDAY!!!!
pid-17376 thread-140735191843600 (MainThread) Prepared the DB.
pid-17376 thread-140735191843600 (MainThread) Holding 3636 cents ($35.00 + $1.36 fee = $36.36) on Balanced for lgtest ... succeeded.
pid-17376 thread-140735191843600 (MainThread) Captured 3636 cents ($35.00 + $1.36 fee = $36.36) on Balanced for lgtest
pid-17376 thread-140735191843600 (MainThread) Captured 1 card holds.
pid-17376 thread-140735191843600 (MainThread) Canceled 0 card holds.
pid-17376 thread-140735191843600 (MainThread) Updated the balances of 3 participants.
pid-17376 thread-140735191843600 (MainThread) Starting payout loop.
pid-17376 thread-140735191843600 (MainThread) Crediting Gittip 2500 cents ($25.00 - $0.00 fee = $25.00) on Balanced ... succeeded.
pid-17376 thread-140735191843600 (MainThread) UNREVIEWED: whit537
pid-17376 thread-140735191843600 (MainThread) Did payout for 2 participants.
pid-17376 thread-140735191843600 (MainThread) Checked the DB.
pid-17376 thread-140735191843600 (MainThread) Updated payday stats.
pid-17376 thread-140735191843600 (MainThread) Updated receiving amounts.
pid-17376 thread-140735191843600 (MainThread) Script ran for {age} (0:00:05.311580).

@Changaco
Copy link
Contributor Author

I don't think we really need the maxconn restriction so I've removed it.

@chadwhitacre
Copy link
Contributor

@Changaco I'm pretty sure that statement_timeout only applies at the connection level. If we're using multiple connections during payday and we only set statement_timeout on one of them and we get a long query on a second connection then the we'll hit an error and payday will crash. If we think that all of our queries during payday will be below the default limit (30 seconds?) then we should remove the statement_timeout configuration entirely, to be added back once we find we need it again.

@chadwhitacre
Copy link
Contributor

@chadwhitacre
Copy link
Contributor

#1600 has backstory on statement_timeout.

@chadwhitacre
Copy link
Contributor

I'm trying to see what the current setting for statement_timeout is. At #1541 (comment) I say that I set it to 10 s, but I don't say how I did that. select * from pg_settings where name='statement_timeout'; shows 0. Did I configure this in a different (per-user?) place? Did we clobber the setting during a db upgrade?

@Changaco
Copy link
Contributor Author

Should we make the error handling parallel in payout? That is, can we do away with the try/except block in there around ach_credit?

We can, but we'll lose the UNREVIEWED: log messages.

No test?

We can add one of course, I simply forgot.

@chadwhitacre
Copy link
Contributor

An UPDATE applied to a row of pg_settings is equivalent to executing the SET command on that named parameter. The change only affects the value used by the current session.

http://www.postgresql.org/docs/9.3/static/view-pg-settings.html

@chadwhitacre
Copy link
Contributor

Not seeing statement_timeout in select rolname, rolconfig from pg_roles; either. :-/

Reticketed as #2601.

@chadwhitacre
Copy link
Contributor

We can, but we'll lose the UNREVIEWED: log messages.

Did we lose those message on the payin side?

@Changaco
Copy link
Contributor Author

Did we lose those message on the payin side?

I'm not sure.

@Changaco
Copy link
Contributor Author

On second thought it's trivial to keep the log message, I've added a commit that removes the try/except block but keeps the log message.

@chadwhitacre
Copy link
Contributor

On second thought it's trivial to keep the log message, I've added a commit that removes the try/except block but keeps the log message.

Awesome, good call!

@chadwhitacre
Copy link
Contributor

I simulated a payday crash and ended up with a balance conflict when rerunning. Sorry, I don't have more detailed information about where in the payday cycle the crash hit.

Wed Jul 30 17:51:20 UTC 2014
pid-18561 thread-140735191843600 (MainThread) Starting a new payday.
pid-18561 thread-140735191843600 (MainThread) Payday started at 2014-07-30 17:51:21.438705+00:00.
pid-18561 thread-140735191843600 (MainThread) Greetings, program! It's PAYDAY!!!!
pid-18561 thread-140735191843600 (MainThread) Prepared the DB.
pid-18561 thread-140735191843600 (MainThread) Holding 3636 cents ($35.00 + $1.36 fee = $36.36) on Balanced for lgtest ... succeeded.
pid-18561 thread-140735191843600 (MainThread) Captured 3430 cents ($33.00 + $1.30 fee = $34.30) on Balanced for lgtest
pid-18561 thread-140735191843600 (MainThread) Captured 1 card holds.
pid-18561 thread-140735191843600 (MainThread) Canceled 0 card holds.
pid-18561 thread-140735191843600 (MainThread) Updated the balances of 3 participants.
pid-18561 thread-140735191843600 (MainThread) Starting payout loop.
pid-18561 thread-140735191843600 (MainThread) UNREVIEWED: whit537
Traceback (most recent call last):
  File "/Users/whit537/personal/gittip/www.gittip.com/env/bin/honcho", line 9, in <module>
    load_entry_point('honcho==cfcc7ebb', 'console_scripts', 'honcho')()
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/honcho/command.py", line 241, in main
    args.func(args)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/honcho/command.py", line 169, in command_run
    p.wait()
  File "/Users/whit537/lib/python2.7/subprocess.py", line 1357, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/Users/whit537/lib/python2.7/subprocess.py", line 478, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt

Wed Jul 30 17:53:34 UTC 2014
pid-18582 thread-140735191843600 (MainThread) Picking up with an existing payday.
pid-18582 thread-140735191843600 (MainThread) Payday started at 2014-07-30 17:51:21.438705+00:00.
pid-18582 thread-140735191843600 (MainThread) Traceback (most recent call last):
pid-18582 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gittip/cli.py", line 28, in payday
pid-18582 thread-140735191843600 (MainThread)     Payday.start().run()
pid-18582 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gittip/billing/payday.py", line 102, in run
pid-18582 thread-140735191843600 (MainThread)     self.db.self_check()
pid-18582 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gittip/models/__init__.py", line 17, in self_check
pid-18582 thread-140735191843600 (MainThread)     check_db(cursor)
pid-18582 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gittip/models/__init__.py", line 23, in check_db
pid-18582 thread-140735191843600 (MainThread)     _check_balances(cursor)
pid-18582 thread-140735191843600 (MainThread)   File "/Users/whit537/personal/gittip/www.gittip.com/gittip/models/__init__.py", line 96, in _check_balances
pid-18582 thread-140735191843600 (MainThread)     assert b == 0, "conflicting balances: {}".format(b)
pid-18582 thread-140735191843600 (MainThread) AssertionError: conflicting balances: 1

@chadwhitacre
Copy link
Contributor

Why name the temporary tables pay_foo instead of payday_foo?

@Changaco
Copy link
Contributor Author

I'm not sure why, but I can rename them if you want.

@Changaco
Copy link
Contributor Author

I simulated a payday crash and ended up with a balance conflict when rerunning. Sorry, I don't have more detailed information about where in the payday cycle the crash hit.

Hmm, can you dump the DB so that I can inspect the participants and exchanges?

@Changaco
Copy link
Contributor Author

@whit537 I believe I've found the problem, I've added commits to fix it and prevent future problems from going undetected like this one.

@chadwhitacre
Copy link
Contributor

@Changaco I think we should write a script to populate a Balanced marketplace with users and credit cards and bank accounts according to last_{ach,bill}_result in a DB backup. I'm willing to work on that when I get back to this next week.

@Changaco
Copy link
Contributor Author

@Changaco Did you address this and I missed it?

No, I forgot to answer that. I'm not sure it's a good idea to stop withholding money for the following week. I think we should keep the current behavior for now.

Okay, but without that condition we'd end up with negative balances, right? That condition is what ensures that we pass over some tips, even while we accept further downstream tips.

Yes.

@chadwhitacre
Copy link
Contributor

I'm not sure it's a good idea to stop withholding money for the following week. I think we should keep the current behavior for now.

Hmm ... this was one of the driving concerns on #1486. What's the reason not to make that change here?

@Changaco
Copy link
Contributor Author

Hmm ... this was one of the driving concerns on #1486. What's the reason not to make that change here?

#1486 is not about holding escrow, it's about unnecessarily high credit card charges, and that's fixed in the payday rewrite by implementing card holds. You're probably thinking of #1383.

@chadwhitacre
Copy link
Contributor

@Changaco #1486 quotes from Twitter:

A little math upfront would not only lessen fees, but help avoid the 52K in escrow, which feels like a scam.

@Changaco
Copy link
Contributor Author

The withholding mechanism is only responsible for $573.75 of our current escrow.

select sum(balance) from participants where last_ach_result is not null and balance = giving+pledging;

@chadwhitacre
Copy link
Contributor

The withholding mechanism is only responsible for $573.75 of our current escrow.

Okay, fair enough. I guess if I'm honest, I was personally hoping to get that $150 I've got stuck in Gittip right now, but that's a bad basis for this decision. :-)

@chadwhitacre
Copy link
Contributor

Okay! I think we might be close, @Changaco! 💃 What's left to do here?

@Changaco
Copy link
Contributor Author

@whit537 Review #2610 and #2620 and merge them into this one. You could also give another try to #2611.

Changaco and others added 3 commits August 12, 2014 14:27
chadwhitacre added a commit that referenced this pull request Aug 12, 2014
@chadwhitacre chadwhitacre merged commit e9d037d into master Aug 12, 2014
@chadwhitacre
Copy link
Contributor

!m @Changaco

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants