Struct holochain::core::IncomingDhtOpSender
source · pub struct IncomingDhtOpSender { /* private fields */ }
Expand description
Allows you to send an op to the incoming_dht_ops_workflow if you found it on the network and were supposed to be holding it.
Implementations§
source§impl IncomingDhtOpSender
impl IncomingDhtOpSender
sourcepub fn new(
space: Arc<Space>,
sys_validation_trigger: TriggerSender
) -> IncomingDhtOpSender
pub fn new(
space: Arc<Space>,
sys_validation_trigger: TriggerSender
) -> IncomingDhtOpSender
Examples found in repository?
src/core/workflow/sys_validation_workflow.rs (line 100)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
async fn sys_validation_workflow_inner(
workspace: Arc<SysValidationWorkspace>,
space: Arc<Space>,
network: HolochainP2pDna,
conductor_handle: ConductorHandle,
sys_validation_trigger: TriggerSender,
) -> WorkflowResult<WorkComplete> {
let db = workspace.dht_db.clone();
let sorted_ops = validation_query::get_ops_to_sys_validate(&db).await?;
let start_len = sorted_ops.len();
tracing::debug!("Validating {} ops", start_len);
let start = (start_len >= NUM_CONCURRENT_OPS).then(std::time::Instant::now);
let saturated = start.is_some();
// Process each op
let iter = sorted_ops.into_iter().map({
let space = space.clone();
move |so| {
// Create an incoming ops sender for any dependencies we find
// that we are meant to be holding but aren't.
// If we are not holding them they will be added to our incoming ops.
let incoming_dht_ops_sender =
IncomingDhtOpSender::new(space.clone(), sys_validation_trigger.clone());
let network = network.clone();
let workspace = workspace.clone();
let conductor_handle = conductor_handle.clone();
async move {
let (op, op_hash) = so.into_inner();
let op_type = op.get_type();
let action = op.action();
let dependency = get_dependency(op_type, &action);
let r = validate_op(
&op,
&(*workspace),
network,
conductor_handle.as_ref(),
Some(incoming_dht_ops_sender),
)
.await;
r.map(|o| (op_hash, o, dependency))
}
}
});
// Create a stream of concurrent validation futures.
// This will run NUM_CONCURRENT_OPS validation futures concurrently and
// return up to NUM_CONCURRENT_OPS * 100 results.
use futures::stream::StreamExt;
let mut iter = futures::stream::iter(iter)
.buffer_unordered(NUM_CONCURRENT_OPS)
.ready_chunks(NUM_CONCURRENT_OPS * 100);
// Spawn a task to actually drive the stream.
// This allows the stream to make progress in the background while
// we are committing previous results to the database.
let (tx, rx) = tokio::sync::mpsc::channel(NUM_CONCURRENT_OPS * 100);
let jh = tokio::spawn(async move {
// Send the result to task that will commit to the database.
while let Some(op) = iter.next().await {
if tx.send(op).await.is_err() {
tracing::warn!("app validation task has failed to send ops. This is not a problem if the conductor is shutting down");
break;
}
}
});
// Create a stream that will chunk up to NUM_CONCURRENT_OPS * 100 ready results.
let mut iter =
tokio_stream::wrappers::ReceiverStream::new(rx).ready_chunks(NUM_CONCURRENT_OPS * 100);
let mut total = 0;
let mut round_time = start.is_some().then(std::time::Instant::now);
// Pull in a chunk of results.
while let Some(chunk) = iter.next().await {
let num_ops: usize = chunk.iter().map(|c| c.len()).sum();
tracing::debug!("Committing {} ops", num_ops);
let (t, a, m, r) = space
.dht_db
.async_commit(move |txn| {
let mut total = 0;
let mut awaiting = 0;
let mut missing = 0;
let mut rejected = 0;
for outcome in chunk.into_iter().flatten() {
let (op_hash, outcome, dependency) = outcome?;
match outcome {
Outcome::Accepted => {
total += 1;
put_validation_limbo(
txn,
&op_hash,
ValidationLimboStatus::SysValidated,
)?;
}
Outcome::AwaitingOpDep(missing_dep) => {
awaiting += 1;
// TODO: Try and get this dependency to add to limbo
//
// I actually can't see how we can do this because there's no
// way to get an DhtOpHash without either having the op or the full
// action. We have neither that's why where here.
//
// We need to be holding the dependency because
// we were meant to get a StoreRecord or StoreEntry or
// RegisterAgentActivity or RegisterAddLink.
let status = ValidationLimboStatus::AwaitingSysDeps(missing_dep);
put_validation_limbo(txn, &op_hash, status)?;
}
Outcome::MissingDhtDep => {
missing += 1;
// TODO: Not sure what missing dht dep is. Check if we need this.
put_validation_limbo(txn, &op_hash, ValidationLimboStatus::Pending)?;
}
Outcome::Rejected => {
rejected += 1;
if let Dependency::Null = dependency {
put_integrated(txn, &op_hash, ValidationStatus::Rejected)?;
} else {
put_integration_limbo(txn, &op_hash, ValidationStatus::Rejected)?;
}
}
}
}
WorkflowResult::Ok((total, awaiting, missing, rejected))
})
.await?;
total += t;
if let (Some(start), Some(round_time)) = (start, &mut round_time) {
let round_el = round_time.elapsed();
*round_time = std::time::Instant::now();
let avg_ops_ps = total as f64 / start.elapsed().as_micros() as f64 * 1_000_000.0;
let ops_ps = t as f64 / round_el.as_micros() as f64 * 1_000_000.0;
tracing::info!(
"Sys validation is saturated. Util {:.2}%. OPS/s avg {:.2}, this round {:.2}",
(start_len - total) as f64 / NUM_CONCURRENT_OPS as f64 * 100.0,
avg_ops_ps,
ops_ps
);
}
tracing::debug!("{} committed, {} awaiting sys dep, {} missing dht dep, {} rejected. {} committed this round", t, a, m, r, total);
}
jh.await?;
tracing::debug!("Accepted {} ops", total);
Ok(if saturated {
WorkComplete::Incomplete
} else {
WorkComplete::Complete
})
}
Trait Implementations§
source§impl Clone for IncomingDhtOpSender
impl Clone for IncomingDhtOpSender
source§fn clone(&self) -> IncomingDhtOpSender
fn clone(&self) -> IncomingDhtOpSender
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for IncomingDhtOpSender
impl Send for IncomingDhtOpSender
impl Sync for IncomingDhtOpSender
impl Unpin for IncomingDhtOpSender
impl !UnwindSafe for IncomingDhtOpSender
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
TODO: once 1.33.0 is the minimum supported compiler version, remove
Any::type_id_compat and use StdAny::type_id instead.
https://github.com/rust-lang/rust/issues/27745
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.§impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref