Commit Graph

45 Commits

Author SHA1 Message Date
Stefan Filip
fc243be543 Ignore flaky test asynchronize_parallel from futures-ext
Summary:
This test was failing consistently on my devserver when I was testing an update to tp2 crates.io. The update did not have any future or tokio changes. This test also fails on other devservers.

This test was added in D9561367.

The test fails on my devserver with:
```
test test::asynchronize_parallel ... FAILED

failures:

---- test::asynchronize_parallel stdout ----
thread 'test::asynchronize_parallel' panicked at 'Parallel sleep time 43.284909ms much greater than
40ms for 20 threads - each thread sleeps for 20ms', common/rust/futures-ext/src/lib.rs:741:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

failures:
    test::asynchronize_parallel

```

Reviewed By: jsgf

Differential Revision: D14055989

fbshipit-source-id: 14a87a1dfe6ff7e273a08052695fd6c9c9ed37c7
2019-02-12 15:27:22 -08:00
Pedro Rittner
b00c3540bf rust: convert futures-ext to Rust 2018
Reviewed By: StanislavGlebik

Differential Revision: D13606742

fbshipit-source-id: 1ee7eac624b1217c3edb285727651a0a920ec14f
2019-02-12 08:43:24 -08:00
Stanislau Hlebik
4973890d63 mononoke: fix hgcli connection error in case of failures
Summary:
We've had this problem for almost a year now, and I've finally made some
progress.

The problem was in tests failing randomly with error like

```
-  remote: * pushrebase failed * (glob)
-  remote:     msg: "pushrebase failed Conflicts([PushrebaseConflict { left: MPath(\"1\"), right: MPath(\"1\") }])"
+  remote: Jan 25 08:46:24.067 ERRO Error in hgcli proxy, error: Connection reset by peer (os error 104), root_cause: Os {
+  remote:     code: 104,
+  remote:     kind: ConnectionReset,
+  remote:     message: "Connection reset by peer"
   remote: * backtrace* (glob)
```

or

```
   remote: * pushrebase failed * (glob)
   remote:     msg: "pushrebase failed Conflicts([PushrebaseConflict { left: MPath(\"1\"), right: MPath(\"1\") }])"
+  remote: Jan 25 08:47:59.966 ERRO Error in hgcli proxy, error: Connection reset by peer (os error 104), root_cause: Os {
+  remote:     code: 104,
+  remote:     kind: ConnectionReset,
+  remote:     message: "Connection reset by peer"
+  remote: }, backtrace:
```

note that the problem are slightly different. In the first case the actual error message is completely lost + we get unnecessary
ConnectionReset problem message. In the second case it's just `ConnectionReset`.

This diff fixes the problem of the lost error message (problem #1) and hides `ConnectionReset` problem (problem #2).

Problem #1 was due to a bug in streamfork. Before this diff if streamfork hit
an error, then it might have not sent already received input to one of the
outputs. This diff fixes it.

This diff just hides Problem #2. If we see a ConnectionReset then an error
won't be reported. That's a hack which should be fixed, but at the moment
a) The bug is not easily debuggable
b) The problem is not urgent and shouldn't cause problems

In some cases server actually sends Connection reset, but in that case
mercurial stil gives us self-explanatory message

```
abort: stream ended unexpectedly (got 0 bytes, expected 4
``

Reviewed By: lukaspiatkowski

Differential Revision: D13818558

fbshipit-source-id: 7a2cba8cd0fcef8211451df3dea558fe2d60fa60
2019-01-28 14:40:40 -08:00
Stanislau Hlebik
b909f2bc9c mononoke: per wireproto command timeout
Summary:
Previously we had a timeout per session i.e. multiple wireproto command will
share the same timeout. It had a few disadvantages:

1) The main disadvantage was that if connection had timed out we didn't log
stats such as number of files, response size etc and we didn't log parameters
to scribe. The latter is even a bigger problem, because we usually want to
replay requests that were slow and timed out and not the requests that finished
quickly.

2) The less important disadvantage is that we have clients that do small
request from the server and then keep the connection open for a long time.
Eventually we kill the connection and log it as an error. With this change
the connection will be open until client closes it. That might potentially be
a problem, and if that's the case then we can reintroduce perconnection
timeout.

Initially I was planning to use tokio::util::timer to implement all the
timeouts, but it has different behaviour for stream - it only allows to set
per-item timeout, while we want timeout for the whole stream.
(https://docs.rs/tokio/0.1/tokio/timer/struct.Timeout.html#futures-and-streams)
To overcome it I implemented simple combinator StreamWithTimeout which does
exactly what I want.

Reviewed By: HarveyHunt

Differential Revision: D13731966

fbshipit-source-id: 211240267c7568cedd18af08155d94bf9246ecc3
2019-01-18 08:35:52 -08:00
Stanislau Hlebik
cf3b9b55eb mononoke: rustfmt
Reviewed By: HarveyHunt

Differential Revision: D13731965

fbshipit-source-id: 670f633baebed1d508a55d57e46f3ae4cd42b7d2
2019-01-18 08:35:52 -08:00
Jeremy Fitzhardinge
65fd5bcf8f rust/futures-ext: implement StreamEither/left_stream/right_stream
Summary: Implement Either for Streams too.

Reviewed By: Imxset21

Differential Revision: D13494405

fbshipit-source-id: 8aea256b317f8d86e80eab3bfa200c59ebfdda35
2018-12-19 16:49:24 -08:00
Lukas Piatkowski
0f24377899 rust-crates-io: add crossbeam to tp2
Reviewed By: ikostia

Differential Revision: D10244968

fbshipit-source-id: 8d06bb64b6a1227ae589caf0588a1f3657603ce9
2018-10-08 21:36:00 -07:00
Simon Farnsworth
0ad8dcc0da Split asynchronize into useful components
Summary:
`asynchronize` does two conceptually separate things:

1. Given a closure that can do blocking I/O or is CPU heavy, create a future
that runs that closure inside a Tokio task.
2. Given a future, run it on a new Tokio task and shuffle the result back to
the caller via a channel.

Split these two things out into their own functions - one to make the future,
one to spawn it and recover the result. For now, this is no net change - but
`spawn_future` is likely to come in useful once we need more parallelism than
we get from I/O alone, and `closure_to_blocking_future` at least signals intent
when we allow a long-running function to take over a Tokio task.

Reviewed By: jsgf

Differential Revision: D9635812

fbshipit-source-id: e15aeeb305c8499219b89a542962cb7c4b740354
2018-09-05 12:23:49 -07:00
Simon Farnsworth
7fd5851f1e Use blocking in asynchronize as well as spawning a task
Summary:
`asynchronize` currently does not warn the event loop that it's
running blocking code, so we can end up starving the thread pool of threads.

We can't use `blocking` directly, because it won't spawn a synchronous task
onto a fresh Tokio task, so your "parallel" futures end up running in series.
Instead, use it inside `asynchronize` so that we can pick up extra threads in
the thread pool as and when we need them due to heavy load.

While in here, fix up `asynchronize` to only work on synchronous tasks and
push the boxing out one layer. Filenodes needs a specific change that's
worth extra eyes.

Reviewed By: jsgf

Differential Revision: D9631141

fbshipit-source-id: 06f79c4cb697288d3fadc96448a9173e38df425f
2018-09-05 12:23:49 -07:00
Simon Farnsworth
6eb6e4543d Add a test for asynchronize
Summary:
We have suspect timings in Mononoke where `asynchronize` is used to
turn a blocking function into a future. Add a test case to ensure that
`asynchronize` itself cannot be causing accidental serialization.

Reviewed By: jsgf

Differential Revision: D9561367

fbshipit-source-id: 14f03e3f003f258450bb897498001050dee0b40d
2018-09-05 12:23:49 -07:00
Arun Kulshreshtha
d9a491b1d8 Use tokio::timer::Timeout
Summary: The latest release of `tokio` updates `tokio::timer` to include a new `Timeout` type and a `.timeout()` method on `Future`s. As such, our internal implementation of `.timeout()` in `FutureExt` is no longer needed.

Reviewed By: jsgf

Differential Revision: D9617519

fbshipit-source-id: b84fd47a3ee4fc1f7c0a52e308317b93f28f04da
2018-08-31 15:37:30 -07:00
Jeremy Fitzhardinge
4021018efc tp2: rust: update rust-crates-io
Summary: Need new version of tokio.

Reviewed By: kulshrax

Differential Revision: D9598352

fbshipit-source-id: e2e217e6b7d18354cf9725cb59e9e32ed153a124
2018-08-30 17:37:32 -07:00
Stanislau Hlebik
2c8d98447d mononoke: revert D8959535
Summary:
It makes startup unbearably slow, and doesn't add any benefits at all. Revert
it

Reviewed By: purplefox

Differential Revision: D9358741

fbshipit-source-id: 26469941304f737c856a6ffca5e577848ad30955
2018-08-16 03:06:14 -07:00
Jeremy Fitzhardinge
e0ce53ce36 rust: change asynchronize to use tokio-threadpool::blocking
Summary:
Should be functionally equivalent and semantically more appropriate

This also makes a couple of small API changes:
- The inner function is expected to just return a Result - IntoFuture is
  overkill if its supposed to be synchronous in the first place
- `asynchronize` itself returns `impl Future` rather than being intrinsically
  boxed.
- Restructure dieselfilenodes::add_filenodes to only asynchronize the insert
  itself.

Reviewed By: farnz

Differential Revision: D8959535

fbshipit-source-id: fef9164e3be0069bd0d93573642cd57bb5babb73
2018-08-13 14:51:45 -07:00
Rain ⁣
3932654ea1 futures-ext: add is_empty and not_empty combinators to StreamExt
Summary: I was surprised these didn't exist, but they work fine.

Reviewed By: Imxset21

Differential Revision: D9016243

fbshipit-source-id: 8405009f536b2e1aa0c9c28be59bb8c1d9ab7a4f
2018-07-26 15:05:57 -07:00
Lukas Piatkowski
af3d993cd3 futures-ext: add ensure_boxfuture! macro similar to failure's ensure!
Summary: As in the comment to the macro: if the condition is not met, return a BoxFuture with Err inside

Reviewed By: farnz

Differential Revision: D8877731

fbshipit-source-id: 7f31a1739155201ea2be30901b8cda2511f49b03
2018-07-19 03:05:54 -07:00
Rain ⁣
2b2a7d0ed8 futures-ext: add a helper method to send and discard over an mpsc channel
Summary: quite straightforward.

Reviewed By: Imxset21

Differential Revision: D8888554

fbshipit-source-id: 43a5d86d72c1ffbfded453ca859549513e6cbd51
2018-07-18 11:22:30 -07:00
Lukas Piatkowski
f997b5c927 futures-ext: replace tokio_core with tokio::runtime
Reviewed By: farnz

Differential Revision: D8868165

fbshipit-source-id: c1017ccf57a726a218fd2100deb3d4cae9d375cd
2018-07-17 04:54:59 -07:00
Lukas Piatkowski
69d791a81f server: split server binary crate into 4 separate crates
Summary: Iterating over the code on server is a bit painful and it has grown a lot, splitting it should speed up future refactories and make it more maintainable

Reviewed By: jsgf, StanislavGlebik

Differential Revision: D8859811

fbshipit-source-id: 7c56f9f835f45eca322955cb3b9eadd87fbb30a1
2018-07-17 04:54:58 -07:00
Pulkit Goyal
fc880f518b Add Cargo.toml files to crates. (#7)
Summary:
This is a series of patches which adds Cargo.toml files to all the crates and tries to build them. There is individual patch for each crate which tells whether that crate build successfully right now using cargo or not, and if not, reason behind that.

Following are the reasons why the crates don't build:

  * failure_ext and netstring crates which are internal
  * error related to tokio_io, there might be an patched version of tokio_io internally
  * actix-web depends on httparse which uses nightly features

All the build is done using rustc version `rustc 1.27.0-dev`.
Pull Request resolved: https://github.com/facebookexperimental/mononoke/pull/7

Differential Revision: D8778746

Pulled By: jsgf

fbshipit-source-id: 927a7a20b1d5c9643869b26c0eab09e90048443e
2018-07-09 19:52:27 -07:00
Stanislau Hlebik
09df07af7e mononoke: add left_future() and right_future()
Summary:
Such methods exist in new futures library, but since we are not using it yet,
let's add these methods to our FutureExt

Reviewed By: jsgf

Differential Revision: D8644300

fbshipit-source-id: e35ff95ff0db3aa5f3e7fba1a77cb826b59873f4
2018-06-27 07:52:53 -07:00
Arun Kulshreshtha
a63b43b11d Add ability to set timeouts on Futures
Summary: This diff adds the methods `timeout()` and `on_timeout()` to the `FuturesExt` trait. The former sets a time limit for the execution of a `Future` -- effectively shorthand for `tokio_timer::Deadline`. The latter takes a callback (which may itself return a `Future`) which is called if the wrapped `Future` times out; this is useful for doing things like logging the state of the program to debug why things are timing out.

Reviewed By: StanislavGlebik

Differential Revision: D8508008

fbshipit-source-id: 6d085c35b68d1cf5a24446be8af77eb30028a7db
2018-06-19 18:21:56 -07:00
Stanislau Hlebik
604340d9ce mononoke: streaming gettreepack
Summary:
Unfortunately I have to remove tracing. The reason is because tracing doesn't
work with Streams. For now it should be fine because enabling tracing in prod
is still not possible because of the memory and cpu overhead.

Reviewed By: farnz

Differential Revision: D8381855

fbshipit-source-id: e28b4396c81527bdf30fa1703c634688cf645ada
2018-06-14 02:50:18 -07:00
Stanislau Hlebik
6d15f70c89 mononoke: add SinkAsyncWrite adapter
Summary:
AsyncWrite and Sink traits have very similar interfaces. This diff creates an
adapter between them.

The primary motivation for this adapter is in Mononoke. Currently mononoke
wireproto methods that return bundles have to buffer them in memory. This have
a few drawbacks. First of all, it increases memory usage and secondly it
increases the latency.

The proper fix would to make Bundle2Encoder return a Stream instead of
BoxFuture<(), Error>. However that would require changing the whole
async-compression crate, and that's too difficult. We may want to eventually do
it, however for now SinkAsyncWrite seems like a good enough fix.

Reviewed By: farnz

Differential Revision: D8379585

fbshipit-source-id: 19af9452ba09318a7505dda44ef765e8c09b004d
2018-06-14 02:50:18 -07:00
Rain ⁣
cfb1588d02 update username and email in Rust code
Summary: Going to take a while to get to everything, but here's a start.

Reviewed By: Imxset21

Differential Revision: D8311107

fbshipit-source-id: ada1908b320a5277eda2587d7e8f26b13b952154
2018-06-07 21:07:14 -07:00
Tim Fox
9e5f08cf6b convert from put_X::<BigEndian> -> put_X_be
Summary: Replace all occurrences of the deprecated put_X::<BigEndian> methods with put_X_be in the files marked with T29077977, and remove any allow deprecation lines in the files and unused imports that might be introduced.

Reviewed By: jsgf

Differential Revision: D7928695

fbshipit-source-id: 8f16915f6b08aa55521637fff58a6cc27c13321a
2018-05-09 09:02:11 -07:00
Jeremy Fitzhardinge
a29aac3469 tp2: update rust-crates-io
Summary:
Update rust-crates-io. Suppress warnings on some deprecated functions;
bootcamped fixes in T29077977.

Reviewed By: StanislavGlebik

Differential Revision: D7897307

fbshipit-source-id: e4b18927b271c663c67ca68bcd784c24b7900e73
2018-05-08 09:09:02 -07:00
Stanislau Hlebik
a5f31946ac mononoke: revsets optimized for pull
Summary:
Specialized revsets to make pull faster.
Previous Union + Intersect combination was extremely slow because it fetched a
lot of stuff that wasn't used.

Reviewed By: farnz

Differential Revision: D7829394

fbshipit-source-id: c038f184c305e48e18b6fcb0f83bab9e9a42b098
2018-05-02 02:23:43 -07:00
Stanislau Hlebik
336ba0f8c5 mononoke: add asynchronize
Summary:
This is a great suggestion from lukaspiatkowski. This method allows us to take synchronous code, schedule it on the default tokio thread pool and convert it to the future.

The great use case is diesel connections.

Reviewed By: lukaspiatkowski

Differential Revision: D7685244

fbshipit-source-id: ba5a99a7ed977a3aa8b5115049cdd71d9b11112c
2018-04-21 08:40:24 -07:00
Stanislau Hlebik
3c5f2212c0 mononoke: fix select_all()
Summary:
In previous diff upstream select_all() was added. However it had a bug.
In
```
match self.inner.poll() {
...
Async::Ready(_) => {
  return Async::Ready(None);
}
}
```

Async::Ready(None) was returned for the case when inner poll returned  `Async::Ready(None)`
and for the case when inner poll returned `Async::Ready(Some(None, remaining))`.
The former was correct, however the latter wasn't. `Async::Ready(Some(None, remaining))`
happens when one of the internal streams was exhausted, however there can be
many more internal streams that are not exhausted yet. Before this diff these
non-exhausted elements would be just lost, so this diff fixes it.

Reviewed By: farnz

Differential Revision: D7550918

fbshipit-source-id: 908af9fed17744b884aa40afdccfc4654520048b
2018-04-10 02:22:51 -07:00
Stanislau Hlebik
32a914edb6 mononoke: copy-paste select_all method from futures-0.2.0
Summary:
This is a simple but useful combinator that queries lots of streams in parallel
and merges the results.
This is code is taken from futures-0.2.0, but it was modified so that it works
with futures-0.1.*. It was re-formatted with our linter.

The code had a bug that will be fixed in the next diffs

Reviewed By: farnz

Differential Revision: D7550919

fbshipit-source-id: c5b394065c0184a89dfab6a9de699725bc2bd6c2
2018-04-10 02:22:51 -07:00
Simon Farnsworth
eb6cf294d3 Give ConservativeReceiever its own error type
Summary: We had a fun bit of debugging because an out-of-order `oneshot::recv()` gave a `oneshot::Canceled` error. Give it an enum for errors, so that we can distinguish dropping the rx channel from calling `oneshot::recv()` before `oneshot::send()`

Reviewed By: StanislavGlebik

Differential Revision: D7382354

fbshipit-source-id: c96f4ac40449a5864b7ba79f43f9af402de7735b
2018-03-26 06:21:20 -07:00
Lukas Piatkowski
d25ca34c0f bundle2-resolver: reorganize resolver for easier handling of BlobRepo::create_changeset
Reviewed By: farnz

Differential Revision: D7032695

fbshipit-source-id: 66a4d75004236536e5dca6da38f71e4662cda0c8
2018-02-22 04:53:56 -08:00
Lukas Piatkowski
ed54079826 futures_ext: added StreamExt::return_remainder
Summary: This new method is useful in my future work where I rely on this easy to use and readable API to be able to get over the fact that futures combinators take Stream by value. With this one can chain on the end of consuming Stream and by using the "remainder" Future get the consumed Stream.

Reviewed By: StanislavGlebik

Differential Revision: D6965532

fbshipit-source-id: 3ab19851b3d48c43c8d7e3a96ae5c03a7d242960
2018-02-14 06:31:41 -08:00
Lukas Piatkowski
0d8cc77882 future-ext: introduce ByteStream for efficient processing stream of bytes
Reviewed By: jsgf

Differential Revision: D6494542

fbshipit-source-id: d069137326697105a402261e4fbe69ab95ade67e
2018-01-15 10:36:32 -08:00
Lukas Piatkowski
533cad062f futures-ext: remove FramedStream and replace it's usages with tokio_io::codec::Framed
Summary: The Framed and FramedParts duet fits following diffs a bit better than FramedStream and ReadLeadingBuffer.

Reviewed By: jsgf

Differential Revision: D6567554

fbshipit-source-id: 88d117ad9e8227f9de278037b333da7ffc4fdf1f
2018-01-15 10:36:31 -08:00
Lukas Piatkowski
35e3c19f1c async-compression: remove the no-compression compressor/decompressor
Summary:
The no-compression decompressor cann't provide framing as other decompressors, so a safe approach would be not to have it at all.
I replaced occurances of no-compression with `Either` reader that seem to be a pattern present in the community (f.e. `futures::future::Either` or `itertools::Either`)

Reviewed By: jsgf

Differential Revision: D6555922

fbshipit-source-id: 998dafab8d9b2f00d058ce2f9e0aced76cf15b4e
2018-01-15 10:36:31 -08:00
Arun Kulshreshtha
fd2c414961 Update to Rust 1.21
Summary:
This diff does a few things:
  - Change the rust versions in `third-party{2,-buck}/config.py` to 1.21.
  - Update the tp2 symlinks for `rust` and `rust-crates-io`
  - Fix build breakages due to new errors/warnings from rustc.

Reviewed By: jsgf, Imxset21

Differential Revision: D6319954

fbshipit-source-id: cd4fe9e0d6f26c1a6c9c3f1256d84cb002bb83d6
2017-11-29 15:21:41 -08:00
Siddharth Agarwal
355e3e02ae futures-ext: add a version of the collect combinator that doesn't consume the stream
Summary:
Sometimes streams can have useful data hanging off of them. For example,
mercurial-bundles' `Bundle2Stream` communicates application-level errors via a
method on the struct. It's important to be able to access that data in tests.

Reviewed By: jsgf

Differential Revision: D6356907

fbshipit-source-id: 42cf2edd0a902e03a4acb894a3174c1c483cc6ab
2017-11-22 01:07:07 -08:00
Jeremy Fitzhardinge
6b5a13c1f6 rust: futures-ext: only consume as much input as needed for the decoder to make progress
Summary:
Avoid over-consuming the input, as excess input isn't easily pushed
back into the input stream. This is necessary to make sure that when parsing a
bundle2 stream we don't consume input from beyond the end of the stream, which
can upset the hg ssh command processor.

Reviewed By: sid0

Differential Revision: D6214174

fbshipit-source-id: 3a2227fab5ddfbb247437508206d40e85024c48e
2017-11-01 18:51:21 -07:00
Chris Konstad
93f8da21c9 Removed deprecated Tokio APIs from common/rust/futures-ext
Summary: See title

Reviewed By: sid0

Differential Revision: D5969152

fbshipit-source-id: e705e81d8ea07b8268267e238c4ebb310892f74e
2017-10-05 11:52:02 -07:00
Jeremy Fitzhardinge
64c19dcf5e rust: futures-ext: use ! for errors that can't happen
Summary:
We can use the "never_type" feature to enable more general use
of the `!` type, which indicates that the type state is impossible (ie,
`!` has no values). Not only is this more expressive than using - say -
`()`, it also allows irrefutable matching against a result (`let Ok(x)
= ...`), since the compiler knows that `Err(!)` can never happen.

Reviewed By: sid0

Differential Revision: D5849877

fbshipit-source-id: 48c14f9c2042fb8168eb1dd308fd3a79c9ed0fc2
2017-09-19 16:11:54 -07:00
Siddharth Agarwal
911164a107 add helpers to box up futures and streams
Summary:
This was deprecated upstream, but is still useful to us.

Also add `nonsend` versions since those are still required in a couple of
places.

Reviewed By: jsgf

Differential Revision: D5817016

fbshipit-source-id: 3753fadcae666099a96b3b849e438c5c16c7232f
2017-09-13 21:52:37 -07:00
Siddharth Agarwal
a74542da60 update and pull in uuid + subprocess
Summary:
Finally got an update working by removing the `mysql_async` crate.

Some notes:

* The `mysql_async` crate was responsible in this case: see https://github.com/rust-lang/cargo/issues/4066#issuecomment-328210204 for why.
* tokio/futures deprecated a bunch of stuff. I've filed a TODO for now.
* We finally pulled in error-chain 0.11, which has a bunch of nice improvements.

Reviewed By: kulshrax

Differential Revision: D5798282

fbshipit-source-id: a38a7b17ee0205428e2ea63334722aa408582493
2017-09-08 17:05:38 -07:00
facebook-github-bot
2b6af6b941 Initial commit
fbshipit-source-id: f75baa4ff6aa71973f677b752d7aba582cf4927f
2017-07-27 18:00:19 -07:00