Commit Graph

138 Commits

Author SHA1 Message Date
Durham Goode
b081b91010 sqlreplay: add start and end rev options
To enable incremental replays, let's add start and end args to the sqlreplay
command.
2017-03-30 15:51:59 -07:00
Durham Goode
b420424f78 fixtests: fixes some incorrect tests relating to treemanifest
The previous commits added treemanifest integration, but the tests weren't
actually accurate. By enabling treemanifest.server=True before making any
commits, it turns out we were creating trees during commit. So all the backfill
and replay logic wasn't actually doing anything.

This patch fixes the tests by moving the treemanifest.server=True bit to later
on, and fixes a bug in the code around needing to not validate that the added
revision linkrevs are newer than tip, since backfilltree and sqlreplay are meant
to add old data.
2017-03-30 13:36:37 -07:00
Durham Goode
baca6adcbf replay: add sqlreplay command
Summary:
The sqlreplay command goes through all the revisions in the database and
attempts to replay them onto the local revlogs.  Any revisions which already
exist in the revlog are skipped, but revisions that aren't in the revlog are
applied to the end of the revlog, with the same verification that is normally
used when applying revisions (i.e. it's being applied at the right file offset
and the parents and delta base nodes are already present).

This is usual when migrating the repository to a new format, like when switching
to treemanifests.

Test Plan: Added a test

Reviewers: #mercurial, rmcelroy

Reviewed By: rmcelroy

Subscribers: rmcelroy

Differential Revision: https://phabricator.intern.facebook.com/D4801108

Signature: t1:4801108:1490869053:920db3a86801612ec56d6c076b5854bb9a44ca62
2017-03-30 09:39:50 -07:00
Durham Goode
5d5a071511 treemanifest: test syncing of trees created during push
Summary:
treemanifest interacts with pushrebase to create trees during push, even if the
client sends a flat manifest. This patch adds a test to verify that those trees
are sent to sql and replicated.

Test Plan: Added a test

Reviewers: #mercurial, simonfar

Reviewed By: simonfar

Differential Revision: https://phabricator.intern.facebook.com/D4801107

Signature: t1:4801107:1490883109:6818cbc96038ac6e63e4e6dd3d619775c6d8c26c
2017-03-30 09:39:47 -07:00
Durham Goode
3f1b2f3117 treemanifest: enable the backfilltree command
Summary:
The backfilltree command is a command in the treemanifest extension that can
retroactively create new revlog entries for treemanifests. hgsql needs to
provide a sql connection for this write so the new entries can be synced to sql.

A future patch will add a new hgsql command for replaying these old writes into
an existing repository, since they won't automatically be replayed since the
linkrevs are older than the tip linkrev (and syncing works by only replaying
newly added revisions).

Test Plan: Added a test. Also ran it on an internal repo.

Reviewers: #mercurial, simonfar

Reviewed By: simonfar

Differential Revision: https://phabricator.intern.facebook.com/D4801101

Signature: t1:4801101:1490883142:a8bd2968a22d7d7f89a9ce626502504a464c9f11
2017-03-30 09:39:44 -07:00
Durham Goode
066f6aa0b0 bookmarks: incrementally update local bookmarks
Summary:
Debugging showed that readding all the bookmarks (especially the old ones) took
a significant amount of time. Let's optimize the bookmark sync to do the minimal
number of adds/deletes instead.

Test Plan: Adds a test for bookmark deletes since it didn't exist before.

Reviewers: simonfar, #mercurial, quark

Reviewed By: quark

Subscribers: quark

Differential Revision: https://phabricator.intern.facebook.com/D4792724

Signature: t1:4792724:1490749918:33e661ffd042a3281c42eee6164f2f669398178b
2017-03-29 14:47:53 -07:00
Durham Goode
5b35b8b9b1 caching: recreate mfctx instead of reusing
Summary:
The upstream manifestctx class has changed to keep a reference to the
manifestlog instead of to the repo. This means that if we access an old mfctx
after repo.manifestlog has been invalidated, it will still have a reference to
the old manifestlog and the old manifestrevlog.

This created a bug where writes would fail because they saw the old
manifestrevlog, and even worse, they would truncate the manifest revlog back to
the last state that process had seen it (i.e. from before the latest db sync),
instead of truncating just the writes done by this transaction.

Test Plan:
I copied it to a server that had issues before the change, and
verified that it no longer truncated the manifest revlog incorrectly.  I'm still
trying to think how I could reproduce the issue in a test.

Reviewers: #mercurial, phillco

Reviewed By: phillco

Differential Revision: https://phabricator.intern.facebook.com/D4789920

Signature: t1:4789920:1490735433:187e8b22d7ce89bfb2f88d9fc3c9932842bab4f8
2017-03-28 14:48:49 -07:00
Jun Wu
92eadab685 hgsql: test non-ascii paths
Summary:
The test is to check whether `varchar CHARACTER SET latin1 COLLATE latin1_bin`
works just fine or not.

Sadly it does not. And `varbinary` makes the test pass, as expected.

For now, this diff only changes the `path` field, other fields like
`revision_references.name` etc should use `varbinary` in theory. But they are
less concerning than `path` because they don't impact real repo content. Using
`varchar`, MySQL clients are happy to display the contents, instead of showing
a placeholder like "(BLOB)".

Test Plan: `run-tests.py *.t`

Reviewers: #sourcecontrol, rmcelroy

Reviewed By: rmcelroy

Subscribers: rmcelroy

Differential Revision: https://phabricator.intern.facebook.com/D4774735

Signature: t1:4774735:1490700636:61a3dc46476b37b3c32e6a022d5791be2c3ea965
2017-03-24 16:19:13 -07:00
Jun Wu
b9e1b30800 hgsql: add a note about MariaDB compatibility
Summary:
MariaDB is a well-known project as a drop-in replacement for MySQL. Some
Linux distributions (ex. Arch Linux) ship it by default.

I cannot get MariaDB pass `test-sync.t`. The server seems to close the
connection early and the client (the hg server) gets something like:

  2055: Lost connection to MySQL server at 'localhost:3306', system error: 32 Broken pipe

I gave up figuring out what's going on after a few hours, and think it may
save others some time if we write down the issue.

Test Plan: spellchecker

Reviewers: #sourcecontrol, rmcelroy

Reviewed By: rmcelroy

Subscribers: rmcelroy

Differential Revision: https://phabricator.intern.facebook.com/D4774842

Signature: t1:4774842:1490401350:9937e8021953fcbaee0cbc7809c243d9bb24d744
2017-03-24 16:41:27 -07:00
Jun Wu
8d54b2b3ed hgsql: add more checks before running tests
Summary:
Add two tests so tests can be skipped early instead of dumping stack traces:
- If the Python module `mysql.connector` is not available, skip.
- If the `mysql` command fails, skip.

Test Plan:
Normally, test passed:

  $ run-tests.py test-sync.t
  .

Without mysql.connector:

  $ mv /usr/lib/python2.7/site-packages/mysql/connector{,2}
  $ run-tests.py test-sync.t
  s
  Skipped test-sync.t: mysql-connector-python missing

With a wrong `getdb.sh`:

  $ echo 'DBPORT=9999' >> getdb.sh
  $ run-tests.py test-sync.t
  s
  Skipped test-sync.t: unable to initialize the database. check your getdb.sh


Reviewers: #sourcecontrol, rmcelroy

Reviewed By: rmcelroy

Differential Revision: https://phabricator.intern.facebook.com/D4772997

Signature: t1:4772997:1490400442:cf67ee406ee12905042cb0faf1053e355eda2ea7
2017-03-24 14:01:13 -07:00
Jun Wu
89744897fb hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:

  ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

This is a cleanup of many minor areas to make it easier for external users
to run the test.

  * Move database schema to `schema.sql`, which could be used as `mysql`
    input directly. Remove schema in other places so `schema.sql` is the
    single source of truth.
  * Change `repo`, `namespace` fields to `varchar` to save space.
  * Explicitly set `latin1(_bin)` in schema to avoid potential encoding
    issues. Also specify `InnoDB` to avoid issues of other engines.
  * Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
  * Provide an example of `getdb.sh` as `getdb.sh.example`.
  * Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
    dropped automatically.
  * Change `README.md` with the latest instruction about database and test.
  * Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.

Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.

Reviewers: #sourcecontrol, rmcelroy

Reviewed By: rmcelroy

Subscribers: stash, rmcelroy, tja, durham, andrasbelo

Differential Revision: https://phabricator.intern.facebook.com/D4313981

Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-23 19:14:52 -07:00
Durham Goode
cdf09f0b65 lock: log lock time for failures
Summary:
Previously we were not logging sqllock wait times for waits that timed out. This
adds that, and adds a variable to indicate if the lock succeed or failed.

Test Plan: Added a test for the ui.log metrics

Reviewers: #mercurial, quark

Reviewed By: quark

Subscribers: quark

Differential Revision: https://phabricator.intern.facebook.com/D4295786

Signature: t1:4295786:1481154111:442b55f230b53add4e0966223af165f5195ba8b4
2016-12-07 15:46:09 -08:00
Durham Goode
cf47efa200 lock: make sync check more robust
Summary:
Previously we detected if we were in the middle of a sync by checking if the
sync limiter lock was taken. This lock is not actually taken during a sync where
we force it to sync. So let's replace _synclock with a more robust
self._issyncing boolean.

Test Plan:
Did some manual testing with break points. My last attempt was just
naive, so this isn't a big change.

Reviewers: #mercurial, quark

Reviewed By: quark

Differential Revision: https://phabricator.intern.facebook.com/D4289240

Signature: t1:4289240:1481071402:e2a448a2739bff3eecfea90a6fd7a0376b944adb
2016-12-06 17:10:25 -08:00
Durham Goode
a6491a0b9c locks: add logging for invalid lock order taking
Summary:
We've been seeing some issues where non-write processes (like clone) are taking
the wlock/lock without taking the sqllock. This causes processes which do want
the sqllock (like pushes) to hang waiting. Streaming clones are one known case
of this, but this extra logging will help us catch other cases.

Once we're confident that nothing takes the wrong lock ordering, we can change
this to throw an exception instead of logging the error.

This required a minor refactor the synclimit code, so we can detect if we're in
a sync lock (which is a case where it's ok to take the wlock/lock without taking
the sqlock). And it configures the tests to use streaming clones when possible,
which trigger the current known bug.

Test Plan: Added a test

Reviewers: #mercurial, quark

Reviewed By: quark

Subscribers: quark

Differential Revision: https://phabricator.intern.facebook.com/D4287384

Signature: t1:4287384:1481065929:dfac78e3537c3cdf44c810bc99c5f07ed5b12f4c
2016-12-06 16:04:20 -08:00
Durham Goode
593af04245 metrics: change elapsed time to ms for sqllock metric
Summary:
Internally we are now logging the sqllock times to our metrics infrastructure.
It's easier if the numbers are integers, so let's turn the elapsed sqllock time
into milliseconds. We leave the user readable message alone though.

Test Plan: doitlive

Reviewers: #mercurial, quark

Reviewed By: quark

Differential Revision: https://phabricator.intern.facebook.com/D4287378

Signature: t1:4287378:1481065691:5ae3b259598692a41927c793dab1bc2c847acae0
2016-12-06 16:04:09 -08:00
Durham Goode
ccbf0a3566 manifest: update to work with upstream changes
Summary:
The manifest has been replaced with a manifestlog in upstream, so we need to
update our usage accordingly.

Test Plan: Ran the tests

Reviewers: #mercurial, quark

Reviewed By: quark

Differential Revision: https://phabricator.intern.facebook.com/D4198744

Signature: t1:4198744:1479408675:94fd5a5de367fcde1fc1ff16c0a88f052ef60a8d
2016-11-17 10:51:40 -08:00
Durham Goode
d61aae9385 races: load bookmarks earlier in no-sync cases
Summary:
In the past we've introduced code into hgsql that tries to load bookmarks into
memory very early in the process, so there's no chance of the bookmarks being
out of sync with the changelog. When we added the synclimiter short circuit code
path, we lost the ordered loading which has caused the master bookmark to seem
to disappear when users were doing a pull and the bookmark file changed after
they had already loaded the changelog.

A real fix should go upstream, but since hgsql wraps the repo object so tightly
(before anything else gets a chance to operate on it), putting a work around
here is a simple, high impact fix.

Test Plan: Ran the tests, but really the tests won't catch anything here.

Reviewers: #mercurial, quark

Reviewed By: quark

Subscribers: quark

Differential Revision: https://phabricator.intern.facebook.com/D4121849

Signature: t1:4121849:1478133009:3cad7decdc866e68872c93b884467dfbc17f850c
2016-11-03 10:22:46 -07:00
Durham Goode
27925e5fef Fix incremental updating of heads and bookmarks
Summary:
We had tried to be smart about incrementally updating only the heads and
bookmarks that actually changed, but the old logic was broken. It compared
binary and hex nodes against each other, and therefore didn't actually do
anything incrementally.

This patch makes us convert the Mercurial data to hex at the very beginning, so
the incremental check uses hex as well.

Test Plan:
Inserted print statements around the insert/delets and verified they
changed before and after

Reviewers: #mercurial

Differential Revision: https://phabricator.intern.facebook.com/D4012317
2016-10-13 09:47:40 -07:00
Simon Farnsworth
145b3a59b8 hgsql: Do not succeed in syncing if we failed to take locks
Summary:
We sometimes "succeeded" in syncing to the database if we could not get local write locks, because we assumed that the only time we can't get those locks is if we're not waiting for them. However, if another process holds the local write locks and is not releasing them, we hit a timeout.

If you're doing a write operation, this is harmless - the MySQL lock ensures that only one client at a time can be syncing anyway. However, for read operations run with `--forcesync`, this can cause us to succeed without syncing, breaking our contract with our users.

Test Plan:
Run the test suite and confirm no change.

Manually take the local write locks, run against the test DB `hg log -r . --forcesync`, and confirm that we fail correctly with this change but not without it.

Confirm that even with the local locks taken, `hg log -r .` returns success

Reviewers: durham

Reviewed By: durham

Subscribers: tja, #mercurial

Differential Revision: https://phabricator.intern.facebook.com/D3976452

Tasks: 13484857

Signature: t1:3976452:1475757832:e8370819bc345ce8e1bde0b057755803adb9896c
2016-10-07 05:25:21 -07:00
Jun Wu
f42f6a17ec hgsql: update tests to fix upstream compatibility
Summary:
Upstream a099aba68382 changed the words about backup bundles.
Let's update our tests.

Test Plan: Run the changed tests.

Reviewers: #sourcecontrol, stash

Reviewed By: stash

Differential Revision: https://phabricator.intern.facebook.com/D3949507

Signature: t1:3949507:1475221527:712dc13005a2860aac64293968472ab8de074f8c
2016-09-29 19:56:45 -07:00
Ryan McElroy
ed2da125a7 Check for proper location of pushrebase extension
Test Plan: run all tests; no more skipped tests

Reviewers: #mercurial, ttung, quark

Reviewed By: quark

Subscribers: quark

Differential Revision: https://phabricator.intern.facebook.com/D3819316

Signature: t1:3819316:1473091353:c695355d74576f879062865c22f0c675c9864367
2016-09-05 09:09:20 -07:00
Kostia Balytskyi
cc24c79882 fix wrong waiting period in test-race-conditions.t
Summary:
Currently test-race-conditions.t fails due to the
fact that we don't wait enough to cover the duration of
presyncdb hook.

Test Plan: run test-race-conditions.t a couple of times

Reviewers: simonfar, durham

Differential Revision: https://phabricator.intern.facebook.com/D3605295
2016-07-22 07:18:47 -07:00
Durham Goode
3f97d92346 bypass: add a hgsql.bypass config option for disabling hgsql
Summary:
Previously, if we needed to disable hgsql for some reason (like testing
corruption, etc) we would just disable the extension. Since we now add a
requires flag to repos that are created with hgsql, this no longer works.

Let's add a config option that can disable hgsql instead and update the tests to
use it. I'm not sure how these test failures slipped through the original
commit.

Test Plan: Ran the tests

Reviewers: #mercurial, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar

Differential Revision: https://phabricator.intern.facebook.com/D3289119

Signature: t1:3289119:1462999047:f33337610a1777c379adb70ec307971823f7ae59
2016-05-11 13:54:24 -07:00
Durham Goode
95858fbd8a bookmarks: stop wrapping bookmarks.write
Summary:
Upstream mercurial has deleted bookmarks.write() since all bookmark writes
happen via transactions now. So we can delete our write wrapper for that. We
already wrap transaction closes, so nothing new needs to be added.

Test Plan: Ran the tests

Reviewers: #mercurial, ttung, rmcelroy

Reviewed By: rmcelroy

Differential Revision: https://phabricator.intern.facebook.com/D3289117

Signature: t1:3289117:1463000038:aaf3454059514d92a017bd579b6de0691b334795
2016-05-11 13:54:21 -07:00
Durham Goode
c58a61d5cd init: add hgsql requirement during repo init and clone
Summary:
We don't want to allow commands to run in the repo if hgsql is not
enabled, so let's add a requirement.

This will not affect existing repositories, since they don't have the flag in
their requires, but the flag can be added manually once this is deployed.

Test Plan: Added a test

Reviewers: #sourcecontrol, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar

Differential Revision: https://phabricator.intern.facebook.com/D3239263

Signature: t1:3239263:1461923217:b8fb59498292e1f9d317d98d5de7ce8513685ba6
2016-04-29 09:55:23 -07:00
Durham Goode
031d404a34 profiling: add the ability to profile the sqllock time
Summary:
This adds a config option that can be enabled to profile what is
happening when the sqlock is taken (since that is the time spent that limits how
fast we can accept commits). It writes the profile out to an external file for
reading.

Test Plan:
Added a test. Also manually copied this to an hg server and did a
push.

Reviewers: #sourcecontrol, ttung, simonfar

Reviewed By: simonfar

Subscribers: simonfar

Differential Revision: https://phabricator.intern.facebook.com/D3239204

Signature: t1:3239204:1461922938:45298ada2955df8e5e145805f137ccc1974becea
2016-04-29 09:53:17 -07:00
Durham Goode
83c63cedf7 Fix corruption when syncing initial data for generaldelta repos
Summary:
This fixes a bug where the initial sync of a generaldelta repo could
cause the changelog.i to have a bad header byte that indicated the revlog was
generaldelta when it really wasn't. This fixes by applying the changelog
hardcoded value to the lightweight hgsql revlog class.

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

Reviewers: #sourcecontrol, ttung, quark

Reviewed By: quark

Subscribers: quark

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

Signature: t1:3194429:1461030817:6cc836e2dcd8b1feeeec16ee46548eac443695bf
2016-04-18 22:07:07 -07:00
Kostia Balytskyi
00ae3a7007 hgsql: add keyword-argument-based logging 2016-04-01 03:11:34 -07:00
Mateusz Kwapich
9916b26ecb tests: update output changed
Summary: we no longer print "activating" if the bookmark is already active

Test Plan: all tests are passing

Reviewers: #sourcecontrol, ttung

Reviewed By: ttung

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

Signature: t1:3117128:1459372145:64b3a523d290fa18d7146d48adaa953f698d9d02
2016-03-30 14:11:07 -07:00
Mateusz Kwapich
3c8b3811cc tests: pushrebase requires bundle2hooks now
Summary: For fixing tests

Test Plan: this is fixing some tests

Reviewers: #sourcecontrol, ttung

Reviewed By: ttung

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

Signature: t1:3117108:1459372132:0daf2049cd66a192e96a551661fcea2a81fb55a8
2016-03-30 14:10:57 -07:00
Mateusz Kwapich
173231304d hgsql: norepo is a parameter now
Test Plan: this is fixing some tests

Reviewers: #sourcecontrol, quark, ttung

Reviewed By: quark

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

Signature: t1:3117092:1459371915:231c133209a06f3e0e207482858775802d5820e7
2016-03-30 14:10:48 -07:00
Durham Goode
3aba9cef0c Force bookmark-then-changelog load order
Summary:
We've been seeing bugs where pulls result in bookmarks missing for clients. We
suspect it to be a race condition on the server side. One possible race is that
we load the changelog data before the bookmarks, and therefore may receive
bookmarks that point to a node that isn't in memory.

A simple fix to decrease the chances of this is to force loading bookmarks
first. Since hgsql is the first bit of code that access the repo, we can just
change the order here to ensure bookmarks are loaded first.

Test Plan:
It's not really a correctness change, so I wasn't able to test it.
What I did do however was insert exceptions into the bookmark loading and
changelog loading logic on one of our servers. This showed me that the changelog
was indeed being loaded first before because of this code.

Reviewers: #sourcecontrol, ttung

Reviewed By: ttung

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

Signature: t1:3063659:1458244130:7448377065fa0f0f6d98e43eaa00bdfc380948b6
2016-03-18 17:02:48 -07:00
Ryan McElroy
94e27b2010 ignore: add .testtimes to hgignore 2016-03-07 02:54:17 -08:00
Ryan McElroy
60d590a50b check for getdb.sh in tests
Test Plan: run tests without getdb.sh

Reviewers: #sourcecontrol, ttung, durham

Reviewed By: durham

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

Signature: t1:3006362:1457030481:7dc0af51e84c6d7007b74e052e804b8fd0be6062
2016-03-07 02:52:23 -08:00
Durham Goode
b9082ab1ff Update tests with new hook output
Upstream added some help output about the --traceback flag when hooks exit
oddly. We need to account for it in the tests.
2016-02-17 14:46:00 -08:00
Mateusz Kwapich
bd3030045b hgsql: move repo._afterlock callbacks execution after the sqllock release
Summary:
We are overriding the _afterlock to mind one more lock before executing
callbacks. We need that so our post commit hooks are executed out of the lock.

Test Plan: run tests

Reviewers: #sourcecontrol, ttung, durham

Reviewed By: durham

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

Signature: t1:2809038:1452124328:3b1d2da7711cdf1c97fe06d5dcf07be253582fcd
2016-01-06 16:37:46 -08:00
Mateusz Kwapich
45bc7261ee hgsql: lint nits
Summary: Just unused imports and variables - nothing serius.

Test Plan: Ran tests.

Reviewers: #sourcecontrol, ttung, durham

Reviewed By: durham

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

Signature: t1:2808903:1452120578:705abfbcd653eecd150d41c443edc855ef334ea3
2016-01-06 15:01:10 -08:00
Durham Goode
9bf82a7d92 bookmarks: remove use of bookmark.write()
Summary:
Upstream has moved almost all bookmark writes to use bookmark.recordchange()
instead of write, which works inside a transaction. For hgsql, we need to
perform our bookmark writes inside a transaction now.

Additionally, we need to check self.disablesync inside committodb.  disablesync
is used to allow us to write bookmarks during a syncdb without triggering the
bookmark writes to the db (since that would be a infinite loop). Previously we
only needed the syncdb check for bookmark writes, but since that has moved to
transactions, we need to do the check there too (committodb fires on
pretxnclose).

Lastly, in theory we could remove our wrapping of bookmark.write now, since
nothing should use it. But since upstream still has code for bookmark.write to
write bookmarks when outside a transaction, we can't remove our code just yet,
in case some extension still uses bookmark.write.

Test Plan: Ran the tests

Reviewers: ttung, lcharignon, #sourcecontrol, mitrandir

Reviewed By: mitrandir

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

Signature: t1:2808601:1452116992:ed34107a97ac633281ad8934266b35e3375cb247
2016-01-06 14:52:23 -08:00
Durham Goode
2ef0e253f8 Add rate limiting to read-only database syncs
Summary:
We've seen load issues on the mysql server in certain situations. This is caused
by large revision_reference query load from every read connection checking the
database.

To fix it, let's use Mercurial locks to enforce that only one reader is checking
and syncing at any given time.  All other will just serve the existing on disk
data immediately.

Writer clients are unaffected. They do not obey the rate limiting lock and do
exactly what they did before.

Test Plan: I'll try to add a test

Reviewers: #sourcecontrol, ttung

Differential Revision: https://phabricator.fb.com/D2756217
2015-12-14 12:34:06 -08:00
Durham Goode
b781a58782 Update test with change from generaldelta
Since upstream Mercurial now defaults to generaldelta, this affects the tests.
In this particular test, the offset value (which contains the revlog type if
it's rev 0, like in this case), is different because it now contains the
generaldelta bit.
2015-12-07 12:56:03 -08:00
Eric Sumner
d5471d331d test change for generaldelta 2015-12-03 12:58:17 -08:00
Eric Sumner
17b4d7c7bd fix test changes 2015-12-02 13:59:20 -08:00
Durham Goode
5b67cb9e47 Reduce test flakiness
Summary:
test-sync tested a race condition by introducing a sleep in a hook inside the
lock. It was flakey though. This extends the lock hook to 2 seconds and makes
the second command wait 1 second before beginning, so we can ensure the first
command is in the lock before the second one starts.

Test Plan:
Ran the tests a lot, saw no failures. Previously I would see them
relatively frequently.

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.fb.com/D2665352
2015-11-17 13:29:21 -08:00
Durham Goode
ab07fcd0a7 Add support for running on top of bundle repos
Summary:
hgsql failed when run against bundle repos before. We've fixed it so that no
sync is performed when reading from a bundle repo, but writes will be rejected.

Test Plan: Added a test and ran the tests

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.fb.com/D2665347
2015-11-17 13:28:56 -08:00
Durham Goode
883b577953 Switch to mysql.connector
Summary:
The old MySQLdb library did not support IPv6 so we've switched to using
mysql.connector, which is more recent and does support IPv6.

The most notable change in functionality is that it returns byte arrays instead
of strings, so I had to add a custom type converter that returns strings.

Test Plan: Ran the tests (after installing the new rpm)

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.fb.com/D2665344
2015-11-17 13:34:00 -08:00
Durham Goode
0d62bc2a7a Refactor issqlrepo check into a function
Summary:
We're going to be refactoring which functions actually sync with sql soon, and
putting this logic in a function will help us stay clean.

Test Plan: Ran the tests

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.fb.com/D2665341
2015-11-17 13:28:15 -08:00
Durham Goode
fae660bb46 One more spot with a+ opener 2015-11-05 12:57:17 -08:00
Durham Goode
6b151bffeb Open data files with read and write mode
Upstream Mercurial now reuses file handles for reads, so we need to open the dfh
handle with a+ so it can be read from.
2015-11-03 13:13:39 -08:00
Durham Goode
c21db7cde6 Fix wlock/lock wrapping order issues
These were caught by the devel warnings in the tests
2015-10-26 15:48:14 -07:00
Durham Goode
2d8cf7b54e Update wrapping to work with Mercurial 3.6 2015-10-26 15:47:53 -07:00