Commit Graph

57 Commits

Author SHA1 Message Date
David Tolnay
fed2ac83f4 rust: Head start on some upcoming warnings
Summary:
This diff sets two Rust lints to warn in fbcode:

```
[rust]
  warn_lints = bare_trait_objects, ellipsis_inclusive_range_patterns
```

and fixes occurrences of those warnings within common/rust, hg, and mononoke.

Both of these lints are set to warn by default starting with rustc 1.37. Enabling them early avoids writing even more new code that needs to be fixed when we pull in 1.37 in six weeks.

Upstream tracking issue: https://github.com/rust-lang/rust/issues/54910

Reviewed By: Imxset21

Differential Revision: D16200291

fbshipit-source-id: aca11a7a944e9fa95f94e226b52f6f053b97ec74
2019-07-12 00:56:44 -07:00
David Tolnay
01a10353b7 rust/futures: Make macros work without FutureExt trait in scope
Summary:
Previously:

```
error[E0599]: no method named `boxify` found for type `futures::future::result_::FutureResult<_, _>` in the current scope
  --> experimental/dtolnay/thttp/main.rs:23:21
   |
23 |     let transport = try_boxfuture!(HttpClient::new(ENDPOINT));
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
   |
1  | use futures_ext::FutureExt;
   |
```

Reviewed By: Imxset21

Differential Revision: D16134586

fbshipit-source-id: 324d2c7223c5e71ffc1f4390cd8fc0b488243c00
2019-07-05 14:31:30 -07:00
Thomas Orozco
bd50a8cde1 futures-ext: BytesStream: don't busy loop on EOF
Summary:
When the underlying stream in a `BytesStream` hits EOF, and the `BytesStream` is asked for more data, it'll busy loop until more data becomes available.

This happens because when the `BytesStream` hits EOF on the underlying stream, it'll record that the stream is done, and won't ever poll the underlying stream again in `poll_buffer`. However, in `poll_buffer_until`, we essentially busy loop through calls to `poll_buffer`

When that happens, the process goes into an infinite loop of:

- Checking that it doesn't have enough bytes.
- Observing that the stream is done.
- Calling `poll_buffer` and not making any progress.

Instead, the right behavior would be to return a successful read of length zero in `read()` to indicate EOF to the caller. This is what this patch does.

It's worth noting that even if the underlying stream returned more data after it reported it was exhausted (callers should avoid polling them again ... or use `fuse()`), the `BytesStream` won't ever poll for that data, since it skips the poll because `stream_done` is set.

Reviewed By: farnz

Differential Revision: D16130672

fbshipit-source-id: a61c39feb1aa1ac74bbef909e47d698051477533
2019-07-05 04:13:50 -07:00
David Tolnay
5369643ef4 rust/futures: Add futures_ext::top_level_launch
Summary:
```
pub fn top_level_launch<F>(future: F) -> Result<F::Item, F::Error>
where
    F: Future + Send + 'static,
    F::Item: Send,
    F::Error: Send;
```

Starts the Tokio runtime using the supplied future to bootstrap the execution.

### Similar APIs

This function is equivalent to [`tokio::run`](https://docs.rs/tokio/0.1.22/tokio/fn.run.html) except that it also returns the future's resolved value as a Result. Thus it requires `F::Item: Send` and `F::Error: Send`.

This function has the same signature as [`Future::wait`](https://docs.rs/futures/0.1.28/futures/future/trait.Future.html#method.wait) which also goes from `F: Future` -> `Result<F::Item, F::Error>`, but `wait` requires an ambient futures runtime to already exist.

### Details

This function does the following:

- Start the Tokio runtime using a default configuration.
- Spawn the given future onto the thread pool.
- Block the current thread until the runtime shuts down.
- Send ownership of the future's resolved value back to the caller's thread.

Note that the function will not return immediately once the original future has completed. Instead it waits for the entire runtime to become idle.

### Panics

This function panics if called from the context of an executor.

Reviewed By: bolinfest

Differential Revision: D16116198

fbshipit-source-id: 52009e17c1ccc566e0c156a86f8fd5844e0e2491
2019-07-04 12:00:03 -07:00
Pavel Aslanov
4488c7c6ab add bounded_traversal_stream
Summary: Introduce `bounded_traversal_stream` operation with is similar to `bounde_traversal` but does not do `fold` hence it is not structure preserving, and returns stream as result.

Reviewed By: farnz

Differential Revision: D16108231

fbshipit-source-id: 3854ff5e18bcf2d7aa3dc75a2b66d27c59ea4f2c
2019-07-04 03:54:12 -07:00
Pavel Aslanov
115f35785d make it more flexible with regards to fold arguments
Summary: After using it for sometime I found that it is more convenient to introduce addition parameter `OutCtx` which represent all information needed about node for `fold` operation instead of using `In`. Note this implementation is strictly more general, and isomorphic to previous one if `OutCtx == In`.

Reviewed By: farnz

Differential Revision: D16029193

fbshipit-source-id: f562baa023d737ce1db2936987f6c59bcd0c3761
2019-06-27 06:57:01 -07:00
Pavel Aslanov
f54d77bac8 pass mutable reference to In for unfold
Summary: Since we own `In` elements `unfold` can have mutable reference instead of immutable one. This can simplify some code, see `BlobRepo::find_entries_in_manifest` for example.

Reviewed By: farnz

Differential Revision: D15939878

fbshipit-source-id: 9c767240bec279f24f922e0771ac919072b3a56c
2019-06-21 08:00:00 -07:00
Pavel Aslanov
6c6d948385 adds Mutex extentsion method .with
Summary:
I find that it is common pattern
```
// create unnecessary to reduce scope of lock guard
let output = {
    let mut value = mutex_value.lock().expect("lock poisoned");
    ... // do some stuff here
};
```
This extension simplifies this pattern to
```
let output = mutex_value.with(|value| /* do some stuff here */);
```

Reviewed By: Imxset21, farnz

Differential Revision: D15577135

fbshipit-source-id: 6b22b20dda79e532ff5ec8ce75cda8b1c1404368
2019-05-31 09:28:54 -07:00
Stanislau Hlebik
ff85bce75d RFC: mononoke: memory limited getpackv1 stream
Reviewed By: farnz

Differential Revision: D14850752

fbshipit-source-id: 211964c407bff33e6e5679ba991cd7cbbfb052ea
2019-05-29 09:39:04 -07:00
Pavel Aslanov
c845de3bd8 added bounded_traversal
Summary: `bounded_traversal` traverses implicit asynchronous tree specified by `init` and `unfold` arguments, and it also does backward pass with `fold` operation. All `unfold` and `fold` operations are executed in parallel if they do not depend on each other (not related by ancestor-descendant relation in implicit tree) with amount of concurrency constrained by `scheduled_max`.

Reviewed By: jsgf

Differential Revision: D15197796

fbshipit-source-id: 1145497f5cb1c0effee47a4d27698bcf9d88f840
2019-05-21 12:25:51 -07:00
Stanislau Hlebik
d3e9dce296 RFC mononoke: do batch writes to blobstore sync queue
Summary:
We've hit an issue of slow pushes to Mononoke when a commit modifies a lot of
files (>500 in our case). turned out that the problem was in the fact that
we have only one master write connection open, and each blobstore write
requires a write to mysql because of multiplexed blobstore. Because we have
only one connection open all our mysql writes are serialized, and the push is
taking too much time. It's especially bad in non-master regions.

To mitigate the issue let's add a batching in the blobstore sync queue. When
clients call `blobstore_sync_queue.add(...)` we'll send this new entry via the
channel to a separate task that would send writes in batches. That allows us to
increase throughput significantly.

Reviewed By: jsgf

Differential Revision: D15248288

fbshipit-source-id: 22bab284b0cbe552b4b51bab4027813b4278fd14
2019-05-21 12:25:45 -07:00
Pavel Aslanov
fcc83b5e93 remove all extern create statements
Summary: remove all `extern create` statements from `futures-ext` crate

Reviewed By: StanislavGlebik

Differential Revision: D15197798

fbshipit-source-id: 61280aa779148a24a0a9c78f25754ea06aa9ee49
2019-05-21 12:25:33 -07:00
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