mirror of
https://github.com/facebook/sapling.git
synced 2024-12-28 15:44:27 +03:00
mononoke: convert places that talk to Memcache to Bytes 0.5
Summary: Memcache doesn't care (because both old and new Bytes to `Into<IOBuf>`), but Thrift is Bytes 0.5. We have our caching ext layer in the middle, which wants Bytes 0.4. This means we end up copying things we don't need to copy. Let's update to fewer copies. I didn't update apiserver, because a) it's going away, and b) those bytes go into Actix, and Actix isn't upgrading to Bytes 0.5 any time soon! Besides, this doesn't actually need updating besides tests anyway. Reviewed By: dtolnay Differential Revision: D20006062 fbshipit-source-id: 42766363a0ff8494f18349bcc822b5238e1ec0cd
This commit is contained in:
parent
288e74f809
commit
c14a88bbef
@ -79,7 +79,7 @@ impl CacheManager {
|
||||
fn set(&self, key: String, value: Bytes) -> impl Future<Item = (), Error = ()> {
|
||||
let key = self.keygen.key(key);
|
||||
let _ = self.cachelib.set_cached(&key, &value.to_vec());
|
||||
self.memcache.set(key, value)
|
||||
self.memcache.set(key, bytes_ext::copy_from_old(value))
|
||||
}
|
||||
|
||||
pub fn get_or_fill<
|
||||
@ -200,7 +200,10 @@ mod test {
|
||||
let serialized_bytes = Bytes::from(serialized.clone());
|
||||
|
||||
runtime
|
||||
.block_on(manager.memcache.set(keygen_key.clone(), serialized_bytes))
|
||||
.block_on(manager.memcache.set(
|
||||
keygen_key.clone(),
|
||||
bytes_ext::copy_from_old(serialized_bytes),
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let result = manager.cachelib.get_cached(&keygen_key).unwrap();
|
||||
|
@ -105,7 +105,7 @@ fn memcache_deserialize(buf: IOBuf) -> Result<BonsaiHgMappingEntry, ()> {
|
||||
}
|
||||
|
||||
fn memcache_serialize(entry: &BonsaiHgMappingEntry) -> Bytes {
|
||||
bytes_ext::copy_from_new(compact_protocol::serialize(&entry.clone().into_thrift()))
|
||||
compact_protocol::serialize(&entry.clone().into_thrift())
|
||||
}
|
||||
|
||||
impl BonsaiHgMapping for CachingBonsaiHgMapping {
|
||||
|
@ -207,7 +207,7 @@ fn deserialize_changeset_entry(buf: IOBuf) -> Result<ChangesetEntry, ()> {
|
||||
}
|
||||
|
||||
fn serialize_changeset_entry(entry: &ChangesetEntry) -> Bytes {
|
||||
bytes_ext::copy_from_new(compact_protocol::serialize(&entry.clone().into_thrift()))
|
||||
compact_protocol::serialize(&entry.clone().into_thrift())
|
||||
}
|
||||
|
||||
fn report_mc_result<T>(res: McResult<T>) {
|
||||
|
@ -90,7 +90,7 @@ pub fn serialize_cs_entries(cs_entries: Vec<ChangesetEntry>) -> Bytes {
|
||||
thrift_entries.push(thrift_entry);
|
||||
}
|
||||
|
||||
bytes_ext::copy_from_new(compact_protocol::serialize(&thrift_entries))
|
||||
compact_protocol::serialize(&thrift_entries)
|
||||
}
|
||||
|
||||
pub fn deserialize_cs_entries(blob: &Bytes) -> Result<Vec<ChangesetEntry>> {
|
||||
|
@ -651,7 +651,7 @@ fn main(fb: FacebookInit) -> Result<(), Error> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bytes::Bytes;
|
||||
use bytes_old::Bytes as BytesOld;
|
||||
use fixtures::linear;
|
||||
use futures::stream;
|
||||
use maplit::btreemap;
|
||||
@ -664,7 +664,7 @@ mod tests {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
let stream: BoxStream<FileBytes, Error> =
|
||||
Box::new(stream::once(Ok(FileBytes(Bytes::from(&b""[..])))));
|
||||
Box::new(stream::once(Ok(FileBytes(BytesOld::from(&b""[..])))));
|
||||
let result = rt.block_on(number_of_lines(stream))?;
|
||||
assert_eq!(result, 0);
|
||||
Ok(())
|
||||
@ -675,7 +675,7 @@ mod tests {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
let stream: BoxStream<FileBytes, Error> = Box::new(stream::once(Ok(FileBytes(
|
||||
Bytes::from(&b"First line\n"[..]),
|
||||
BytesOld::from(&b"First line\n"[..]),
|
||||
))));
|
||||
let result = rt.block_on(number_of_lines(stream))?;
|
||||
assert_eq!(result, 1);
|
||||
@ -687,7 +687,7 @@ mod tests {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
let stream: BoxStream<FileBytes, Error> = Box::new(stream::once(Ok(FileBytes(
|
||||
Bytes::from(&b"First line\nSecond line\nThird line\n"[..]),
|
||||
BytesOld::from(&b"First line\nSecond line\nThird line\n"[..]),
|
||||
))));
|
||||
let result = rt.block_on(number_of_lines(stream))?;
|
||||
assert_eq!(result, 3);
|
||||
@ -699,9 +699,11 @@ mod tests {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
let vec = vec![
|
||||
FileBytes(Bytes::from(&b"First line\n"[..])),
|
||||
FileBytes(Bytes::from(&b""[..])),
|
||||
FileBytes(Bytes::from(&b"First line\nSecond line\nThird line\n"[..])),
|
||||
FileBytes(BytesOld::from(&b"First line\n"[..])),
|
||||
FileBytes(BytesOld::from(&b""[..])),
|
||||
FileBytes(BytesOld::from(
|
||||
&b"First line\nSecond line\nThird line\n"[..],
|
||||
)),
|
||||
];
|
||||
let stream: BoxStream<FileBytes, Error> = Box::new(stream::iter_ok(vec));
|
||||
let result = rt.block_on(number_of_lines(stream))?;
|
||||
|
Loading…
Reference in New Issue
Block a user