Commit Graph

55 Commits

Author SHA1 Message Date
Simon Farnsworth
2bf6be2869 Make all bindings fully exception-safe
Summary:
cachelib can throw exceptions from any method. Make all our bindings
exception-safe

Reviewed By: jsgf

Differential Revision: D9158062

fbshipit-source-id: 57948aa6ead304fac6e037621a1f6641826345c5
2018-08-07 13:37:08 -07:00
Simon Farnsworth
cc1454d333 Restore cachelib blob caching
Summary: Reverts D8989404 so that we're using cachelib again.

Reviewed By: jsgf

Differential Revision: D9036003

fbshipit-source-id: 9867a12b81369156ee2e6aa7a7f1c81a638185d6
2018-08-07 11:37:37 -07:00
Zeyi Fan
82ab81238d re-exporting types from other crate is not a good idea
Summary:
I had enough seeing compiler giving me error messages with `blobrepo::Error` whereas it should be `failure::Error`.

`pub type` is exporting a type alias whereas `pub use` is re-exporting. The later apparently will fool the compiler to think that they own the thing they are re-exporting which in this case, failure::Error. If it is for the purpose of declaring the error type the crate is using, type alias is obviously more suitable as it won't take the ownership of the type.

Reviewed By: lukaspiatkowski

Differential Revision: D8926275

fbshipit-source-id: 6b1346adf52bec6b666a3f8b23e7a4ea4e0ab070
2018-07-26 14:23:07 -07:00
Lukas Piatkowski
dec3e9a444 mononoke: backout cachelib integration for blob caching
Summary:
Back out "[mononoke] Switch to cachelib for blob caching"

Original commit changeset: 2549d85dfcba

Back out "[mononoke] Remove unused asyncmemo imports"

Original commit changeset: e34f8c34a3f6

Back out "mononoke: fix blobimport"

Original commit changeset: b540201b93f1

Reviewed By: StanislavGlebik

Differential Revision: D8989404

fbshipit-source-id: e4e7c629cb4dcf196aa56eb07a53a45f6008eb4e
2018-07-26 10:09:32 -07:00
Simon Farnsworth
9ee880f90e Remove unused asyncmemo imports
Summary: These files import the asyncmemo crate but do not use it. Remove it.

Reviewed By: StanislavGlebik

Differential Revision: D8951887

fbshipit-source-id: e34f8c34a3f652156b63d795023d67260242a58e
2018-07-23 07:37:30 -07:00
Simon Farnsworth
2d15681343 Switch to cachelib for blob caching
Summary:
Start deprecating AsyncMemo for caching purposes, by removing its use
as a blobstore cache.

Reviewed By: StanislavGlebik

Differential Revision: D8840496

fbshipit-source-id: 2549d85dfcba6647e9b0824ab55ab76165a17564
2018-07-21 13:37:14 -07:00
Rain ⁣
fa58de6e4e blobrepo: add support for doing in-memory writes to blobstore
Summary:
This proves to be extremely useful for the upcoming bonsai
verification code.

The in-memory stuff is more complicated for the database backends, so punt on
that for now with some warnings.

Reviewed By: farnz

Differential Revision: D8909426

fbshipit-source-id: 1d66d877cfa48ef06bbe614f37c66cf6c2f0446c
2018-07-20 11:37:36 -07:00
Rain ⁣
e15c0bf3c1 blobstore: implement Debug for all blobstores
Summary:
This is generally quite useful while trying to figure out what chain
of blobstores this actually is.

Reviewed By: farnz

Differential Revision: D8909424

fbshipit-source-id: 49ba471c71c3da109bd219ec5f78cc0fdc2bc857
2018-07-20 11:37:36 -07:00
Simon Farnsworth
fa7507f60b Fix lease releases
Summary:
StanislavGlebik noticed that the lease release on a successful store didn't
have the correct hint - fix it.

Reviewed By: StanislavGlebik

Differential Revision: D8893519

fbshipit-source-id: d509aa72575533ad161b96599c80f8d9c3b4f997
2018-07-19 04:36:59 -07:00
Simon Farnsworth
0d53c4599e Implement blobstore leases in-process
Summary:
It's wasteful to send the same bunch of bytes to a backing blobstore
twice; introduce an in-memory LeaseOps that, when combined with a presence
cache, ensures that we'll never do that.

Reviewed By: StanislavGlebik

Differential Revision: D8820987

fbshipit-source-id: 406a388cb1f08a35daa49151dadd023fde260e07
2018-07-18 04:36:08 -07:00
Simon Farnsworth
f83fd7225a Add a cachelib backed Blobstore cache
Summary:
We want to remove AsyncMemo from caching duties - abusing a memoizer
to provide caching introduces issues of its own. Provide a replacement cache we
can use instead of AsyncMemo

Reviewed By: StanislavGlebik

Differential Revision: D8810965

fbshipit-source-id: 0469c5ff5f16cf40ae1a1652f0af0d301611a39a
2018-07-18 04:36:08 -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 ⁣
c463be6e11 blobstore: use inlinable string for prefix
Summary:
This blobstore gets cloned a lot, and an inline string is much cheaper
to clone.

Reviewed By: StanislavGlebik

Differential Revision: D8843939

fbshipit-source-id: 879c2e43b27ec7a410ef64eb65d3ac78d21fa1db
2018-07-16 00:21:34 -07:00
Simon Farnsworth
4933b3f8e2 Introduce DummyLease, to nop out Blobstore leases for testing
Summary:
The CachingBlobstore can use a LeaseOps implementation to prevent
multiple parallel writes to the same backing store. Provide a dummy implementation
that does not block parallel writes, for performance testing and to use where
there's no way to implement a useful lease operation using a given cache.

Reviewed By: StanislavGlebik

Differential Revision: D8809077

fbshipit-source-id: 54cf67882a42b43dde1c6ac68611fb28144509bc
2018-07-12 09:07:00 -07:00
Simon Farnsworth
2f35a8dd24 Add stats to memcache operations to distinguish the causes of each success/failure
Summary:
The memcache implementations of CacheOps and LeaseOps are fairly complex, with lots of edge cases.

Add some stats, so we can see which edge cases are being hit, and optimize accordingly

Reviewed By: lukaspiatkowski

Differential Revision: D8752599

fbshipit-source-id: fe1376956beceff702c2b6a020598556016033b5
2018-07-10 12:52:46 -07:00
Simon Farnsworth
d40a725f7b Refactor MemcacheBlobstore to split into common and memcache parts
Summary:
When we add cachelib bindings to Rust, we're going to want to implement a
cachelib blobstore that's more or less the same as the memcache version, but
backed by a cachelib pool instead of a memcache instance.

Split this code up so that we don't duplicate functionality

Reviewed By: StanislavGlebik

Differential Revision: D8523713

fbshipit-source-id: 882298abab8c208103f6d8c74fee60a768c877f6
2018-07-10 10:10:18 -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
Simon Farnsworth
f62f032e2e Implement a "cache mutex" to avoid multiple writes through memcache
Summary:
Manifold can complain when we expect it to succeed if we write the
same thing twice. As this is inefficient, use memcache to avoid writing to the
backing blobstore if we know the object is already present

Reviewed By: StanislavGlebik

Differential Revision: D8424296

fbshipit-source-id: 3b97683b80a1ea5245998d8446c8f540975343df
2018-06-19 13:07:13 -07:00
Simon Farnsworth
43c9f2f29a Use different memcache keys for each backing blobstore
Summary:
It would be suboptimal if memcache could be abused to examine objects
you should not have access to. Change the key used so that (a) it's a regional
cluster for wider caching, and (b) it's got the blobstore details in it so that
you cannot extract objects not from your blob store.

Reviewed By: StanislavGlebik

Differential Revision: D8424298

fbshipit-source-id: 78f9a1a7302b4a60575f257bda665f719dc1a7b6
2018-06-15 14:03:44 -07:00
Lukas Piatkowski
2cddcd7a8e blobstore: add CountedBlobstore to measure usage of different layers of blobstores
Reviewed By: StanislavGlebik

Differential Revision: D8446905

fbshipit-source-id: 7a7f605a5e8cc1dfb9b983606e5c42f80686c863
2018-06-15 10:10:41 -07:00
Rain ⁣
f3fe0b37fc blobstore: switch memcache methods to a trait
Summary:
So that both prefixed and non-prefixed blobstores can be used with the
same code.

Reviewed By: farnz

Differential Revision: D8402466

fbshipit-source-id: 3a4f7882ce697d0582eb7f7908b74716322806cf
2018-06-13 13:13:06 -07:00
Rain ⁣
1327706215 blobstore: add a blobstore which prefixes keys
Summary:
We'd like to prefix each key with a fixed string, and this wrapper
easily lets us achieve that.

Reviewed By: farnz

Differential Revision: D8374708

fbshipit-source-id: f02845d207c8015ea0241789f696884d440e3db6
2018-06-12 15:40:10 -07:00
Rain ⁣
e3ff3de80c blobstore: move memblob into main blobstore
Summary: It's really straightforward and useful for internal blobstore testing.

Reviewed By: farnz

Differential Revision: D8374496

fbshipit-source-id: 8501e31218ecb5d80530a114e0be5e5d0e8f6c91
2018-06-12 15:40:10 -07:00
Simon Farnsworth
9b98afc9a4 Implement is_present directly in MemcacheBlobstore
Summary:
When I implement a cachemutex to keep the herd from all trying to
write the same blob multiple times, we'll be able to accelerate this. In the
short term, move the implementation up to here so that the change will be
obvious when it's put up for review.

Reviewed By: jsgf

Differential Revision: D8318152

fbshipit-source-id: f117c5fd834cab55ace10ac46bffa881457c840a
2018-06-08 06:53:16 -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
Simon Farnsworth
b2978095e2 Add an admin command option to interrogate memcache blobstore
Summary: If we're going to use memcache to cache things, we need to be able to confirm that the blobstore contains what we expect. Add an admin option that lets us check what's in memcache and/or in the blobstore when using memcache

Reviewed By: StanislavGlebik

Differential Revision: D8124624

fbshipit-source-id: 763786930cf9f4be6d2d8e346ae1ef94dc8e492c
2018-05-30 07:21:15 -07:00
Simon Farnsworth
e1a783d3e6 Add a Memcache-backed caching blobstore
Summary:
Memcache provides us with a low-latency out-of-process cache, shared
between multiple machines. If we use this to provide a write-through cache,
then we get a couple of benefits:

1. Mononoke servers accessing the same memcache backend get low latency access
to commonly requested blobs.
2. Recently written blobs are available at low latency to the server that just
wrote them, hopefully speeding up new_blobimport.

Reviewed By: StanislavGlebik

Differential Revision: D8124623

fbshipit-source-id: 5af085aa8bb63c1366740edfda9020d72b8a9015
2018-05-30 07:21:15 -07:00
Simon Farnsworth
2e24a77e85 Rename CachingBlobstore to MemoizedBlobstore
Summary:
I'm about to introduce a MemoizedBlobstore - let's ensure that
ambiguity is kept to a minimum by renaming CachingBlobstore

Reviewed By: jsgf

Differential Revision: D8124625

fbshipit-source-id: 301fbb31c5a772c11e84566889b8a6ac86cdae19
2018-05-29 10:08:16 -07:00
Simon Farnsworth
e33d05223f Make CachingBlobstore generic, to allow optimization through the Arc
Summary:
In practice, caching blobstores are always wrapped around a known
concrete blob store. Make it generic in the type of the Blobstore, so that
rustc can reach in and inline appropriately if it sees an optimization
opportunity.

This is a micro-optimization, hence nice to have

Reviewed By: StanislavGlebik

Differential Revision: D8124627

fbshipit-source-id: 0d5d9b11fdede062ceaa949ace574b3d1c75e6b5
2018-05-29 10:08:16 -07:00
Simon Farnsworth
969026576d Refactor blobstore lib.rs to reduce its size
Summary:
I'm about to add a memcache caching blobstore, and the blobstore
lib.rs is getting large. Shrink it by removing the outdated comment, replacing
it with documentation comments, and moving the CachingBlobstore to its own file

Reviewed By: jsgf

Differential Revision: D8124626

fbshipit-source-id: ac081a162c2f15a26452ff708d16a108699c279b
2018-05-29 10:08:16 -07:00
Jeremy Fitzhardinge
51c49a47be tp2: update to rust 1.26.0 and corresponding rust-crates-io rebuild
Summary:
Rust 1.26 adds many new language features. In particular `impl Trait` is now
stable, so we no longer need `conservative_impl_trait`.

There also seems to have been changed in the (unstable) TryFrom with respect to
usize, and the behaviour of the never type `!`.

There are still a few deprecation warnings, but they don't cause the build to
fail.

Path remapping is now stable, so the buck config needs to change to use it
rather than the unstable command line option.

TODO:
- get aarch64 rust-crates-io build (can defer to a later update)

Reviewed By: Imxset21

Differential Revision: D7966091

fbshipit-source-id: 2e61e262c21eb01c852a36f49c6a6369cdaddcdb
2018-05-11 11:07:33 -07:00
Jeremy Fitzhardinge
22bc45bf1f mononoke: migrate DelayBlob to new timer model
Summary:
We don't need to explicitly create timers since the environment has
one set up by default.

Reviewed By: StanislavGlebik

Differential Revision: D7873576

fbshipit-source-id: bfcdc27a46397bff0730f64ad4f3de3865c7cfa1
2018-05-04 10:15:26 -07:00
Siddharth Agarwal
4e9f826728 blobstore: restrict the types that can be stored
Summary:
Currently, any sort of `Bytes` can be stored in the blobstore. That
caused me to make several mistakes while writing the code to store bonsai
changesets, because I'd just end up storing the wrong set of `Bytes`.

Introduce stronger typing so that only types that explicitly implement
`BlobStorable` can be stored in the blobstore.

Currently, these sorts of blobs can be stored in the blob store:

* `ChangesetBlob` and `ContentBlob` in `mononoke-types` (these are Thrift-serialized structures)
* The envelope `RawNodeBlob` and `RawCSBlob` types in `blobrepo`, once converted to `EnvelopeBlob` instances
* `HgBlob`, which contains revlog data (manifests or files) exactly as serialized by Mercurial

Reviewed By: StanislavGlebik

Differential Revision: D7627290

fbshipit-source-id: d1bcbde8881e365dec99618556e7b054985bccf7
2018-04-18 19:53:32 -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
Simon Farnsworth
3005439ed3 Introduce a delaying blob store, for testing
Summary:
We don't want to depend on Manifold being consistent and reliable when
we're trying to fix our performance issues. Introduce a DelayBlob store that
wraps another blobstore and allows you to pass it a function that generates
delay times (e.g. a random number generator with a log-normal distribution).

The idea is that we can use DelayBlob wrapped around RocksBlob to approximate
expected Manifold behaviour, and can improve if needed.

Reviewed By: StanislavGlebik

Differential Revision: D7353228

fbshipit-source-id: fee977d2754f3134af752efc2dbfc77fedc7f2bf
2018-03-22 07:03:27 -07:00
Simon Farnsworth
9e366eacd4 Introduce a LazyMemblob test blobstore
Summary:
The current Memblob store is eager; this is great for finding certain
classes of bugs (those that assume an ordering that is not guaranteed), but not
so good for exposing other classes of bugs (those that assume that the future
has done its work before it resolves).

Add a lazy variant that functions in the same way as Memblob, but that waits
until it's polled to return.

Reviewed By: StanislavGlebik

Differential Revision: D7033792

fbshipit-source-id: 4c2d8a8150d908bcb26347757f96f99e20d74fc2
2018-02-21 07:17:00 -08:00
Simon Farnsworth
1510d2838f Fix default assert_present implementation
Summary:
The default implementation of `assert_present` only asserted that no
errors were found accessing the blobstore. Update it to fail if the blob is
absent.

Reviewed By: StanislavGlebik

Differential Revision: D7033794

fbshipit-source-id: 596d3b0d3d55d05a5b96760c311defe5a05af634
2018-02-21 04:06:57 -08:00
Simon Farnsworth
03c30f7067 Extend blobstore with methods for commit API
Summary:
The commit API would like to avoid uploading and downloading data when
it doesn't need to - extend the blobstore API so that blobstores can avoid
wasted work

Reviewed By: StanislavGlebik

Differential Revision: D6966729

fbshipit-source-id: 17783e2123d47e43824af724da0b4358a163fa5b
2018-02-13 04:36:20 -08:00
Simon Farnsworth
28caf3f938 Remove Error, GetBlob and PutBlob from BlobStore
Summary:
Remove the last associated types from BlobStore - this means that
BlobStore now has an associated trait object type.

Reviewed By: jsgf

Differential Revision: D6425414

fbshipit-source-id: 7186dab9b56593dd1d70be732d4ad56d1e7b3c63
2017-12-11 07:05:53 -08:00
Jeremy Fitzhardinge
ac31713c84 rust: failure cleanup pass
Summary:
Don't use failure's bail!() and ensure!() macros.

Instead, failure_ext provides:
- bail_err!(err) - Converts its single parameter to the expected error and returns; ie `return Err(From::from(err));`
- bail_msg!(fmt, ...) - takes format string parameters and returns a `failure::err_msg()` error
- ensure_err!(), ensure_msg!() - corresponding changes

Also:
- remove all stray references to error-chain
- remove direct references to failure_derive (it's reexported via failure and failure_ext)
- replace uses of `Err(foo)?;` with `bail_err!()` (since `bail_err` unconditionally returns, but `Err(x)?` does not in principle, which can affect type inference)

Reviewed By: kulshrax

Differential Revision: D6507717

fbshipit-source-id: 635fb6f8c96d185b195dff171ea9c8db9e83af10
2017-12-07 14:10:17 -08:00
Jeremy Fitzhardinge
dc5e78c1c1 rust: mass convert scm/mononoke/... to use failure
Summary:
Convert scm/mononoke to use failure, and update common/rust crates it depends on as well.

What it looks like is a lot of deleted code...

General strategy:
- common/rust/failure_ext adds some things that are in git failure that aren't yet in crates.io (`bail!` and `ensure!`, `Result<T, Error>`)
- everything returns `Result<T, failure::Error>`
- crates with real error get an error type, with a derived Fail implementation
  - replicate error-chain by defining an `enum ErrorKind` where the fields match the declared errors in the error! macro
- crates with dummy error-chain (no local errors) lose it
- `.chain_err()` -> `.context()` or `.with_context()`

So far the only place I've needed to extract an error is in a unit test.
Having a single unified error type has simplified a lot of things, and removed a lot of error type parameters, error conversion, etc, etc.

Reviewed By: sid0

Differential Revision: D6446584

fbshipit-source-id: 744640ca2997d4a85513c4519017f2e2e78a73f5
2017-12-05 18:11:13 -08:00
Simon Farnsworth
16da012250 Remove ValueIn/ValueOut from the BlobStore generic arguments.
Summary:
BlobStore is entirely generic, and puts no limits on its
implementations. Remove ValueIn and ValueOut type parameters, and insist that
all blobs are Bytes (as per production setups)

Reviewed By: StanislavGlebik

Differential Revision: D6425413

fbshipit-source-id: 455e526d8baebd0d0f1906941648acca89be4881
2017-12-04 10:22:09 -08:00
Simon Farnsworth
c1ee28dbc7 Remove Key from the BlobStore generic arguments.
Summary:
BlobStore is entirely generic, and puts no limits on its
implementations. Remove the "Key" type parameter, and insist that all keys are
String (as per production setups)

Reviewed By: StanislavGlebik

Differential Revision: D6425412

fbshipit-source-id: 1f1229bf8e001bf780964e883c6beb071e9ef1d8
2017-12-04 10:22:09 -08:00
Stanislau Hlebik
83f2eb90a5 mononoke: remove retries
Summary:
Putting retries on this layer is not very good, because it requires every
client to add RetryingBlobstore.

Reviewed By: kulshrax

Differential Revision: D6298254

fbshipit-source-id: dbdce7fe141f9e1511322e74a1258d3819a68eb5
2017-11-13 03:21:31 -08:00
Lukas Piatkowski
9712530c0e blobstore: add RetryingBlobstore that retries failed put/get operations with delay
Reviewed By: StanislavGlebik

Differential Revision: D6203017

fbshipit-source-id: 277fa267e86d2cb5eede241bf80dd8d1c90a3b96
2017-10-31 20:53:08 -07:00
Brandon Milton
90b02ca11a Remove uses of deprecated Tokio API
Summary:
Removes uses of deprecated Tokio API by doing the following:
1. Removing the ignore deprecation header
2. Including `futures_ext` in TARGETS
3. Porting all FutureBox uses to `futures_ext`
4. Porting `boxed()` to `boxify()`

The guide I followed:
https://our.intern.facebook.com/intern/wiki/Rust/Tokio_cleanup/

Reviewed By: sid0

Differential Revision: D6083953

fbshipit-source-id: 93b3ce0c70affbbf2b1158abf66f6f3a4d60a420
2017-10-20 09:39:46 -07:00
Siddharth Agarwal
0a0c594e03 blobstore: unify blobstore tests
Summary:
Similar to heads/bookmarks, share blobstore tests across
implementations.

The trait bounds got a bit tricky, but I think I managed to get the ones we
need and no more.

Reviewed By: StanislavGlebik

Differential Revision: D6082649

fbshipit-source-id: 3a80adc95d6c1059dab7ec89e5ec5724370cc268
2017-10-18 15:20:39 -07:00
Siddharth Agarwal
db28a15305 add deny(warnings)/allow(deprecated) to a few crates
Summary:
Realized that we were missing a few crates from the Tokio cleanup because those crates
didn't have `#![deny(warnings)]`.

This also caused a bunch of files to be rustfmted, which is fine.

Reviewed By: kulshrax

Differential Revision: D6024628

fbshipit-source-id: 55032d20f3676c92ef124d861e1edcd34126ab55
2017-10-10 15:23:25 -07:00
Fangbo Tao
c7017dd916 Removes usage of BoxFuture and BoxStream from futures crate in blobstore/fileblob
Summary: Removes usage of BoxFuture and BoxStream from futures crate in blobstore/fileblob, following instructions in https://our.intern.facebook.com/intern/wiki/Rust/Tokio_cleanup/

Reviewed By: jsgf

Differential Revision: D5884656

fbshipit-source-id: dcf979daf939cd193f4d6361eb36d03977380a22
2017-09-28 15:38:23 -07:00