java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to net.openhft.chronicle.map.VanillaChronicleMap

1,473 views
Skip to first unread message

Levani Kokhreidze

unread,
Nov 23, 2016, 3:21:25 AM11/23/16
to Chronicle
Hello,

I am fairly new to chronicle map and I stumbled upon one problem. I have a microservice which creates chronicle map with the following code

ChronicleMap.of(String.class, String.class)
          .averageValueSize(averageValueSize)
          .averageKeySize(averageKeySize)
          .averageKey(averageKey)
          .entries(entrySize)
          .createPersistedTo(chronicleDataFile);

And have another java process which tries to access those chronicle map files. The code in another java process is exactly the same. But from there I am getting the following exception:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to net.openhft.chronicle.map.VanillaChronicleMap
at net.openhft.chronicle.map.ChronicleMapBuilder.openWithExistingFile(ChronicleMapBuilder.java:1629) ~[chronicle-map-3.10.1.jar:3.10.1]
at net.openhft.chronicle.map.ChronicleMapBuilder.createWithFile(ChronicleMapBuilder.java:1479) ~[chronicle-map-3.10.1.jar:3.10.1]
at net.openhft.chronicle.map.ChronicleMapBuilder.createPersistedTo(ChronicleMapBuilder.java:1440) ~[chronicle-map-3.10.1.jar:3.10.1]
at eu.plumbr.druid.extensions.lookup.chronicle.ChronicleLookupExtractorFactory.start(ChronicleLookupExtractorFactory.java:49) [chronicle-lookup-extractor-1.0.0.jar:?]
at io.druid.query.lookup.LookupReferencesManager.updateIfNew(LookupReferencesManager.java:191) [druid-processing-0.9.1.1.jar:0.9.1.1]
at io.druid.query.lookup.LookupListeningResource$2.post(LookupModule.java:130) [druid-server-0.9.1.1.jar:0.9.1.1]
at io.druid.server.listener.resource.AbstractListenerHandler.handlePOSTAll(AbstractListenerHandler.java:107) [druid-server-0.9.1.1.jar:0.9.1.1]
at io.druid.server.listener.resource.ListenerResource.serviceAnnouncementPOSTAll(ListenerResource.java:92) [druid-server-0.9.1.1.jar:0.9.1.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_65]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_65]
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) [jersey-server-1.19.jar:1.19]
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) [jersey-servlet-1.19.jar:1.19]
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) [jersey-servlet-1.19.jar:1.19]
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733) [jersey-servlet-1.19.jar:1.19]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [javax.servlet-api-3.1.0.jar:3.1.0]
at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:278) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:268) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:180) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:93) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:132) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.GuiceFilter$1.call(GuiceFilter.java:129) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:206) [guice-servlet-4.0-beta.jar:?]
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:129) [guice-servlet-4.0-beta.jar:?]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlets.UserAgentFilter.doFilter(UserAgentFilter.java:83) [jetty-servlets-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlets.GzipFilter.doFilter(GzipFilter.java:364) [jetty-servlets-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlets.QoSFilter.doFilter(QoSFilter.java:200) [jetty-servlets-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.Server.handle(Server.java:497) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248) [jetty-server-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [jetty-io-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620) [jetty-util-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540) [jetty-util-9.2.5.v20141112.jar:9.2.5.v20141112]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]

The "another" process that tries to access chronicle map is a Druid lookup extension. Strange thing is that this exception happens only from Druid, everything works from other simple Java processes, for example:

public static void main(String args[]) throws IOException {
    ChronicleMap.of(String.class, String.class)
          .averageValueSize(averageValueSize)
          .averageKeySize(averageKeySize)
          .averageKey(averageKey)
          .entries(entrySize)
          .createPersistedTo(chronicleDataFile);
}

Does anyone have any idea why this happens only in druid? Any help would be much appreciated.

Thanks in advance.

Kind regards,
Levani. 

Roman Leventov

unread,
Nov 23, 2016, 3:52:32 AM11/23/16
to java-ch...@googlegroups.com
1) Try to update to Chronicle Map 3.11.0
2) Please ensure that the versions of net.openhft:chronicle-bytes and chronicle-wire jars are exactly the same in classpaths of both processes, and exactly the same as specified in the dependencies of chronicle map currently in use. Correct work is not guaranteed if the versions differ, even in patch number.
3) If it doesn't help please post the beginning of the Chronicle Map file (before it becomes unreadable binary)

Also note that specifying averageKeySize() and averageKey() is excessive at the same time (because the latter configuration overrides the former), leave just averageKey().


--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicle+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Levani Kokhreidze

unread,
Nov 23, 2016, 4:35:04 AM11/23/16
to Chronicle
Hi Roman,

Thanks for the quick reply.

I tried everything that you wrote and versions for wire and bytes jar match for both processes. Unfortunately, situation is the same.

Here is the header of the sample *.dat file

!net.openhft.chronicle.map.VanillaChronicleMap {
  dataFileVersion: "3.11.0",
  keyClass: !type String,
  keySizeMarshaller: !net.openhft.chronicle.hash.serialization.impl.StopBitSizeMarshaller {
  },
  keyReader: !net.openhft.chronicle.hash.serialization.impl.StringSizedReader {
  },
  keyDataAccess: !net.openhft.chronicle.hash.serialization.impl.StringUtf8DataAccess {
  },
  checksumEntries: true,
  actualSegments: 256,
  hashSplitting: !net.openhft.chronicle.hash.impl.HashSplitting$ForPowerOf2Segments {
    bits: 8
  },
  chunkSize: 8,
  maxChunksPerEntry: 33382,
  actualChunksPerSegmentTier: 33382,
  segmentHeaderSize: 64,
  tierHashLookupValueBits: 16,
  tierHashLookupKeyBits: 16,
  tierHashLookupSlotSize: 4,
  tierHashLookupCapacity: 8192,
  maxEntriesPerHashLookup: 6553,
  tierHashLookupInnerSize: 32768,
  tierHashLookupOuterSize: 32768,
  tierFreeListInnerSize: 4176,
  tierFreeListOuterSize: 4224,
  tierEntrySpaceInnerSize: 267056,
  tierEntrySpaceInnerOffset: 0,
  tierEntrySpaceOuterSize: 267072,
  tierSize: 304192,
  maxExtraTiers: 256,
  tierBulkSizeInBytes: 9734144,
  tierBulkInnerOffsetToTiers: 0,
  tiersInBulk: 32,
  log2TiersInBulk: 5,
  valueClass: !type String,
  valueSizeMarshaller: !net.openhft.chronicle.hash.serialization.impl.StopBitSizeMarshaller {
  },
  valueReader: !net.openhft.chronicle.hash.serialization.impl.StringSizedReader {
  },
  valueDataAccess: !net.openhft.chronicle.hash.serialization.impl.StringUtf8DataAccess {
  },
  constantlySizedEntry: false,
  alignment: 1,
  worstAlignment: 0
}

As you can see header starts with ! symbol. And in TextWire#TextValueIn#objectWithInferredType0 I see corresponding switch statement. It doesn't make sense for my why it chooses map instead of object from druid.

To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.

Levani Kokhreidze

unread,
Nov 23, 2016, 6:59:42 AM11/23/16
to Chronicle
Further debugging showed that TextWire#TextValueIn#typePrefix throws ClassNotFoundException when: 

sb = "net.openhft.chronicle.map.VanillaChronicleMap"


Apparently maps:
    private final Map<String, Class> stringClassMap = new ConcurrentHashMap<>();
   
private final Map<String, Class> stringClassMap2 = new ConcurrentHashMap<>();
   
private final Map<Class, String> classStringMap = new ConcurrentHashMap<>();


in ClassAliasPool doesn't contain net.openhft.chronicle.map.VanillaChronicleMap alias

 

On Wednesday, November 23, 2016 at 10:52:32 AM UTC+2, Roman Leventov wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
Message has been deleted

Levani Kokhreidze

unread,
Nov 23, 2016, 7:21:03 AM11/23/16
to Chronicle
OK, it seems somehow related to Druid class loading. net.openhft.chronicle.map.VanillaChronicleMap class can not be found from ClassAliasPool#forName0 method. Class.forName(name0, true, classLoader) returns null.


On Wednesday, November 23, 2016 at 10:52:32 AM UTC+2, Roman Leventov wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.

Rob Austin

unread,
Nov 23, 2016, 7:38:12 AM11/23/16
to java-ch...@googlegroups.com
If seen exceptions like this when classes are not register in  net.openhft.chronicle.core.pool.ClassAliasPool. Although in your case , this is not what the stack trace is reporting.

Levani Kokhreidze

unread,
Nov 24, 2016, 7:34:35 AM11/24/16
to Chronicle
If someone else stumbles up this issue, we were able to solve the problem by putting Chronicle jar files into Druid lib/ folder. Due to yet unknown reasons, Druid doesn't load net.openhft.chronicle.map.VanillaChronicleMap class via extensions.
Reply all
Reply to author
Forward
0 new messages