mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 12:46:49 +00:00
chore: Reformat with latest nightly
This commit is contained in:
113 files changed
+981
-831
No files matched your search
+4
-3
@@ -404,7 +404,8 @@ impl<'a, 'de: 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||
unhandled!("deserialize Unit not implemented")
|
||||
}
|
||||
|
||||
// this only used for $serde_json::private::RawValue at this time; see MapAccess
|
||||
// this only used for $serde_json::private::RawValue at this time; see
|
||||
// MapAccess
|
||||
#[cfg_attr(unabridged, tracing::instrument(level = "trace", skip_all))]
|
||||
fn deserialize_identifier<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value> {
|
||||
let input = "$serde_json::private::RawValue";
|
||||
@@ -480,8 +481,8 @@ fn deserialize_str(input: &[u8]) -> Result<&str> { string::str_from_bytes(input)
|
||||
#[cfg(disable)]
|
||||
#[inline]
|
||||
fn deserialize_str(input: &[u8]) -> Result<&str> {
|
||||
// SAFETY: Strings were written by the serializer to the database. Assuming no
|
||||
// database corruption, the string will be valid. Database corruption is
|
||||
// SAFETY: Strings were written by the serializer to the database. Assuming
|
||||
// no database corruption, the string will be valid. Database corruption is
|
||||
// detected via rocksdb checksums.
|
||||
unsafe { std::str::from_utf8_unchecked(input) }
|
||||
}
|
||||
@@ -109,8 +109,8 @@ pub(crate) fn db_options(config: &Config, env: &Env, row_cache: &Cache) -> Resul
|
||||
|
||||
// <https://github.com/facebook/rocksdb/wiki/Track-WAL-in-MANIFEST>
|
||||
// "We recommend to set track_and_verify_wals_in_manifest to true for
|
||||
// production, it has been enabled in production for the entire database cluster
|
||||
// serving the social graph for all Meta apps."
|
||||
// production, it has been enabled in production for the entire database
|
||||
// cluster serving the social graph for all Meta apps."
|
||||
opts.set_track_and_verify_wals_in_manifest(true);
|
||||
|
||||
opts.set_paranoid_checks(config.rocksdb_paranoid_file_checks);
|
||||
|
||||
@@ -80,8 +80,8 @@ impl super::Map {
|
||||
I: Iterator<Item = &'a K> + ExactSizeIterator + Send,
|
||||
K: AsRef<[u8]> + Send + ?Sized + Sync + 'a,
|
||||
{
|
||||
// Optimization can be `true` if key vector is pre-sorted **by the column
|
||||
// comparator**.
|
||||
// Optimization can be `true` if key vector is pre-sorted **by the
|
||||
// column comparator**.
|
||||
const SORTED: bool = false;
|
||||
|
||||
self.db
|
||||
|
||||
+16
-16
@@ -10,25 +10,25 @@ pub(super) fn open(db: &Arc<Engine>, name: &str) -> Arc<ColumnFamily> {
|
||||
let cf_ptr = bounded_ptr.cast::<ColumnFamily>();
|
||||
|
||||
// SAFETY: Column family handles out of RocksDB are basic pointers and can
|
||||
// be invalidated: 1. when the database closes. 2. when the column is dropped or
|
||||
// closed. rust_rocksdb wraps this for us by storing handles in their own
|
||||
// `RwLock<BTreeMap>` map and returning an Arc<BoundColumnFamily<'_>>` to
|
||||
// provide expected safety. Similarly in "single-threaded mode" we would
|
||||
// receive `&'_ ColumnFamily`.
|
||||
// be invalidated: 1. when the database closes. 2. when the column is
|
||||
// dropped or closed. rust_rocksdb wraps this for us by storing handles in
|
||||
// their own `RwLock<BTreeMap>` map and returning an
|
||||
// Arc<BoundColumnFamily<'_>>` to provide expected safety. Similarly in
|
||||
// "single-threaded mode" we would receive `&'_ ColumnFamily`.
|
||||
//
|
||||
// PROBLEM: We need to hold these handles in a field, otherwise we have to take
|
||||
// a lock and get them by name from this map for every query, which is what
|
||||
// conduit was doing, but we're not going to make a query for every query so we
|
||||
// need to be holding it right. The lifetime parameter on these references makes
|
||||
// that complicated. If this can be done without polluting the userspace
|
||||
// with lifetimes on every instance of `Map` then this `unsafe` might not be
|
||||
// necessary.
|
||||
// PROBLEM: We need to hold these handles in a field, otherwise we have to
|
||||
// take a lock and get them by name from this map for every query, which is
|
||||
// what conduit was doing, but we're not going to make a query for every
|
||||
// query so we need to be holding it right. The lifetime parameter on these
|
||||
// references makes that complicated. If this can be done without polluting
|
||||
// the userspace with lifetimes on every instance of `Map` then this
|
||||
// `unsafe` might not be necessary.
|
||||
//
|
||||
// SOLUTION: After investigating the underlying types it appears valid to
|
||||
// Arc-swap `BoundColumnFamily<'_>` for `ColumnFamily`. They have the
|
||||
// same inner data, the same Drop behavior, Deref, etc. We're just losing the
|
||||
// lifetime parameter. We should not hold this handle, even in its Arc, after
|
||||
// closing the database (dropping `Engine`). Since `Arc<Engine>` is a sibling
|
||||
// member along with this handle in `Map`, that is prevented.
|
||||
// same inner data, the same Drop behavior, Deref, etc. We're just losing
|
||||
// the lifetime parameter. We should not hold this handle, even in its Arc,
|
||||
// after closing the database (dropping `Engine`). Since `Arc<Engine>` is a
|
||||
// sibling member along with this handle in `Map`, that is prevented.
|
||||
unsafe { Arc::from_raw(cf_ptr) }
|
||||
}
|
||||
@@ -381,15 +381,15 @@ impl Pool {
|
||||
// Obtain the result channel.
|
||||
let chan = cmd.res.take().expect("missing result channel");
|
||||
|
||||
// It is worth checking if the future was dropped while the command was queued
|
||||
// so we can bail without paying for any query.
|
||||
// It is worth checking if the future was dropped while the command was
|
||||
// queued so we can bail without paying for any query.
|
||||
if chan.is_canceled() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform the actual database query. We reuse our database::Map interface but
|
||||
// limited to the blocking calls, rather than creating another surface directly
|
||||
// with rocksdb here.
|
||||
// Perform the actual database query. We reuse our database::Map
|
||||
// interface but limited to the blocking calls, rather than creating
|
||||
// another surface directly with rocksdb here.
|
||||
let result = cmd.map.get_blocking(&cmd.key[0]);
|
||||
|
||||
// Send the result back to the submitter.
|
||||
@@ -416,10 +416,10 @@ impl Drop for Pool {
|
||||
}
|
||||
|
||||
fn into_send_get(result: BatchResult<'_>) -> BatchResult<'static> {
|
||||
// SAFETY: Necessary to send the Handle (rust_rocksdb::PinnableSlice) through
|
||||
// the channel. The lifetime on the handle is a device by rust-rocksdb to
|
||||
// associate a database lifetime with its assets. The Handle must be dropped
|
||||
// before the database is dropped.
|
||||
// SAFETY: Necessary to send the Handle (rust_rocksdb::PinnableSlice)
|
||||
// through the channel. The lifetime on the handle is a device by
|
||||
// rust-rocksdb to associate a database lifetime with its assets. The
|
||||
// Handle must be dropped before the database is dropped.
|
||||
unsafe { std::mem::transmute(result) }
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,12 @@ pub(super) fn configure(server: &Arc<Server>) -> (usize, Vec<usize>, Vec<usize>)
|
||||
let device_name = storage::name_from_path(&path).log_debug_err().ok();
|
||||
let device_prop = storage::parallelism(&path);
|
||||
|
||||
// The default worker count is masked-on if we didn't find better information.
|
||||
// The default worker count is masked-on if we didn't find better
|
||||
// information.
|
||||
let default_worker_count = device_prop.mq.is_empty().then_some(config.db_pool_workers);
|
||||
|
||||
// Determine the worker groupings. Each indice represents a hardware queue and
|
||||
// contains the number of workers which will service it.
|
||||
// Determine the worker groupings. Each indice represents a hardware queue
|
||||
// and contains the number of workers which will service it.
|
||||
let worker_counts: Vec<_> = device_prop
|
||||
.mq
|
||||
.iter()
|
||||
@@ -47,8 +48,8 @@ pub(super) fn configure(server: &Arc<Server>) -> (usize, Vec<usize>, Vec<usize>)
|
||||
.chain(default_worker_count)
|
||||
.collect();
|
||||
|
||||
// Determine our software queue size for each hardware queue. This is the mpmc
|
||||
// between the tokio worker and the pool worker.
|
||||
// Determine our software queue size for each hardware queue. This is the
|
||||
// mpmc between the tokio worker and the pool worker.
|
||||
let queue_sizes: Vec<_> = worker_counts
|
||||
.iter()
|
||||
.map(|worker_count| {
|
||||
@@ -58,10 +59,10 @@ pub(super) fn configure(server: &Arc<Server>) -> (usize, Vec<usize>, Vec<usize>)
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Determine the CPU affinities of each hardware queue. Each indice is a cpu and
|
||||
// each value is the associated hardware queue. There is a little shiftiness
|
||||
// going on because cpu's which are not available to the process are filtered
|
||||
// out, similar to the worker_counts.
|
||||
// Determine the CPU affinities of each hardware queue. Each indice is a cpu
|
||||
// and each value is the associated hardware queue. There is a little
|
||||
// shiftiness going on because cpu's which are not available to the process
|
||||
// are filtered out, similar to the worker_counts.
|
||||
let topology = device_prop
|
||||
.mq
|
||||
.iter()
|
||||
@@ -76,8 +77,8 @@ pub(super) fn configure(server: &Arc<Server>) -> (usize, Vec<usize>, Vec<usize>)
|
||||
topology
|
||||
});
|
||||
|
||||
// Regardless of the capacity of all queues we establish some limit on the total
|
||||
// number of workers; this is hopefully hinted by nr_requests.
|
||||
// Regardless of the capacity of all queues we establish some limit on the
|
||||
// total number of workers; this is hopefully hinted by nr_requests.
|
||||
let max_workers = device_prop
|
||||
.mq
|
||||
.iter()
|
||||
@@ -92,8 +93,8 @@ pub(super) fn configure(server: &Arc<Server>) -> (usize, Vec<usize>, Vec<usize>)
|
||||
.sum::<usize>()
|
||||
.clamp(WORKER_LIMIT.0, max_workers);
|
||||
|
||||
// After computing all of the above we can update the global automatic stream
|
||||
// width, hopefully with a better value tailored to this system.
|
||||
// After computing all of the above we can update the global automatic
|
||||
// stream width, hopefully with a better value tailored to this system.
|
||||
if config.stream_width_scale > 0.0 {
|
||||
let num_queues = queue_sizes.len().max(1);
|
||||
update_stream_width(server, num_queues, total_workers);
|
||||
|
||||
+15
-13
@@ -133,20 +133,22 @@ fn keyval_longevity<'a, 'b: 'a>(item: KeyVal<'a>) -> KeyVal<'b> {
|
||||
}
|
||||
|
||||
fn slice_longevity<'a, 'b: 'a>(item: &'a Slice) -> &'b Slice {
|
||||
// SAFETY: The lifetime of the data returned by the rocksdb cursor is only valid
|
||||
// between each movement of the cursor. It is hereby unsafely extended to match
|
||||
// the lifetime of the cursor itself. This is due to the limitation of the
|
||||
// Stream trait where the Item is incapable of conveying a lifetime; this is due
|
||||
// to GAT's being unstable during its development. This unsafety can be removed
|
||||
// as soon as this limitation is addressed by an upcoming version.
|
||||
// SAFETY: The lifetime of the data returned by the rocksdb cursor is only
|
||||
// valid between each movement of the cursor. It is hereby unsafely
|
||||
// extended to match the lifetime of the cursor itself. This is due to the
|
||||
// limitation of the Stream trait where the Item is incapable of conveying
|
||||
// a lifetime; this is due to GAT's being unstable during its development.
|
||||
// This unsafety can be removed as soon as this limitation is addressed by
|
||||
// an upcoming version.
|
||||
//
|
||||
// We have done our best to mitigate the implications of this in conjunction
|
||||
// with the deserialization API such that borrows being held across movements of
|
||||
// the cursor do not happen accidentally. The compiler will still error when
|
||||
// values herein produced try to leave a closure passed to a StreamExt API. But
|
||||
// escapes can happen if you explicitly and intentionally attempt it, and there
|
||||
// will be no compiler error or warning. This is primarily the case with
|
||||
// calling collect() without a preceding map(ToOwned::to_owned). A collection
|
||||
// of references here is illegal, but this will not be enforced by the compiler.
|
||||
// with the deserialization API such that borrows being held across
|
||||
// movements of the cursor do not happen accidentally. The compiler will
|
||||
// still error when values herein produced try to leave a closure passed to
|
||||
// a StreamExt API. But escapes can happen if you explicitly and
|
||||
// intentionally attempt it, and there will be no compiler error or
|
||||
// warning. This is primarily the case with calling collect() without a
|
||||
// preceding map(ToOwned::to_owned). A collection of references here is
|
||||
// illegal, but this will not be enforced by the compiler.
|
||||
unsafe { std::mem::transmute(item) }
|
||||
}
|
||||
@@ -15,7 +15,8 @@ macro_rules! unhandled {
|
||||
// SAFETY: Eliminates branches for serializing and deserializing types never
|
||||
// encountered in the codebase. This can promote optimization and reduce
|
||||
// codegen. The developer must verify for every invoking callsite that the
|
||||
// unhandled type is in no way involved and could not possibly be encountered.
|
||||
// unhandled type is in no way involved and could not possibly be
|
||||
// encountered.
|
||||
unsafe {
|
||||
std::hint::unreachable_unchecked();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user