Commit Graph

64 Commits

Author SHA1 Message Date
Durham Goode
ff04a6d5e2 Fetch verification data in batches
Summary:
I was seeing errors where mysql timed about because it was fetching too much
data during the rev validation stage. So let's change it to verify the revs in
batches.

Test Plan:
Tests pass, I also deployed it to a hg server and pushed changes to
it.

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.fb.com/D2396632
2015-08-28 18:14:19 -07:00
Durham Goode
3a211d0cce Don't eat exceptions during sqlunlock
OperationalError exceptions were being hidden by "MySQL server has gone away"
exceptions caused by the unlock. We already accounted for certain kinds of
exceptions, so we just need to add the other type to the list.

Tested it by hotfixing a server.
2015-08-27 21:27:53 -07:00
Durham Goode
41ea00a0cc Handle exceptions on the background fetch thread
Summary:
We've seen some hg processes hang on the Mercurial servers because
mysql throws an exception on the background thread and the foreground thread
just waits forever.

This patch catches background exceptions and sends them to the foreground for
throwing.

Test Plan:
I'm not sure how to cause an exception via test, but I manually
verified it works by adding a 'raise Exception(...)' to the background thread
and running the tests and verifying the exception showed up.

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.fb.com/D2337535
2015-08-12 11:10:25 -07:00
Durham Goode
1782ee1a10 Update revlog.addgroup to match upstream
Upstream added a new addrevisioncb parameter to addgroup. This just updates our
code to use it.
2015-07-22 15:50:55 -07:00
Ryan McElroy
cf0e8435a3 Use FORCE INDEX to prevent full table scans
Summary:
We suspect that these delete statements sometimes cause full table
scans which lock up the table and cause lock wait timeout errors from other
repositories. By forcing the index, we should prevent the scan and prevent
these errors from happening, increasing hgsql throughput.

Test Plan: ./run-tests.py

Reviewers: #sourcecontrol, durham, ebergen

Reviewed By: ebergen

Subscribers: durham

Differential Revision: https://phabricator.fb.com/D2235417

Tasks: 7462484

Signature: t1:2235417:1436579460:b0d0193db4c2d799c8263fb2225b70b8762eb06f
2015-07-10 18:39:01 -07:00
Durham Goode
98db3044fd Remove use of sopener
Upstream has removed repo.sopener, so switch it.  Also fix a flakey test.
2015-07-08 21:23:54 -07:00
Durham Goode
235a2d4a1a hooks: disable all pretxnclose hooks during sync
Summary:
pretxnclose hooks were incorrectly running during the sql sync. Since the
commits have already been committed (on another machine), there's no need to run
the hooks, so let's disable them.

Test Plan: Added a test

Reviewers: pyd, lcharignon, akushner, rmcelroy

Differential Revision: https://phabricator.fb.com/D2173886
2015-06-19 12:45:16 -07:00
Durham Goode
e12f55e798 hgssh: override readonly hook in hgssh
Summary:
The hg-ssh wrapper prevents all transactions from running, including the one we
use to sync our repositories from hgsql. This patch updates hgsql to override
that hook temporarily during syncs.

This wasn't an issue before because upstream mercurial used to hook on
prechangegroup which hgsql did not fire.

Test Plan: Added a test. Verified it failed before, and passes now.

Reviewers: pyd, lcharignon, rmcelroy, sid0

Differential Revision: https://phabricator.fb.com/D2148580
2015-06-11 14:37:03 -07:00
Ryan McElroy
ef88578b6b hgsql: always commit before refreshing references
Summary:
This can't hurt anything, and it makes sure we have a fresh
transaction for the references which have been timing out, strangely.

Test Plan: run_tests.py

Reviewers: durham

Reviewed By: durham

Subscribers: durham

Differential Revision: https://phabricator.fb.com/D2137954

Signature: t1:2137954:1433811692:1234cde23efd2fa8a95ad87453390aa8edeb335d
2015-06-08 17:35:09 -07:00
Ryan McElroy
e9b78c142a hgsql: batch sql inserts
Summary: this may be more performant in practice

Test Plan: run tests

Reviewers: durham

Reviewed By: durham

Subscribers: durham

Differential Revision: https://phabricator.fb.com/D2137916

Signature: t1:2137916:1433811302:32c45a163caa70654150945e3dc62ca197331b65
2015-06-08 17:24:14 -07:00
Durham Goode
ca017a211a Allow configuring innodb_lock_wait_timeout
We're encountering server failures with "Lock wait timeout exceeded" issues.
Let's allow us to crank up the timeout via a config.

Also update a test which is mildly out of date.
2015-05-27 14:32:15 -07:00
Durham Goode
c02edfe335 Update for bundle2 and new transaction hooks
Summary:
Upstream has changed bundle2 and the transaction hooks. We need to update to
match them. There is now a validator function on transactions that runs the
pretxnclose hooks. We now wrap that to make sure our db commit happens after
the hooks have run.

Test Plan: Fixed the tests to cover the new hooks

Reviewers: sid0, rmcelroy, lcharignon, pyd, ericsumner

Reviewed By: ericsumner

Differential Revision: https://phabricator.fb.com/D2015133

Signature: t1:2015133:1429904252:d0f1fe226df1cc97a3e1da0d9dd6b2ac6ccf8a1a
2015-04-22 15:10:26 -07:00
Eric Sumner
9383d6d113 hgsql: fix a bunch of test errors
Summary:
* Update ##run-tests##
* Fix bundle names
* Add new argument to ##_addrevision##

Still 1 broken test

Test Plan: ##run-tests##

Reviewers: sid0, daviser, davidsp, mitrandir, akushner, pyd, mpm, rmcelroy, durham

Reviewed By: durham

Differential Revision: https://phabricator.fb.com/D1816601

Tasks: 6118847

Signature: t1:1816601:1422917211:60d8c222a726b16fe004b16d9ab8f0a1ee7d9d3e
2015-01-30 15:15:19 -08:00
Durham Goode
950fb8ecf1 Take sql lock for local repo during push
Upstream Mercurial now takes the source repo lock during a push because it might
update the source phase data. Consequently, we need to wrap this with a sqllock.

A test caught this.
2015-01-06 10:16:35 -08:00
Durham Goode
d549d44a85 Fix bookmark writing as part of transactions
Summary:
Bookmarks could get prematurely written to sql if hooks were invoked
during a bundle2 transaction. If the transaction was then aborted, we could be
left in a state where the bookmarks had been written, but the commits had not.

The fix is to only write bookmarks outside the transaction if bookmarks.write()
is explicitly called.  Otherwise we write them as part of transactionclose, just
like the revlog entries.

Test Plan: Ran the tests.

Reviewers: sid0, pyd

Reviewed By: pyd

Differential Revision: https://phabricator.fb.com/D1711961

Signature: t1:1711961:1417549773:044611a63de2376c64c218404cdb1e04337ced3d
2014-12-01 17:30:20 -08:00
Durham Goode
0f9e86390a Remove unnecessary reorder counter 2014-12-01 17:33:40 -08:00
Ryan McElroy
f0240b2404 Fixup the forcesync change
Summary:
I made a last minute change to the last diff that broke it. Thought it through
and got the intended fix behavior while still being correct.

Test Plan: actually run the test

Reviewers: durham, sid0, davidsp

Differential Revision: https://phabricator.fb.com/D1683661
2014-11-14 18:01:56 -08:00
Ryan McElroy
4eb49056eb Make forcesync only acquire local repo lock
Summary:
Previously, the --forcesync flag would cause the command to acquire the
sqllock, which would mean a read only command would block for any ongoing write
commands to complete, which is undesirable. Now, we will wait for the lcoal repo
lock only, instead of skipping the sync as we did before the initial patch.
This ensures that forcesync operations will see all committed changes, but won't
wait for ongoing write transactions from other masters.

Test Plan: updated test

Reviewers: sid0, davidsp, pyd, mpm, durham

Reviewed By: durham

Differential Revision: https://phabricator.fb.com/D1682970

Signature: t1:1682970:1416014352:e7f3daa09e79abd43a16c8eb74bc69272d73c83d
2014-11-14 10:53:35 -08:00
Durham Goode
a619ce459a Updated to work with bundle2
Local pushing and pulling with bundle two goes through exchange.unbundle, so we
need to wrap that now. Also did some minor grouping of the wrapping's. The only
new one is for exchange.unbundle.

Tested it by enabling bundle2 for all the tests and running it without my change
and with my change.
2014-11-04 17:41:13 -08:00
Ryan McElroy
8d592b5f2d Add forcesync global option to hgsql
Summary:
When enabled, forcesync enables a read-only caller to force a DB sync. This
allows a simple command like 'hg log -l 1' to still ensure a full sync occurs.

Test Plan: updated test

Reviewers: durham, sid0, davidsp, pyd, mpm

Reviewed By: durham

Differential Revision: https://phabricator.fb.com/D1643055

Tasks: 5456657
2014-10-27 13:56:13 -07:00
Durham Goode
53fffdadd1 Update bookmark write handling
Upstream Mercurial no longer always calls bookmark.write to serialize the
bookmarks. Now it sometimes goes through the transaction API which calls
bookmark._write.
2014-10-14 17:07:18 -07:00
Durham Goode
1a28710032 Fix sqlstrip with multi-digit revision
Summary:
The sqlstrip command had a bug where a multidigit revision, like '5381' would be
treated like a string, sorted, and the first digit taken.  So we always
sqlstripped one of the first revs in the repository.

This fixes that to treat rev like an integer, and removes the sort (which was a
legacy bit of code from when sqlstrip supported multiple integers).

Test Plan: Ran the tests.

Reviewers: sid0, pyd, davidsp

Differential Revision: https://phabricator.fb.com/D1580556
2014-09-25 18:15:17 -07:00
Siddharth Agarwal
01295e337a fix compatibility with Mercurial 3.2
Summary: Mercurial rev f8c397b4362c changed the API for `phases.advanceboundary`. A different rev also added a benign 'activating bookmark' message.

Test Plan: Ran the tests.

Reviewers: durham

Reviewed By: durham

Differential Revision: https://phabricator.fb.com/D1561665

Tasks: 5170539
2014-09-17 13:53:22 -07:00
Durham Goode
faf7475d75 Revert previous change and fix local phase moves
The previous change that allowed transactions that didn't touch revlogs was
broken. It allowed transactions like 'strip', etc. This reverts that.

To fix the actual issue we were trying to fix before, we now add a sql
transaction around local phase moves as part of exchange.
2014-08-26 03:51:11 -07:00
Durham Goode
731d9a18cb Allow transactions that don't touch the changelog
Recent upstream Mercurial changes have moved the phase cache into a transaction.
We don't sync phases as part of hgsql (everything is just public), so lets allow
transactions as long as they don't touch revlogs.

This was necessary because pushing between local repos was broken by this.
2014-08-20 15:41:42 -07:00
Durham Goode
bad33b03ec Add README and COPYING 2014-08-04 19:38:52 -07:00
Durham Goode
78c03a44c9 Add sqlstrip command
Summary:
Adds an 'hg sqlstrip' command that strips commits from the local repo and from
the database. Since this modifes the database, all other server hosts will
suddenly become out of sync, so ideally this command should be run on all the
server hosts at the same time.

Test Plan: Added a test and ran it

Reviewers: sid0, pyd, dschleimer, davidsp

Reviewed By: davidsp

Differential Revision: https://phabricator.fb.com/D1422865
2014-07-07 16:10:26 -07:00
Durham Goode
6a80d92d31 Hide unnecessary sql warning
Commit 70d94df78f11 tried to hide this benign warning, but did it at the wrong
spot. This does it at the right spot (around cursor.close()).

This is the description from the original commit:
The revision_references table has multiple unique keys (primary key, and a unique
name index). Using ON DUPLICATE KEY in an INSERT causes a warning, since it will
only update one of the rows, even if there are two duplicates. We can safely
ignore this since we know there will only ever be one row that has a duplicate
key.
2014-04-17 11:09:48 -07:00
Durham Goode
e1c9858952 Change expected rev validation to use the builtin sql escaping
Previously we escaped path names ourselves, but this didn't remove %'s from the
paths, which could break the sql libraries ability to format queries with args.

Now we use the actual sql libraries builtin formatting.
2014-04-17 10:33:37 -07:00
Durham Goode
a109789413 Move addchangegroup to match Mercurial upstream
localrepository.addchangegroup got moved to changegroup.addchangegroup in
upstream Mercurial. So we need to move it accordingly.
2014-04-09 10:56:53 -07:00
Durham Goode
a3a66d460a Hide mysql warning when updating a row with multiple unique keys
The revision_references table has multiple unique keys (primary key, and a unique
name index). Using ON DUPLICATE KEY in an INSERT causes a warning, since it will
only update one of the rows, even if there are two duplicates. We can safely
ignore this since we know there will only ever be one row that has a duplicate
key.
2014-03-19 13:06:20 -07:00
Durham Goode
40472c5f28 Allow local commits 2014-03-13 12:42:20 -07:00
Durham Goode
d64b28c7f5 Verify write lock before writing to db
Check with the actual database to ensure we are the ones with the write lock
before performing the actual lock. We encountered an issue previously where two
writers managed to write at once, which this should now catch.
2014-03-12 12:52:27 -07:00
Durham Goode
d355928627 Switch to a single write_lock for commits and bookmarks 2014-03-12 12:35:04 -07:00
Durham Goode
8059a8f932 Take bookmark lock for duration of pulls
Summary:
In certain pull use cases (hg pull -B foo), it tries to update the bookmarks
outside of the normal bookmark.updatefromremote() function. This takes the lock
at the very beginning of the pull so all inner bookmark manipulations should
succeed.

Test Plan:
Ran the new test with and without the fix, verified it failed before
and passed afterwards.

Reviewers: sid0, davidsp

Differential Revision: https://phabricator.fb.com/D1214148
2014-03-11 11:25:23 -07:00
Durham Goode
75f687460a Replace (path,rev,chunk) IN (....) query since it didn't use an index
It turns out mysql doesn't optimize '(a,b,c) IN ((x,y,z),(m,n,o),...)' queries,
so we want to avoid using them.
2014-03-10 14:52:31 -07:00
Durham Goode
e35323e658 Make the waittimeout configurable 2014-03-07 16:29:09 -08:00
Durham Goode
0f98887c95 Fix pushing and pulling bookmarks from local repos
Pushing and pulling local bookmarks was a bit broken, since as soon as the
bookmark dict tried to write, it would sync with the db, which overwrote the
current bookmarks.

This changes it to require the sql connection to be set up and locked before
the bookmark modifications even start to happen.
2014-02-18 17:16:45 -08:00
Durham Goode
f7cb418f63 Fix pushing and pulling from a local repo 2014-02-18 15:59:46 -08:00
Durham Goode
8e1cbbb098 Don't block readonly operations when the repo needs updating
Previously, if the repo needed to be synced, every command would block and
wait until the repo was synced.  So if one command was doing the update, all
the other parallel commands (even the readonly ones) would be blocked.

This changes it so readonly commands (i.e. commands that don't require locking
the db) can be executed even if the repo is slightly out of date. The downside
of this is a user may get a slightly old (by seconds) version of the repo when
doing a pull.
2014-02-06 14:39:57 -08:00
Durham Goode
3bee69cba0 Rename pushkeys table to revision_references 2014-02-03 14:18:38 -08:00
Durham Goode
3cb8d47272 Fix pushing bookmarks
Bookmarks were failing to write to the database when pushed (but worked fine
when pulled) because the executewithsql around the bookmark writing would sync
the bookmark dict and overwrite the pending bookmarks.

The new logic takes the lock up at the pushkey level. Also had to add support
for nesting locks so both the pushkeys and the bookmark write could take the
bookmarks_lock.
2014-01-28 20:46:23 -08:00
Durham Goode
bc08b5e4b9 Add comments around rev reordering 2014-01-27 18:50:24 -08:00
Durham Goode
32863d5aa7 General clean up and maxrowsize configuration
Fixes up some comments and function descriptions.

Adds hgsql.maxrowsize configuration option with a default value of 1MB.
2014-01-23 19:22:49 -08:00
Durham Goode
bfe1b6458d Add configuration for a maximum transaction size
MySQL has limits on how large a transaction can become, so if a commit is
larger than that we need to break it into several database transactions. To
keep the atomic nature of the repo table, we add a new pushkey namespace 'tip'
that contains the latest valid linkrev for that repo in the table. Then at the
very end we update the 'tip' marker (along with the heads).

When syncing, the repo only syncs up to the tip commit.

When making a commit, it first cleans up any abandon commits by deleting
any rows that have a linkrev greater than the tip.
2014-01-23 18:40:55 -08:00
Durham Goode
8ab51eaa9f Add pending revision validation
Before writing revisions to the database we now validate that they are
correct. This consists of two checks:

1. Are we appending to the same linkrev in the database as we are in the local
repo.
2. Every rev that we are writing to the database has a base, p1, and p2 rev
dependency. Before we write the rev, verify that the base, p1, and p2 revs in
the database have the same nodes as in the localrepo. This prevents us from
writing rev dependencies that then point at the incorrect node (due to
different ordering in the db vs local).
2014-01-21 16:09:08 -08:00
Durham Goode
9f0b718461 Allow nested connections
When performing a pull it does the commits, then the bookmarks. This change
allows the sql connections to become nested, enabling that.
2014-01-21 16:06:25 -08:00
Durham Goode
97167ab6c4 Add node information to revisions table
In order to validate that the incoming revisions are valid, we need node
information in the revisions table. A future patch will add the actual
validation.
2014-01-21 16:05:27 -08:00
Durham Goode
6e3be66ba0 Add more verification during syncs
Check that heads and bookmarks match after syncing.
Verify that the new commits are being applied on top of the correct linkrev on
the server.
Remove excess invalidate steps. They are no longer necessary since we do the
lock.release() much later in the process (which was what caused problems
originally).
2014-01-03 12:03:52 -08:00
Durham Goode
52fa7e03b2 Wrap revlog._writeentry instead of intercepting
I added revlog._writeentry to upstream Mercurial which allows us to easily
intercept revlog writes instead of building crazy file-like objects to
intercept the calls.
2014-01-03 12:01:50 -08:00