Skip to content

Commit

Permalink
CORDA-1695 Include thread ID in flow logging MDC (corda#3463)
Browse files Browse the repository at this point in the history
  • Loading branch information
rick-r3 authored and sollecitom committed Jun 28, 2018
1 parent e2f657d commit a768904
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,21 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
if (value) field = value else throw IllegalArgumentException("Can only set to true")
}

/**
/**
* Processes an event by creating the associated transition and executing it using the given executor.
* Try to avoid using this directly, instead use [processEventsUntilFlowIsResumed] or [processEventImmediately]
* instead.
*/
@Suspendable
private fun processEvent(transitionExecutor: TransitionExecutor, event: Event): FlowContinuation {
setLoggingContext()
val stateMachine = getTransientField(TransientValues::stateMachine)
val oldState = transientState!!.value
val actionExecutor = getTransientField(TransientValues::actionExecutor)
val transition = stateMachine.transition(event, oldState)
val (continuation, newState) = transitionExecutor.executeTransition(this, oldState, event, transition, actionExecutor)
transientState = TransientReference(newState)
setLoggingContext()
return continuation
}

Expand Down Expand Up @@ -196,6 +198,7 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
context.pushToLoggingContext()
MDC.put("flow-id", id.uuid.toString())
MDC.put("fiber-id", this.getId().toString())
MDC.put("thread-id", Thread.currentThread().id.toString())
}

@Suspendable
Expand Down Expand Up @@ -353,6 +356,7 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
val serializationContext = TransientReference(getTransientField(TransientValues::checkpointSerializationContext))
val transaction = extractThreadLocalTransaction()
parkAndSerialize { _, _ ->
setLoggingContext()
logger.trace { "Suspended on $ioRequest" }

// Will skip checkpoint if there are any idempotent flows in the subflow stack.
Expand All @@ -379,7 +383,6 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
require(continuation == FlowContinuation.ProcessEvents)
unpark(SERIALIZER_BLOCKER)
}
setLoggingContext()
return uncheckedCast(processEventsUntilFlowIsResumed(
isDbTransactionOpenOnEntry = false,
isDbTransactionOpenOnExit = true
Expand Down

0 comments on commit a768904

Please sign in to comment.