rabbah commented on a change in pull request #3199: One tid for the whole
system.
URL:
https://github.com/apache/incubator-openwhisk/pull/3199#discussion_r182921359
##########
File path: common/scala/src/main/scala/whisk/common/TransactionId.scala
##########
@@ -200,58 +196,42 @@ object TransactionId {
val metricsKamonTags: Boolean =
sys.env.get("METRICS_KAMON_TAGS").getOrElse("False").toBoolean
val metricsLog: Boolean =
sys.env.get("METRICS_LOG").getOrElse("True").toBoolean
- val unknown = TransactionId(0)
- val testing = TransactionId(-1) // Common id for for unit testing
- val invoker = TransactionId(-100) // Invoker startup/shutdown or GC activity
- val invokerWarmup = TransactionId(-101) // Invoker warmup thread that makes
stem-cell containers
- val invokerNanny = TransactionId(-102) // Invoker nanny thread
- val dispatcher = TransactionId(-110) // Kafka message dispatcher
- val loadbalancer = TransactionId(-120) // Loadbalancer thread
- val invokerHealth = TransactionId(-121) // Invoker supervision
- val controller = TransactionId(-130) // Controller startup
- val dbBatcher = TransactionId(-140) // Database batcher
-
- def apply(tid: BigDecimal, extraLogging: Boolean = false): TransactionId = {
- Try {
- val now = Instant.now(Clock.systemUTC())
- TransactionId(TransactionMetadata(tid.toLong, now, extraLogging))
- } getOrElse unknown
+ val generatorConfig =
loadConfigOrThrow[TransactionGeneratorConfig](ConfigKeys.transactions)
+
+ val unknown = TransactionId("sid_unknown")
+ val testing = TransactionId("sid_testing") // Common id for for unit testing
+ val invoker = TransactionId("sid_invoker") // Invoker startup/shutdown or GC
activity
+ val invokerWarmup = TransactionId("sid_invokerWarmup") // Invoker warmup
thread that makes stem-cell containers
+ val invokerNanny = TransactionId("sid_invokerNanny") // Invoker nanny thread
+ val dispatcher = TransactionId("sid_dispatcher") // Kafka message dispatcher
+ val loadbalancer = TransactionId("sid_loadbalancer") // Loadbalancer thread
+ val invokerHealth = TransactionId("sid_invokerHealth") // Invoker supervision
+ val controller = TransactionId("sid_controller") // Controller startup
+ val dbBatcher = TransactionId("sid_dbBatcher") // Database batcher
+
+ def apply(tid: String, extraLogging: Boolean = false): TransactionId = {
+ val now = Instant.now(Clock.systemUTC())
+ TransactionId(TransactionMetadata(tid, now, extraLogging))
}
implicit val serdes = new RootJsonFormat[TransactionId] {
def write(t: TransactionId) = {
if (t.meta.extraLogging)
- JsArray(JsNumber(t.meta.id), JsNumber(t.meta.start.toEpochMilli),
JsBoolean(t.meta.extraLogging))
+ JsArray(JsString(t.meta.id), JsNumber(t.meta.start.toEpochMilli),
JsBoolean(t.meta.extraLogging))
else
- JsArray(JsNumber(t.meta.id), JsNumber(t.meta.start.toEpochMilli))
+ JsArray(JsString(t.meta.id), JsNumber(t.meta.start.toEpochMilli))
}
def read(value: JsValue) =
Try {
value match {
- case JsArray(Vector(JsNumber(id), JsNumber(start))) =>
- TransactionId(TransactionMetadata(id.longValue,
Instant.ofEpochMilli(start.longValue), false))
- case JsArray(Vector(JsNumber(id), JsNumber(start),
JsBoolean(extraLogging))) =>
- TransactionId(TransactionMetadata(id.longValue,
Instant.ofEpochMilli(start.longValue), extraLogging))
+ case JsArray(Vector(JsString(id), JsNumber(start))) =>
+ TransactionId(TransactionMetadata(id,
Instant.ofEpochMilli(start.longValue), false))
+ case JsArray(Vector(JsString(id), JsNumber(start),
JsBoolean(extraLogging))) =>
+ TransactionId(TransactionMetadata(id,
Instant.ofEpochMilli(start.longValue), extraLogging))
}
} getOrElse unknown
}
}
-/**
- * A thread-safe transaction counter.
- */
-trait TransactionCounter {
- case class TransactionCounterConfig(stride: Int)
-
- val transCounterConfig =
loadConfigOrThrow[TransactionCounterConfig](ConfigKeys.transactions)
- val stride = transCounterConfig.stride
- val instanceOrdinal: Int
-
- // seed the counter so transids do not overlap: instanceOrdinal + n *
stride, start at n = 1
- private lazy val cnt = new AtomicInteger(instanceOrdinal + stride)
-
- def transid(extraLogging: Boolean = false): TransactionId = {
- TransactionId(cnt.addAndGet(stride), extraLogging)
- }
-}
+case class TransactionGeneratorConfig(header: String)
Review comment:
I think for local testing it might still be nice to have a counter based id
instead. Thoughts?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services