Loadable interface in classpath with any extension coordinate dynamically loaded causes problems
Currently the initialization routine checks for implementations in the extension coordinates, and optionally (via druid.extensions.searchCurrentClassloader) in the classpath.
This can cause unexpected binding behavior where items are attempted to be bound twice if the extension happens to also be in the classpath.
Steps to reproduce:
1.Unzip a fresh copy of the services self contained tar.gz
2.Copy an extension to the lib directory which happens to also be in the list of coordinates under config/_common cp ~/.m2/repository/io/druid/extensions/mysql-metadata-storage/0.7.0-SNAPSHOT/mysql-metadata-storage-0.7.0-SNAPSHOT.jar lib/
3.Run it java -cp config/_common/:config/coordinator/:lib/* io.druid.cli.Main server coordinator
result:
2015-01-07 11:26:58,945 INFO [main] io.druid.initialization.Initialization - Adding extension module[class io.druid.metadata.storage.mysql.MySQLMetadataStorageModule] for class[io.druid.initialization.DruidModule]
Exception in thread "main" com.google.inject.CreationException: Guice creation errors:
1) Map injection failed due to duplicated key "mysql"
at com.google.inject.multibindings.MapBinder$RealMapBinder$1.initialize(MapBinder.java:357)
at io.druid.guice.PolyBind.optionBinder(PolyBind.java:94)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:448)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:176)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at io.druid.initialization.Initialization.makeInjectorWithModules(Initialization.java:371)
at io.druid.cli.GuiceRunnable.makeInjector(GuiceRunnable.java:57)
at io.druid.cli.ServerRunnable.run(ServerRunnable.java:39)
at io.druid.cli.Main.main(Main.java:90)
Alternatively, put the extension's jar in the classpath, then run with a COMPLETELY DIFFERENT extension (like druid.extensions.coordinates=["io.druid.extensions:druid-kafka-seven"])
same effect.
A potential fix is to ensure that all DruidModules and CliCommandCreators implement the following or similar:
@Override
public int hashCode(){
return getClass().getCanonicalName().hashCode();
}
Implementing a simple equals method is highly suggested as well.
Do you have an example of the sort of unexpected behavior this is causing and what problems it may cause? I could see a use case where someone may want to load a newer version of an existing module as part of extensions, without having to rebuild all of Druid.
Found out this also requires some mainline druid code changes in the Initialization::getFromExtensions
Yes, let me get a use case for you that works on mainline druid.
1.Unzip a fresh copy of the services self contained tar.gz
2.Copy an extension to the lib directory which happens to also be in the list of coordinates under config/_common cp ~/.m2/repository/io/druid/extensions/mysql-metadata-storage/0.7.0-SNAPSHOT/mysql-metadata-storage-0.7.0-SNAPSHOT.jar lib/
3.Run it java -cp config/_common/:config/coordinator/:lib/* io.druid.cli.Main server coordinator
result:
2015-01-07 11:26:58,945 INFO [main] io.druid.initialization.Initialization - Adding extension module[class io.druid.metadata.storage.mysql.MySQLMetadataStorageModule] for class[io.druid.initialization.DruidModule]
Exception in thread "main" com.google.inject.CreationException: Guice creation errors:
1) Map injection failed due to duplicated key "mysql"
at com.google.inject.multibindings.MapBinder$RealMapBinder$1.initialize(MapBinder.java:357)
at io.druid.guice.PolyBind.optionBinder(PolyBind.java:94)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:448)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:176)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at io.druid.initialization.Initialization.makeInjectorWithModules(Initialization.java:371)
at io.druid.cli.GuiceRunnable.makeInjector(GuiceRunnable.java:57)
at io.druid.cli.ServerRunnable.run(ServerRunnable.java:39)
at io.druid.cli.Main.main(Main.java:90)
This is MOST annoying for testing/development purposes where it is very easy to accidentally pollute your ClassPath with your new extension that you are testing.
errr... this got closed automatically on closing #1425. repoening.
Believed fixed by #1427