Commit Graph

51 Commits

Author SHA1 Message Date
Michael Samoylenko
e156bbd676 Allow more read-connection-types when creating SqlConnections
Summary:
I want to use `ReplicaFirst` read connection type since `ReplicaOnly` is a bit too restrictive.

We've had 2 MySQL SEVs this year when all the replicas went down crashing our services despite the primary instance working normally.
There was also a case when I've deleted too much rows at once and all replicas went down due to replication lag (I know better now)

RFC
- Yay or Nay?
- Should I expand `ReadConnectionType` to mirror all options of `InstanceRequirement`?
- Perhaps it's worth moving it into the `common/rust/shed/sql` crate?

I kept cleaning up all the usages out of this diff to keep the changes minimal for RFC

Differential Revision: D30574326

fbshipit-source-id: 1462b238305d47557372afe7763096c53df55f10
2021-09-06 14:40:47 -07:00
Alex Hornby
3f8c9ed354 mononoke: add cli arguments for manifold_request_priority
Summary: This diff adds a CLI option to be able to override the manifold request priority for a particular job or command line run.

Reviewed By: HarveyHunt

Differential Revision: D30277209

fbshipit-source-id: 58217c11234133dfc68e11b230d99066dd783600
2021-08-12 08:49:36 -07:00
Mark Juggurnauth-Thomas
3c9bf458be metaconfig: add ephemeral blobstore config
Summary:
Extend metaconfig to include configuration for the ephemeral blobstore.

An ephemeral blobstore is optional: repos without an ephemeral blobstore cannot
store ephemeral commits or snapshots.

Reviewed By: StanislavGlebik

Differential Revision: D29067719

fbshipit-source-id: fe7d42173d5c34a937c99c72f4b2bd08af503889
2021-06-24 04:13:58 -07:00
Mark Juggurnauth-Thomas
fb646e5edc blobstore: enumeration ranges are inclusive
Summary:
Manifold enumeration ranges are inclusive.  Update documentation of options that
ultimately feed into this as such.

To avoid future confusion, use Rust's inclusive ranges to initialize these, and
remove the exclusive range option.

The fileblob implementation was actually performing exclusive checks at both
ends, rather than inclusive ones.  Correct this by implementing `RangeBounds`
and using `range.contains` instead.

Reviewed By: liubov-dmitrieva

Differential Revision: D28224481

fbshipit-source-id: 7244588271d7754d6c6820790cbd76574b296d7b
2021-06-15 08:29:31 -07:00
Alex Hornby
ce923a0f33 mononoke: simplify manifoldblob construction
Summary: The new and new_with_ttl constructors were causing duplication.  Combine them.

Reviewed By: farnz

Differential Revision: D28471162

fbshipit-source-id: c7095a9a337d0ccbf5cd15ac3650cd5b361aaebf
2021-05-17 04:00:58 -07:00
Alex Hornby
74f5e21506 mononoke: add a cmdlib option for manifold weak consistency
Reviewed By: farnz

Differential Revision: D28217480

fbshipit-source-id: c520650cbf0a34bc042e711ddb7e09063e0eea47
2021-05-05 05:51:03 -07:00
Thomas Orozco
0f44a4f106 mononoke: update to tokio 1.x
Summary:
NOTE: there is one final pre-requisite here, which is that we should default all Mononoke binaries to `--use-mysql-client` because the other SQL client implementations will break once this lands. That said, this is probably the right time to start reviewing.

There's a lot going on here, but Tokio updates being what they are, it has to happen as just one diff (though I did try to minimize churn by modernizing a bunch of stuff in earlier diffs).

Here's a detailed list of what is going on:

- I had to add a number `cargo_toml_dir` for binaries in `eden/mononoke/TARGETS`, because we have to use 2 versions of Bytes concurrently at this time, and the two cannot co-exist in the same Cargo workspace.
- Lots of little Tokio changes:
  - Stream abstractions moving to `tokio-stream`
  - `tokio::time::delay_for` became `tokio::time::sleep`
  - `tokio::sync::Sender::send` became `tokio::sync::Sender::broadcast`
  - `tokio::sync::Semaphore::acquire` returns a `Result` now.
  - `tokio::runtime::Runtime::block_on` no longer takes a `&mut self` (just a `&self`).
  - `Notify` grew a few more methods with different semantics. We only use this in tests, I used what seemed logical given the use case.
- Runtime builders have changed quite a bit:
  - My `no_coop` patch is gone in Tokio 1.x, but it has a new `tokio::task::unconstrained` wrapper (also from me), which I included on  `MononokeApi::new`.
  - Tokio now detects your logical CPUs, not physical CPUs, so we no longer need to use `num_cpus::get()` to figure it out.
- Tokio 1.x now uses Bytes 1.x:
  - At the edges (i.e. streams returned to Hyper or emitted by RepoClient), we need to return Bytes 1.x. However, internally we still use Bytes 0.5 in some places (notably: Filestore).
  - In LFS, this means we make a copy. We used to do that a while ago anyway (in the other direction) and it was never a meaningful CPU cost, so I think this is fine.
  - In Mononoke Server it doesn't really matter because that still generates ... Bytes 0.1 anyway so there was a copy before from 0.1 to 0.5 and it's from 0.1 to 1.x.
  - In the very few places where we read stuff using Tokio from the outside world (historical import tools for LFS), we copy.
- tokio-tls changed a lot, they removed all the convenience methods around connecting. This resulted in updates to:
  - How we listen in Mononoke Server & LFS
  - How we connect in hgcli.
  - Note: all this stuff has test coverage.
- The child process API changed a little bit. We used to have a ChildWrapper around the hg sync job to make a Tokio 0.2.x child look more like a Tokio 1.x Child, so now we can just remove this.
- Hyper changed their Websocket upgrade mechanism (you now need the whole `Request` to upgrade, whereas before that you needed just the `Body`, so I changed up our code a little bit in Mononoke's HTTP acceptor to defer splitting up the `Request` into parts until after we know whether we plan to upgrade it.
- I removed the MySQL tests that didn't use mysql client, because we're leaving that behind and don't intend to support it on Tokio 1.x.

Reviewed By: mitrandir77

Differential Revision: D26669620

fbshipit-source-id: acb6aff92e7f70a7a43f32cf758f252f330e60c9
2021-04-28 07:36:31 -07:00
Aida Getoeva
bb3d207e33 mononoke: remove myrouter from Mononoke
Summary:
MyRouter is no longer used by Mononoke services, it is deprecated and will stop working when we upgrade the tokio.

This diff removes MyRouter support from Mononoke and simplifies the Mysql connection type struct.
Before we had `MysqlOptions` and `MysqlConnectionType` enum to represent what kind of a client we want to use. Now we use only MySQL FFI so I removed `MysqlConnectionType` completely and put everything into the options struct.

As setting up the connections (aka conn pool) is not an async operation, some of the methods don't need to be async anymore. Because this diff is already enormous, I'm refactoring this in the next one.

Reviewed By: StanislavGlebik

Differential Revision: D28007850

fbshipit-source-id: 32c3740f4bb132f06e1e256b0530ace755446cdd
2021-04-28 03:43:48 -07:00
Aida Getoeva
88fefc8736 mononoke: make MySQL FFI default client and remove raw XDB
Summary:
This diff makes MySQL FFI client the default option for a MySQL connection. It means that if no arguments provided, the MySQL FFI client is used. `--use-mysql-client` option is still accepted, as it is used in the configs, and will be removed a bit later.

I also removed raw connections as a way to connect to MySQL from Mononoke, as it is no longer used. Although I had to keep some `sql_ext` API for now because other projects rely on it.
(I talked to the teams and they are willing to switch to the new client as well. I'm helping where it's possible to replace these raw xdb conns.)

Reviewed By: krallin

Differential Revision: D27925435

fbshipit-source-id: 4f08eef07df676a4e6be58b6e351be3e3d3e8ab7
2021-04-22 10:00:13 -07:00
Thomas Orozco
db4c509b9e mononoke: use MononokeEnvironment in RepoFactory
Summary:
There is a very frustrating operation that happens often when working on the
Mononoke code base:

- You want to add a flag
- You want to consume it in the repo somewhere

Unfortunately, when we need to do this, we end up having to thread this from a
million places and parse it out in every single main() we have.

This is a mess, and it results in every single Mononoke binary starting with
heaps of useless boilerplate:

```
    let matches = app.get_matches();

    let (caching, logger, mut runtime) = matches.init_mononoke(fb)?;

    let config_store = args::init_config_store(fb, &logger, &matches)?;

    let mysql_options = args::parse_mysql_options(&matches);
    let blobstore_options = args::parse_blobstore_options(&matches)?;
    let readonly_storage = args::parse_readonly_storage(&matches);
```

So, this diff updates us to just use MononokeEnvironment directly in
RepoFactory, which means none of that has to happen: we can now add a flag,
parse it into MononokeEnvironment, and get going.

While we're at it, we can also remove blobstore options and all that jazz from
MononokeApiEnvironment since now it's there in the underlying RepoFactory.

Reviewed By: HarveyHunt

Differential Revision: D27767700

fbshipit-source-id: e1e359bf403b4d3d7b36e5f670aa1a7dd4f1d209
2021-04-16 10:27:43 -07:00
Thomas Orozco
c2c904f933 mononoke: initialize loggers, config, caching, tunables & runtime in MononokeMatches
Summary:
Basically every single Mononoke binary starts with the same preamble:

- Init mononoke
- Init caching
- Init logging
- Init tunables

Some of them forget to do it, some don't, etc. This is a mess.

To make things messier, our initialization consists of a bunch of lazy statics
interacting with each other (init logging & init configerator are kinda
intertwined due to the fact that configerator wants a logger but dynamic
observability wants a logger), and methods you must only call once.

This diff attempts to clean this up by moving all this initialization into the
construction of MononokeMatches. I didn't change all the accessor methods
(though I did update those that would otherwise return things instantiated at
startup).

I'm planning to do a bit more on top of this, as my actual goal here is to make
it easier to thread arguments from MononokeMatches to RepoFactory, and to do so
I'd like to just pass my MononokeEnvironment as an input to RepoFactory.

Reviewed By: HarveyHunt

Differential Revision: D27767698

fbshipit-source-id: 00d66b07b8c69f072b92d3d3919393300dd7a392
2021-04-16 10:27:43 -07:00
Simon Farnsworth
f8247dbc53 Remove Thrift Manifold client
Summary: It's no longer in use, so remove it completely to simplify the code

Reviewed By: ahornby

Differential Revision: D27234699

fbshipit-source-id: ec26f4e283d48b05e19b951b8485ca6fa7751072
2021-03-23 03:08:22 -07:00
Thomas Orozco
097e4ad00c mononoke: remove tokio-compat (i.e. use tokio 0.2 exclusively)
Summary:
The earlier diffs in this stack have removed all our dependencies on the Tokio
0.1 runtime environment (so, basically, `tokio-executor` and `tokio-timer`), so
we don't need this anymore.

We do still have some deps on `tokio-io`, but this is just traits + helpers,
so this doesn't actually prevent us from removing the 0.1 runtime!

Note that we still have a few transitive dependencies on Tokio 0.1:

- async-unit uses tokio-compat
- hg depends on tokio-compat too, and we depend on it in tests

This isn't the end of the world though, we can live with that :)

Reviewed By: ahornby

Differential Revision: D26544410

fbshipit-source-id: 24789be2402c3f48220dcaad110e8246ef02ecd8
2021-02-22 09:22:42 -08:00
Simon Farnsworth
1641740028 Use a wrapper around the Thrift Manifold client
Summary: In preparation for adding C++ client alternatives, use a wrapper around the Thrift client. This currently just calls the Thrift client directly, but will grow the ability to call the C++ client, too. For now, there's a dummy parameter to control the use of the C++ client.

Reviewed By: ahornby

Differential Revision: D26513598

fbshipit-source-id: b26cd9a9d89ab0502510b8533df4a60f5ca65292
2021-02-19 12:40:15 -08:00
Simon Farnsworth
7747032bdf Move Thrift Manifold client blobstore into its own modules
Summary:
I'm going to start shifting from Thrift to C++ client - to make reuse easier, put the Thrift client in its own module, with the Thrift-specific tests, and put shared tests in a shared module.

While in here, rename the blobstore to ManifoldBlobstore, so that it's clear that it's not just a Thrift blobstore, ready for it being a mix of C++ and Thrift.

Reviewed By: ahornby

Differential Revision: D26513599

fbshipit-source-id: 9e111583f1700eea18e83032b9ca1b9c8babc83e
2021-02-19 10:50:16 -08:00
Ilia Medianikov
bb9a4e5e8c Record blob size to blobstore healer queue
Summary:
Schema for `xdb.mononoke_blobstore_sync_queue : blobstore_sync_queue` wasn't altered yet as AOSC [wasn't working](https://fb.workplace.com/groups/mysql.users/permalink/4991036464278262/).

This will allow the blobstore healer to make decisions about how many blobs it should copy at once. The goal is to eliminate the OOMs that were regularly seen by giving the blobstore healer a memory budget.

Reviewed By: krallin

Differential Revision: D25925522

fbshipit-source-id: d3714dbadc74274a4c4a0e66fa732b84bef89227
2021-01-22 08:34:16 -08:00
Alex Hornby
2d0b7db627 mononoke: allow cmdlib init_logging to return a Result
Summary: Allow us to return arg parsing errors rather than panicing

Reviewed By: krallin

Differential Revision: D25837626

fbshipit-source-id: 87e39de140b1dcd3b13a529602fdafc31233175d
2021-01-14 09:52:40 -08:00
Aida Getoeva
8b93f52b71 mononoke/mysql: use single static shared connection pool
Summary:
The correct workflow for using a multi-threaded connection pool for multiple DBs is to have a single shared pool for all the use-cases. The pool is smart enough to maintain separate "pools" for each DB locator and limit them to maximum 100 conn per key.

In this diff I create a `OnceCell` connection pool that is initialized once and reused for every attempt to connect to the DB.
The pool is stored in `MononokeAppData` in order to bind its lifetime to the lifetime of Mononoke app. Then it is passed down as a part of `MysqlOptions`.  Unfortunately this makes `MysqlOptions` not copyable, so the diff also contains lots of "clones".

Reviewed By: ahornby

Differential Revision: D25055819

fbshipit-source-id: 21f7d4a89e657fc9f91bf22c56c6a7172fb76ee8
2020-12-17 15:46:30 -08:00
Alex Hornby
a2247dc41c mononoke: rename MononokeApp to MononokeAppBuilder
Summary:
It has a build() method and later in stack it will build a mononoke
specific type rather than the clap::App

Differential Revision: D25216827

fbshipit-source-id: 24a531856405a702e7fecf54d60be1ea3d2aa6e7
2020-12-01 11:45:00 -08:00
Lukas Piatkowski
fa1a195fd0 mononoke/blobstore: pass CoreContext via borrowed instead of owned value
Summary: Follow up after removing 'static from blobstore.

Reviewed By: StanislavGlebik

Differential Revision: D25182106

fbshipit-source-id: e13a7a31d71b4674425123268e655ae66127f1b7
2020-11-27 03:31:07 -08:00
Lukas Piatkowski
0f54cc3d63 mononoke/blobstore: make Blobstore generic over lifetime
Summary: Remove 'static requirement for async methods of Blobstore, propagate this change and fixup low hanging fruits where the code can become 'static free easily.

Reviewed By: ahornby, farnz

Differential Revision: D24839054

fbshipit-source-id: 5d5daa04c23c4c9ae902b669b0a71fe41ee6dee6
2020-11-20 05:51:52 -08:00
Alex Hornby
14128ce2dc mononoke: remove unnecessary .version("0.0.0") in clap App setup
Summary: We don't need to declare a fake empty version number

Reviewed By: farnz

Differential Revision: D24757981

fbshipit-source-id: 594c97e225704d783bea723efcbb9dfc4d5d800b
2020-11-06 02:23:46 -08:00
Simon Farnsworth
7e06175e61 Make config store always explicit
Summary: In D24447404, I provided some utility functions that allowed me to avoid constructing and/or passing around a ConfigStore. Remove those functions and fix up the code to run.

Reviewed By: krallin

Differential Revision: D24502692

fbshipit-source-id: 742dbc54fbcf735895d6829745b9317af14dfa0b
2020-10-24 06:23:49 -07:00
Simon Farnsworth
00871310a7 Ensure we have only one ConfigStore for the application
Summary: It's designed as a singleton store for normal use - rather than have lots of ways to get different config stores, let's use one global store

Reviewed By: krallin

Differential Revision: D24447404

fbshipit-source-id: 6ecc46351b14794471f654cec98527a11a93d3ef
2020-10-24 06:23:49 -07:00
Thomas Orozco
63158883e3 mononoke/manifoldblob: log retries, delay and conflicts to perf counters
Summary:
This updates ManifoldBlob to log the aformentioned data points to perf
counters. There's a bit of refactoring that also had to go into this to make
`ctx` available everywhere it's needed.

Reviewed By: aslpavel

Differential Revision: D24333040

fbshipit-source-id: 1b63bcd1e1ee36bae4dbbc1da053c7f1bdf96675
2020-10-16 08:57:13 -07:00
Alex Hornby
48900ae545 mononoke: predicate based PutBehaviour logic to manifoldblob
Summary:
Add predicate based PutBehaviour logic to manifoldblob.

This will prevent overwrites of keys when in IfAbsent mode, and will generate useful logging in OverwriteAndLog and IsAbsent mode.

This change factors our part of the put logic to put_check_conflict, so that it can use re-used from each of the PutBehaviour cases.

Reviewed By: StanislavGlebik

Differential Revision: D24021170

fbshipit-source-id: d2e71afadada3d5e661634449108e6c9f8dc5907
2020-10-12 07:12:10 -07:00
Alex Hornby
9c9401f691 mononoke: add put behaviour handling to fileblob
Summary: Add put behaviour handling to fileblob so that it can prevent overwrites if requested.

Differential Revision: D23933228

fbshipit-source-id: 8e74ac96b232be841174f6ad2bd2fccf92aaa90d
2020-10-07 12:11:10 -07:00
Aida Getoeva
40b8353d21 mononoke: integrate mysql client
Summary:
This diff introduces Mysql client for Rust to Mononoke as a one more backend in the same row with raw xdb connections and myrouter. So now Mononoke can use new Mysql client connections instead of Myrouter.

To run Mononoke with the new backend, pass `--use-mysql-client` options (conflicts with `--myrouter-port`).

I also added a new target for integration tests, which runs mysql tests using mysql client.
Now to run mysql tests using raw xdb connections, you can use `mononoke/tests/integration:integration-mysql-raw-xdb` and using mysql client `mononoke/tests/integration:integration-mysql`

Reviewed By: ahornby

Differential Revision: D23213228

fbshipit-source-id: c124ccb15747edb17ed94cdad2c6f7703d3bf1a2
2020-09-29 03:09:05 -07:00
David Tolnay
be0786f14b Prepare for rustfmt 2.0
Summary:
Generated by formatting with rustfmt 2.0.0-rc.2 and then a second time with fbsource's current rustfmt (1.4.14).

This results in formatting for which rustfmt 1.4 is idempotent but is closer to the style of rustfmt 2.0, reducing the amount of code that will need to change atomically in that upgrade.

 ---

*Why now?* **:** The 1.x branch is no longer being developed and fixes like https://github.com/rust-lang/rustfmt/issues/4159 (which we need in fbcode) only land to the 2.0 branch.

 ---

Reviewed By: StanislavGlebik

Differential Revision: D23568780

fbshipit-source-id: b4b4a0aa683d236e2fdeb5b96d723ac2d84b9faf
2020-09-08 07:33:16 -07:00
Simon Farnsworth
0c3fe9b20f Fully asyncify blobstore sync queue
Summary: Move it from `'static` BoxFutures to async_trait and lifetimes

Reviewed By: markbt

Differential Revision: D22927171

fbshipit-source-id: 637a983fa6fa91d4cd1e73d822340cb08647c57d
2020-08-05 15:41:15 -07:00
Santiago Alfonso Muñoz Rodriguez
007dc93916 Enumeration API for BlobStore keys
Summary:
- Enumerate API now provided via trait BlobstoreKeySource
- Implementation for Fileblob and ManifoldBlob
- Modified populate_healer to use new api
- Modified fixrepocontents to use new api

Reviewed By: ahornby

Differential Revision: D22763274

fbshipit-source-id: 8ee4503912bf40d4ac525114289a75d409ef3790
2020-08-04 06:54:18 -07:00
Simon Farnsworth
a9b8793d2d Add a write-mostly blobstore mode for populating blobstores
Summary:
We're going to add an SQL blobstore to our existing multiplex, which won't have all the blobs initially.

In order to populate it safely, we want to have normal operations filling it with the latest data, and then backfill from Manifold; once we're confident all the data is in here, we can switch to normal mode, and never have an excessive number of reads of blobs that we know aren't in the new blobstore.

Reviewed By: krallin

Differential Revision: D22820501

fbshipit-source-id: 5f1c78ad94136b97ae3ac273a83792ab9ac591a9
2020-08-03 04:36:19 -07:00
Santiago Alfonso Muñoz Rodriguez
c32b31984f Resolve cmd line argument conflict on populate_healer
Summary: populate_healer would panic on launch because there were 2 aguments assigned to -d: debug and destination-blobstore-id

Reviewed By: StanislavGlebik

Differential Revision: D22843091

fbshipit-source-id: e300af85b4e9d4f757b4311f2b7d776f59c7527d
2020-07-31 00:17:43 -07:00
Simon Farnsworth
78847ff88c Make BlobstoreSyncQueue use new futures
Summary: Stage 1 of a migration - next step is to make all users of this trait use new futures, and then I can come back, add lifetimes and references, and leave it modernised

Reviewed By: StanislavGlebik

Differential Revision: D22460164

fbshipit-source-id: 94591183912c0b006b7bcd7388a3d7c296e60577
2020-07-10 06:43:13 -07:00
Simon Farnsworth
b1c85aaf4b Switch Blobstore to new-style futures
Summary:
Eventually, we want everything to be `async`/`await`; as a stepping stone in that direction, switch the remaining lobstore traits to new-style futures.

This just pushes the `.compat()` out to old-style futures, but it makes the move to non-'static lifetimes easier, as all the compile errors will relate to lifetime issues.

Reviewed By: krallin

Differential Revision: D22183228

fbshipit-source-id: 3fe3977f4469626f55cbf5636d17fff905039827
2020-06-26 03:54:42 -07:00
Mark Thomas
6ad7e5c96e metaconfig/parser: use free functions for loading configuration
Summary:
Replace the use of `RepoConfigs::read*` associated functions with free
functions.  These didn't really need to be associated functions (and in the
case of the common and storage configs, really didn't belong there either).

Reviewed By: krallin

Differential Revision: D21837270

fbshipit-source-id: 2dc73a880ed66e11ea484b88b749582ebdf8a73f
2020-06-02 09:30:03 -07:00
Thomas Orozco
6ac0c26e06 mononoke/context_concurrency_blobstore: use rate limit instead of semaphore
Summary:
Limits on concurrent calls are a bit hard to reason about, and it's not super
obvious what a good limit when all our underlying limits are expressed in QPS
(and when our data sets don't have peak concurrency - instead they have
completion time + # blob accesses).

Considering our past experience with ThrottledBlob has been quite positive
overall, I'd like to just use the same approach in ContextConcurrencyBlobstore.
To be safe, I've also updated this to be driven by tunables, which make it
easier to rollout and rollback.

Note that I removed `Debug` on `CoreContext` as part of this because it wasn't
used anywhere. We can bring back a meaningful implementation of `Debug` there
in the future if we want to. That triggered some warnings about unused fields,
which for now I just silenced.

Reviewed By: farnz

Differential Revision: D21449405

fbshipit-source-id: 5ca843694607888653a75067a4396b36e572f070
2020-05-12 06:49:25 -07:00
Mistral Orhan Jean-Pierre Contrastin
5fe820dd06 Expose ctime from Blobstore::get() in mononoke
Summary:
- Change get return value for `Blobstore` from `BlobstoreBytes` to `BlobstoreGetData` which include `ctime` metadata
- Update the call sites and tests broken due to this change
- Change `ScrubHandler::on_repair` to accept metadata and log ctime
- `Fileblob` and `Manifoldblob` attach the ctime metadata
- Tests for fileblob in `mononoke:blobstore-test` and integration test `test-walker-scrub-blobstore.t`
- Make cachelib based caching use `BlobstoreGetData`

Reviewed By: ahornby

Differential Revision: D21094023

fbshipit-source-id: dc597e888eac2098c0e50d06e80ee180b4f3e069
2020-05-06 00:55:07 -07:00
Mark Thomas
640f272598 migrate from sql_ext::SqlConstructors to sql_construct
Summary:
Migrate the configuration of sql data managers from the old configuration using `sql_ext::SqlConstructors` to the new configuration using `sql_construct::SqlConstruct`.

In the old configuration, sharded filenodes were included in the configuration of remote databases, even when that made no sense:
```
[storage.db.remote]
db_address = "main_database"
sharded_filenodes = { shard_map = "sharded_database", shard_num = 100 }

[storage.blobstore.multiplexed]
queue_db = { remote = {
    db_address = "queue_database",
    sharded_filenodes = { shard_map = "valid_config_but_meaningless", shard_num = 100 }
}
```

This change separates out:
* **DatabaseConfig**, which describes a single local or remote connection to a database, used in configuration like the queue database.
* **MetadataDatabaseConfig**, which describes the multiple databases used for repo metadata.

**MetadataDatabaseConfig** is either:
* **Local**, which is a local sqlite database, the same as for **DatabaseConfig**; or
* **Remote**, which contains:
    * `primary`, the database used for main metadata.
    * `filenodes`, the database used for filenodes, which may be sharded or unsharded.

More fields can be added to **RemoteMetadataDatabaseConfig** when we want to add new databases.

New configuration looks like:
```
[storage.metadata.remote]
primary = { db_address = "main_database" }
filenodes = { sharded = { shard_map = "sharded_database", shard_num = 100 } }

[storage.blobstore.multiplexed]
queue_db = { remote = { db_address = "queue_database" } }
```

The `sql_construct` crate facilitates this by providing the following traits:

* **SqlConstruct** defines the basic rules for construction, and allows construction based on a local sqlite database.
* **SqlShardedConstruct** defines the basic rules for construction based on sharded databases.
* **FbSqlConstruct** and **FbShardedSqlConstruct** allow construction based on unsharded and sharded remote databases on Facebook infra.
* **SqlConstructFromDatabaseConfig** allows construction based on the database defined in **DatabaseConfig**.
* **SqlConstructFromMetadataDatabaseConfig** allows construction based on the appropriate database defined in **MetadataDatabaseConfig**.
* **SqlShardableConstructFromMetadataDatabaseConfig** allows construction based on the appropriate shardable databases defined in **MetadataDatabaseConfig**.

Sql database managers should implement:

* **SqlConstruct** in order to define how to construct an unsharded instance from a single set of `SqlConnections`.
* **SqlShardedConstruct**, if they are shardable, in order to define how to construct a sharded instance.
* If the database is part of the repository metadata database config, either of:
    * **SqlConstructFromMetadataDatabaseConfig** if they are not shardable.  By default they will use the primary metadata database, but this can be overridden by implementing `remote_database_config`.
    * **SqlShardableConstructFromMetadataDatabaseConfig** if they are shardable.  They must implement `remote_database_config` to specify where to get the sharded or unsharded configuration from.

Reviewed By: StanislavGlebik

Differential Revision: D20734883

fbshipit-source-id: bb2f4cb3806edad2bbd54a47558a164e3190c5d1
2020-04-02 05:27:16 -07:00
Lukas Piatkowski
963f3cc724 mononoke: make blobstore/sqlblob buildable in OSS
Summary:
This shifts the responsibility of mocking all facebook-specific code
to mononoke's sql_ext crate. If OSS code calls into any of that code it will
most likely result in a panic.

Reviewed By: ahornby

Differential Revision: D20247580

fbshipit-source-id: 43f158d91aa32adaa5df6e3786243fb89c9ce961
2020-03-27 08:13:47 -07:00
Mateusz Kwapich
3d314761c3 introduce OperationKey
Summary:
From time to time we're experiencing the blobstore healer to crash
because its SQL queries timing out. The rootcause of the problem
is that the same blob_key may show up on the queue many times repeatedly
and the query is trying to select all occurences.

But, the original intention of blobstore healer is to act on a single
put operation across all blobstores. To be able to identify which
puts in the healer queue are part of the same operation we need
some unique id that we'll use per such operation, let's call it OperationKey.

corresponding configerator change to create db column: D20557659

NOTE: This diff has to be landed and rolled out first, before D20557700 is rolled out. I'm assuming that after some time since rolling out this diff all the rows in the production db will have proper `operation_key` value set.

Reviewed By: krallin

Differential Revision: D20557702

fbshipit-source-id: 404d9fdea6796b38193292d1bbd4b8cd4b5b3eb8
2020-03-24 10:07:31 -07:00
James Crooks
d2f5062182 Move fbcode/eden/mononoke/cmds/populate_healer.rs to async diff4
Summary:
Last diff. Fully migrates all of populate_healer.rs to async/await
futures.  This makes `put_resume_state()` async, with one `.compat()` call needed
for dealing with `manifold.put()`. Also changes `populate_healer_queue()` to
use the new async `put_resume_state()`. At this point, the only `.compat()`
calls remaining are for interop with ThrifManifoldBlob's interface, and can be
removed once ThriftManifoldBlob is updated or provides async replacement
functions. All explicit old-style future creation sites have been removed in
favor of 0.3 futures.

Reviewed By: krallin

Differential Revision: D20479264

fbshipit-source-id: baad535da3fc8b621d72de567454bcd64862977a
2020-03-19 09:16:25 -07:00
James Crooks
7ecd298e7b Move fbcode/eden/mononoke/cmds/populate_healer.rs to async diff3
Summary: Moves to using 0.3 futures inside of the populate_healer_queue() function. This leaves only one remaining source of `.compat()` calls inside of populate_healer.rs, which will be removed in the following diff.

Reviewed By: krallin

Differential Revision: D20473834

fbshipit-source-id: 6d76e0673b875fba15611a495d86b9ca0b1695db
2020-03-19 09:16:25 -07:00
James Crooks
20afa84689 Move fbcode/eden/mononoke/cmds/populate_healer.rs to async diff2
Summary:
Another small change moving toward using the new futures. This time we
make get_resume_state() async. This pushes the implicit .compat() we would otherwise have down to where we call ThriftManifoldBlob::get() which still returns an old-style BoxFuture.

Reviewed By: farnz

Differential Revision: D20444381

fbshipit-source-id: a5aab448c5b25e71e4ce5ea031302280d586066f
2020-03-16 09:23:46 -07:00
James Crooks
1b941f3d76 Move fbcode/eden/mononoke/cmds/populate_healer.rs main to async
Summary:
Pushes the `compat` call in main() down one level into
populate_healer_queue(). This ended up being straightforward, just a fn
signature change and a couple of callsite changes.

This only affects main(), going to follow-up with future diffs to push it down
a little farther.

Remaining line deltas are just due to rustfmt.

Reviewed By: farnz

Differential Revision: D20432676

fbshipit-source-id: 98100f1b651648d6e3509fa56e94b80ee075843f
2020-03-16 09:23:46 -07:00
Lukas Piatkowski
7ddcdd818c mononoke: make sql_ext OSS buildable
Summary: separate out the Facebook-specific pieces of the sql_ext crate

Reviewed By: ahornby

Differential Revision: D20218219

fbshipit-source-id: e933c7402b31fcd5c4af78d5e70adafd67e91ecd
2020-03-06 01:33:38 -08:00
David Tolnay
e988a88be9 rust: Rename futures_preview:: to futures::
Summary:
Context: https://fb.workplace.com/groups/rust.language/permalink/3338940432821215/

This codemod replaces *all* dependencies on `//common/rust/renamed:futures-preview` with `fbsource//third-party/rust:futures-preview` and their uses in Rust code from `futures_preview::` to `futures::`.

This does not introduce any collisions with `futures::` meaning 0.1 futures because D20168958 previously renamed all of those to `futures_old::` in crates that depend on *both* 0.1 and 0.3 futures.

Codemod performed by:

```
rg \
    --files-with-matches \
    --type-add buck:TARGETS \
    --type buck \
    --glob '!/experimental' \
    --regexp '(_|\b)rust(_|\b)' \
| sed 's,TARGETS$,:,' \
| xargs \
    -x \
    buck query "labels(srcs, rdeps(%Ss, //common/rust/renamed:futures-preview, 1))" \
| xargs sed -i 's,\bfutures_preview::,futures::,'

rg \
    --files-with-matches \
    --type-add buck:TARGETS \
    --type buck \
    --glob '!/experimental' \
    --regexp '(_|\b)rust(_|\b)' \
| xargs sed -i 's,//common/rust/renamed:futures-preview,fbsource//third-party/rust:futures-preview,'
```

Reviewed By: k21

Differential Revision: D20213432

fbshipit-source-id: 07ee643d350c5817cda1f43684d55084f8ac68a6
2020-03-03 11:01:20 -08:00
David Tolnay
fe65402e46 rust: Move futures-old rdeps to renamed futures-old
Summary:
In targets that depend on *both* 0.1 and 0.3 futures, this codemod renames the 0.1 dependency to be exposed as futures_old::. This is in preparation for flipping the 0.3 dependencies from futures_preview:: to plain futures::.

rs changes performed by:

```
rg \
    --files-with-matches \
    --type-add buck:TARGETS \
    --type buck \
    --glob '!/experimental' \
    --regexp '(_|\b)rust(_|\b)' \
| sed 's,TARGETS$,:,' \
| xargs \
    -x \
    buck query "labels(srcs,
        rdeps(%Ss, fbsource//third-party/rust:futures-old, 1)
        intersect
        rdeps(%Ss, //common/rust/renamed:futures-preview, 1)
    )" \
| xargs sed -i 's/\bfutures::/futures_old::/'
```

Reviewed By: jsgf

Differential Revision: D20168958

fbshipit-source-id: d2c099f9170c427e542975bc22fd96138a7725b0
2020-03-02 21:02:50 -08:00
Lukasz Piatkowski
542d1f93d3 Manual synchronization of fbcode/eden and facebookexperimental/eden
Summary:
This commit manually synchronizes the internal move of
fbcode/scm/mononoke under fbcode/eden/mononoke which couldn't be
performed by ShipIt automatically.

Reviewed By: StanislavGlebik

Differential Revision: D19722832

fbshipit-source-id: 52fbc8bc42a8940b39872dfb8b00ce9c0f6b0800
2020-02-11 11:42:43 +01:00
Harvey Hunt
78c44c5ec2 mononoke: Populate multiplex_id when writing blobs and update the healer to read them
Summary:
Modify the multiplexed blobstore implementation so that the
multiplex_id is written to the healer queue after a put. Further, update the
blobstore healer to only look at entries with the same multiplex ID as it's
configured to run with.

Reviewed By: ahornby

Differential Revision: D19770057

fbshipit-source-id: 41db19f0b0f84c048d49ab9e6258cccc89cf4195
2020-02-10 04:37:40 -08:00