Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common: fix ClassCastException with multi-thread access #278

Closed
chuwy opened this issue Jun 26, 2020 · 3 comments
Closed

Common: fix ClassCastException with multi-thread access #278

chuwy opened this issue Jun 26, 2020 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@chuwy
Copy link
Contributor

chuwy commented Jun 26, 2020

Version 1.2.0

java.lang.ClassCastException: java.util.LinkedHashMap$Entry cannot be cast to java.util.HashMap$TreeNode
at java.util.HashMap$TreeNode.moveRootToFront(HashMap.java:1827)
at java.util.HashMap$TreeNode.treeify(HashMap.java:1944)
at java.util.HashMap.treeifyBin(HashMap.java:771)
at java.util.HashMap.putVal(HashMap.java:643)
at java.util.HashMap.put(HashMap.java:611)
at com.snowplowanalytics.lrumap.CreateLruMap$$anon$1$$anon$4.put(CreateLruMap.scala:51)
at com.snowplowanalytics.lrumap.CreateLruMap$$anon$1$$anon$4.put(CreateLruMap.scala:47)
at com.snowplowanalytics.maxmind.iplookups.IpLookups.$anonfun$performLookupsWithLruCache$1(IpLookups.scala:289)
at cats.package$$anon$1.flatMap(package.scala:41)
at cats.FlatMap$Ops.flatMap(FlatMap.scala:21)
at cats.FlatMap$Ops.flatMap$(FlatMap.scala:21)
at cats.FlatMap$ToFlatMapOps$$anon$2.flatMap(FlatMap.scala:21)
at com.snowplowanalytics.maxmind.iplookups.IpLookups.performLookupsWithLruCache(IpLookups.scala:288)
at com.snowplowanalytics.maxmind.iplookups.IpLookups.$anonfun$performLookups$1(IpLookups.scala:238)
at scala.Option.map(Option.scala:230)
at com.snowplowanalytics.maxmind.iplookups.IpLookups.performLookups(IpLookups.scala:238)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.registry.IpLookupsEnrichment.extractIpInformation(IpLookupsEnrichment.scala:124)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.$anonfun$geoLocation$2(EnrichmentManager.scala:364)
at cats.data.OptionT.$anonfun$flatMap$1(OptionT.scala:53)
at scala.Option.fold(Option.scala:251)
at cats.data.OptionT.$anonfun$flatMapF$1(OptionT.scala:56)
at cats.package$$anon$1.flatMap(package.scala:41)
at cats.data.OptionT.flatMapF(OptionT.scala:56)
at cats.data.OptionT.flatMap(OptionT.scala:53)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.$anonfun$geoLocation$1(EnrichmentManager.scala:363)
at cats.data.OptionT.$anonfun$flatMap$1(OptionT.scala:53)
at scala.Option.fold(Option.scala:251)
at cats.data.OptionT.$anonfun$flatMapF$1(OptionT.scala:56)
at cats.package$$anon$1.flatMap(package.scala:41)
at cats.data.OptionT.flatMapF(OptionT.scala:56)
at cats.data.OptionT.flatMap(OptionT.scala:53)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.geoLocation(EnrichmentManager.scala:362)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.runEnrichments(EnrichmentManager.scala:204)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.$anonfun$enrichEvent$4(EnrichmentManager.scala:78)
at cats.data.EitherT.$anonfun$flatMap$1(EitherT.scala:99)
at cats.package$$anon$1.flatMap(package.scala:41)
at cats.data.EitherT.flatMap(EitherT.scala:97)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.$anonfun$enrichEvent$2(EnrichmentManager.scala:76)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.$anonfun$enrichEvent$2$adapted(EnrichmentManager.scala:75)
at cats.data.EitherT.$anonfun$flatMap$1(EitherT.scala:99)
at cats.package$$anon$1.flatMap(package.scala:41)
at cats.data.EitherT.flatMap(EitherT.scala:97)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.$anonfun$enrichEvent$1(EnrichmentManager.scala:75)
at cats.data.EitherT.$anonfun$flatMap$1(EitherT.scala:99)
at cats.package$$anon$1.flatMap(package.scala:41)
at cats.data.EitherT.flatMap(EitherT.scala:97)
at com.snowplowanalytics.snowplow.enrich.common.enrichments.EnrichmentManager$.enrichEvent(EnrichmentManager.scala:74)
at com.snowplowanalytics.snowplow.enrich.common.EtlPipeline$.$anonfun$processEvents$2(EtlPipeline.scala:68)
at cats.instances.ListInstances$$anon$1.$anonfun$traverse$2(list.scala:74)
at cats.instances.ListInstances$$anon$1.loop$2(list.scala:64)
at cats.instances.ListInstances$$anon$1.$anonfun$foldRight$1(list.scala:64)
at cats.Eval$.loop$1(Eval.scala:336)
at cats.Eval$.cats$Eval$$evaluate(Eval.scala:368)
at cats.Eval$Defer.value(Eval.scala:257)
at cats.instances.ListInstances$$anon$1.traverse(list.scala:73)
at cats.instances.ListInstances$$anon$1.traverse(list.scala:12)
at cats.Traverse$Ops.traverse(Traverse.scala:19)
at cats.Traverse$Ops.traverse$(Traverse.scala:19)
at cats.Traverse$ToTraverseOps$$anon$3.traverse(Traverse.scala:19)
at com.snowplowanalytics.snowplow.enrich.common.EtlPipeline$.$anonfun$processEvents$1(EtlPipeline.scala:66)
at cats.package$$anon$1.flatMap(package.scala:41)
at cats.FlatMap$Ops.flatMap(FlatMap.scala:21)
at cats.FlatMap$Ops.flatMap$(FlatMap.scala:21)
at cats.FlatMap$ToFlatMapOps$$anon$2.flatMap(FlatMap.scala:21)
at com.snowplowanalytics.snowplow.enrich.common.EtlPipeline$.processEvents(EtlPipeline.scala:64)
at com.snowplowanalytics.snowplow.enrich.beam.Enrich$.enrich(Enrich.scala:271)
at com.snowplowanalytics.snowplow.enrich.beam.Enrich$.$anonfun$enrichEvents$2(Enrich.scala:199)
at com.snowplowanalytics.snowplow.enrich.beam.utils$.timeMs(utils.scala:152)
at com.snowplowanalytics.snowplow.enrich.beam.Enrich$.$anonfun$enrichEvents$1(Enrich.scala:196)
at com.spotify.scio.util.Functions$$anon$7.processElement(Functions.scala:263)

@chuwy
Copy link
Contributor Author

chuwy commented Jun 26, 2020

Migrated from snowplow/beam-enrich#37 (comments are auto-generated)

@chuwy
Copy link
Contributor Author

chuwy commented Jun 26, 2020

One source of ClassCastExceptions was JS Enrichment, which is getting fixed by #138

@chuwy chuwy changed the title Beam: investigate ClassCastException Common: fix ClassCastException with multi-thread access Jul 11, 2020
@chuwy chuwy self-assigned this Jul 11, 2020
@chuwy chuwy added the bug Something isn't working label Jul 11, 2020
@chuwy
Copy link
Contributor Author

chuwy commented Jul 12, 2020

The commit is fairly overloaded. Reason of the exception was a race condition in scala-lru-map caused by workers trying to evict the same element from cache. As a workaround we had to replace own LinkedHashMap-backed implementation with scalacache and guava backend.

Scalacache provides its own way to abstract over effects and Eval instances are fairly hard to implement. As a result I decided to drop the Eval in scala-lru-map, which in turn required to drop all Eval logic from SCE. Luckily, we have Evals only in tests and switching with Id made them just closer to real-world implementation.

Also see #51

@chuwy chuwy added this to the 1.3.0 milestone Jul 12, 2020
@chuwy chuwy closed this as completed in 48e4ce8 Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant