Commit Graph

30 Commits

Author SHA1 Message Date
Andres Suarez
9a90a484f8 Apply rustfmt to all rust files
Reviewed By: jsgf

Differential Revision: D14578283

fbshipit-source-id: 9b4a7b1fd445fd033b64c6af04ee52b27eefb616
2019-07-10 19:36:32 -07:00
David Tolnay
df39ac67d6 rust: Remove extern crate from common/rust
Summary:
This diff removes all occurrences of `extern crate` from //fbcode/common/rust// except within files included into bindgen code which are forced to use 2015 edition.

`#[macro_use]` attributes are replaced by 2018-style individual `use` of macros.

Reviewed By: jsgf

Differential Revision: D16179130

fbshipit-source-id: 25771eaec8e38043bfa1f9be267dc185758cd2d7
2019-07-10 11:58:48 -07:00
Greg Cowan
041770b090 Transition fbcode Rust crates to 2018 edition
Summary: Marking all Cargo.tomls in fbcode as 2018 edition.

Reviewed By: jsgf

Differential Revision: D15951175

fbshipit-source-id: edf18449c214ee1ff285d6a2cb61839aaf58a8cd
2019-06-24 13:15:17 -07:00
Jeremy Fitzhardinge
4e97680a8f Convert //common/rust/asyncmemo:asyncmemo to Rust 2018
Reviewed By: StanislavGlebik

Differential Revision: D15444118

fbshipit-source-id: 42b7a17de75ff6e10bae9dd5175793338fe6546f
2019-05-22 01:00:42 -07:00
Jeremy Fitzhardinge
ec86d453ae rust/stats: don't require users to import lazy_static
Summary:
Now that Rust macros can be `use`d like normal symbols, `stats` can
simply import the `lazy_static!` macro without requiring its users to do it.

Reviewed By: Imxset21

Differential Revision: D13281897

fbshipit-source-id: a6780fbace07dd784308e642d4a384322a17c367
2018-12-02 14:34:39 -08:00
Pulkit Goyal
0f34435140 Add travis-CI integration by adding .travis.yml file.
Summary: Pull Request resolved: https://github.com/facebookexperimental/mononoke/pull/8

Differential Revision: D9015245

Pulled By: jsgf

fbshipit-source-id: e898c50241a837964b98b86aa2fd457cb4db5f5a
2018-07-26 10:09:32 -07:00
Lukas Piatkowski
a429cf26ac rust: update tokio_timer to 0.2
Reviewed By: farnz

Differential Revision: D8872798

fbshipit-source-id: c053f8d36da2321e28267ce6905d5a8ac24a84df
2018-07-17 04:54:59 -07:00
Rain ⁣
80db1ae90c add inlinable_string and chashmap
Summary:
Add optionally and necessarily inlinable strings, and another
concurrent hashmap impl.

The asyncmemo changes are because of futures 0.1.23, which fixed an [unsoundness bug](15dbc97f30).

Reviewed By: kulshrax

Differential Revision: D8840579

fbshipit-source-id: 77d3e724310b727aeacc0c86a0353ea01e8fc679
2018-07-13 14:37:46 -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
Lukas Piatkowski
985e370f87 asyncmemo: add stats to track size of asyncmemo cache
Reviewed By: jsgf

Differential Revision: D8677107

fbshipit-source-id: f3ef30f36c918c1d4e06d3e2e7856ce429bad6cf
2018-06-28 09:21:31 -07:00
Lukas Piatkowski
a1203f7d30 asyncmemo: shard CacheHash to reduce lock contention
Summary:
It seems that a single mutex on a cache is causing too much contention.

In this diff the Mutex<CacheHash> is split into Vec<Mutex<CacheHash>> and a `std::collections::hash_map::DefaultHasher` is used to compute the shard of a key.

Reviewed By: StanislavGlebik

Differential Revision: D8627675

fbshipit-source-id: cbb46ff26815862f447d15bb92bca4eafc720eac
2018-06-26 09:06:28 -07:00
Simon Farnsworth
59ddd45a41 Don't do a fetch when MemoizedBlobstore::is_present is called
Summary:
Memcache is going to provide a faster implementation of `is_present`
that relies on the put cachemutex. We lose all the benefits if `is_present` up
here ends up always calling `get` from lower layers - teach it not to do that.

Reviewed By: jsgf

Differential Revision: D8318151

fbshipit-source-id: 130d4cb17c530c8677bdd563806989c393b4c6cf
2018-06-08 06:53:16 -07:00
Stanislau Hlebik
08b1e0226c asyncmemo: do not add key sizes to the total weight
Summary:
We had an asyncmemo bug when keys were, for example, Strings. If we insert
String::new("key"), and then try to remove String::new("key"), then these keys
may have different weights because Strings may have different capacity.

This is not the case for values though, because inserted and deleted value is
always the same object.

Let's not take key sizes into account at all. That means that the real asyncmemo memory usage will be
higher, however values are a great deal bigger than keys, so it sholdn't be an
issue.
Also we are planning to do it anyway, because we want to split
asyncmemo hashmap into in-flight futures and completed futures, and in-flight
futures won't take key sizes into account.

Reviewed By: jsgf

Differential Revision: D8040684

fbshipit-source-id: 332dbe5663182dd84ea291ca4b33b41995ac0166
2018-05-18 01:58:19 -07:00
Jeremy Fitzhardinge
337d3797a8 rust/asyncmemo: try using parking_lot for locking
Summary:
parking_lot's primitives are apparently lighter-weight than using
standard (pthreads) ones, and are more or less drop-in replacements.

Reviewed By: farnz

Differential Revision: D7661246

fbshipit-source-id: c7558a15971bf5b30c4dadb9437586832cdad3d4
2018-05-17 12:27:27 -07:00
Stanislau Hlebik
b3432410ae mononoke: use caching for filenodes
Summary: As with changesets and blobs, let's cache filenodes data

Reviewed By: jsgf

Differential Revision: D7831105

fbshipit-source-id: 334cb474f5cc3ef8dba0945d11273b2b3875e8ad
2018-05-03 10:31:32 -07:00
Stanislau Hlebik
3f600af142 mononoke: add Changesets cache
Summary:
Use asyncmemo to cache Changesets.

Unfortunately currently we are using separate asyncmemo cache, so we have to
specify the size for the caches separately. Later we'll have a single cache for
everything, and the number of config knobs will go down.

Reviewed By: lukaspiatkowski

Differential Revision: D7685376

fbshipit-source-id: efe8a3a95fcc72fab4f4af93564e706cd1540c2f
2018-04-22 04:59:27 -07:00
Stanislau Hlebik
6dc26e93d5 asyncmemo: remove Polling state
Summary:
Polling state doesn't help much. It only helps prevent a create/create race,
however in practice it happens very rarely. Even if it happens, it won't be a
big deal, because the same future will be created twice.

At the same time Polling state makes a lot of things broken - see the new
tests. There were a lot of situations that can prevent future from ever
resolving.

Let's remove this state.

Reviewed By: jsgf

Differential Revision: D7635175

fbshipit-source-id: d1314ffdb91aca9c3fc11d734ca35b8965150b9f
2018-04-18 04:09:09 -07:00
Stanislau Hlebik
1b74ed40a1 mononoke: add CachingBlobstore
Summary:
Add CachingBlobstore that uses Asyncmemo as a cache.

Normal Blobstore returns Option<Bytes>. CachingBlobstore doesn't cache `None` response, because this blob may appear later in the blobstore, and we want clients to be able to access it.

Reviewed By: farnz

Differential Revision: D6579385

fbshipit-source-id: 746a5c222dd00a35c3353e76c2792fc8e2323381
2018-04-18 03:30:07 -07:00
Stanislau Hlebik
263c0b980e asyncmemo: remove overgeneric Weight implementation
Summary:
That prevents us from implementing, for example, Weight for Bytes. There are no
impl specialization in Rust yet, and since Bytes do not implement HeapSizeOf,
we can't implement Weight for Bytes.

However we want to use Asyncmemo with Bytes. So in order to fix the issue let's
remove overgeneric Weight implementation and add implementation for the most
basic things.

Reviewed By: jsgf

Differential Revision: D7639162

fbshipit-source-id: b81d7e50599fdd8bdb8f9903d7aedff71734cdf2
2018-04-18 03:30:07 -07:00
Siddharth Agarwal
c909b681f8 add some debug code to figure out a failing test
Summary:
Not clear why this is happening, and I can't repro on my devserver, so
this debug code it is.

Reviewed By: swolchok

Differential Revision: D7480116

fbshipit-source-id: 0c9d54e22ed8ca51b27796792b0cc2045fe88f45
2018-04-02 18:18:38 -07:00
Stanislau Hlebik
3011302908 mononoke: rewrite asyncmemo to use Shared
Summary:
Asyncmemo re-implementation using Shared future. The reasons for doing it are:

1 Now it's safe to drop MemoFuture
2 Now there will be no deadlocks where one future evict another future from the
cache, and then the second future evicts the first futures and so on.

Since Shared returns SharedError, I had to do a hack to work around that. More
details in the code comments.

Reviewed By: farnz

Differential Revision: D7099852

fbshipit-source-id: e08cb859ef06f28339ac9314edb8e53e92480874
2018-03-01 02:35:34 -08:00
Stanislau Hlebik
3e7319dcfc asyncmemo: record all the tasks that polled the future
Summary:
Previously if we had two different tasks (or the same tasks but with different
Notify, as in
[FuturesUnordered](http://alexcrichton.com/futures-rs/futures/stream/futures_unordered/struct.FuturesUnordered.html)),
interchangebly polling the future, only one latest future completes, and all
other futures receive no `notify()` call and may never finish.
This diff fixes it by storing a list of tasks that ever polled a future.

Note that if future was polled twice by the same task, the task will be
recorded twice. This is not great, but unfortunately one can't compare Tokio's
tasks.

Reviewed By: lukaspiatkowski

Differential Revision: D6611511

fbshipit-source-id: 2742cb85b13a684699a13a874e36e17b29fb4480
2018-01-19 02:18:10 -08:00
Stanislau Hlebik
9ba06ebc3c asyncmemo: remove entry with the same key before inserting new one
Summary:
There was a bug when if the entry with the same key is present in the hash and
the hash is full, then some entry will be evicted even though it's not
necessary.
It adds one hash map lookup, but it shouldn't be a big problem

Reviewed By: jsgf

Differential Revision: D6702001

fbshipit-source-id: 1c8cadc5e4bad6f6d95279b21edf00ed99f62c49
2018-01-19 01:10:27 -08:00
Stanislau Hlebik
45f1fbdd4e asyncmemo: use spawn() in tests
Summary:
In the next diff we'll `task::current()` inside MemoFuture. It fails if no
task exists. Let's use spawn to create a Task for each future.

Reviewed By: jsgf

Differential Revision: D6611510

fbshipit-source-id: 95a825dff9714579e9b16e74f355c54d8fa83a24
2017-12-22 03:41:22 -08:00
Stanislau Hlebik
79c6006853 rust: asyncmemo rustfmt
Summary: rustfmt

Reviewed By: jsgf

Differential Revision: D6611512

fbshipit-source-id: 84c8306015e961ea283341fc1a52c153f3db2a49
2017-12-22 03:41:22 -08:00
Stanislau Hlebik
e734b3f9be asyncmemo: fix hash size calculation
Summary: Previously inserting the same key twice will add size of this key twice.  This diff fixes it.

Reviewed By: jsgf

Differential Revision: D6602501

fbshipit-source-id: eb8f785296945bca1df4b6cd33bd3050a48e2174
2017-12-22 03:41:22 -08:00
Jeremy Fitzhardinge
8c457e731c rust: asyncmemo: add failure test
Summary: Add a unit test for failing to compute a value.

Reviewed By: Imxset21

Differential Revision: D5717910

fbshipit-source-id: cb5b1560a539f4b99d87dc2f8fc0afd37f4b5b97
2017-08-29 12:36:18 -07:00
Jeremy Fitzhardinge
9501d33699 rust: asyncmemo: allow fill function to be recursive
Summary:
Pass a reference to the cache to the fill function. This allows the
function to be recursive based on memoized values.

This also required quite a bit of restructuring to make sure that locks
and ownership are handled properly during recursive calls. Specifically,
a new `Slot` state - `Polling` - is used to indicate when a thread/task
is currently calling `.poll()` on the future. This contains a list of
futures Tasks which are interested in the state of the slot which can be
notified when it changes state.

Also removed unused Entry API code.

Reviewed By: sid0

Differential Revision: D5652704

fbshipit-source-id: 29cd3fe37d4eb9316235872b7e2e228bf10a016f
2017-08-29 12:36:18 -07:00
Jeremy Fitzhardinge
08b847a0b9 rust: asyncmemo: implement Debug
Summary: Implement Debug for Asyncmemo where possible.

Reviewed By: sid0

Differential Revision: D5652740

fbshipit-source-id: c04e3972ade1b7120d273c1500b3e2650b2a8c34
2017-08-22 15:05:03 -07:00
facebook-github-bot
2b6af6b941 Initial commit
fbshipit-source-id: f75baa4ff6aa71973f677b752d7aba582cf4927f
2017-07-27 18:00:19 -07:00