mirror of https://github.com/apache/druid.git
remove mysql dependencies + fix jdbc class loading
This commit is contained in:
parent
c2727dd063
commit
3cc1b2e690
|
@ -46,9 +46,8 @@
|
|||
<artifactId>commons-codec</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>1.4</version>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-pool</groupId>
|
||||
|
|
|
@ -47,11 +47,6 @@
|
|||
<artifactId>druid-indexing-hadoop</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.18</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Tests -->
|
||||
<dependency>
|
||||
|
|
|
@ -49,16 +49,6 @@
|
|||
<artifactId>druid-server</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.druid</groupId>
|
||||
<artifactId>druid-indexing-hadoop</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.druid</groupId>
|
||||
<artifactId>druid-indexing-service</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
|
|
|
@ -22,16 +22,16 @@ package io.druid.storage.mysql;
|
|||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Inject;
|
||||
import com.metamx.common.logger.Logger;
|
||||
import com.mysql.jdbc.exceptions.MySQLTransientException;
|
||||
import io.druid.db.MetadataStorageConnectorConfig;
|
||||
import io.druid.db.MetadataStorageTablesConfig;
|
||||
import io.druid.db.SQLMetadataConnector;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.skife.jdbi.v2.DBI;
|
||||
import org.skife.jdbi.v2.Handle;
|
||||
import org.skife.jdbi.v2.IDBI;
|
||||
import org.skife.jdbi.v2.tweak.HandleCallback;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MySQLConnector extends SQLMetadataConnector
|
||||
{
|
||||
|
@ -45,7 +45,15 @@ public class MySQLConnector extends SQLMetadataConnector
|
|||
public MySQLConnector(Supplier<MetadataStorageConnectorConfig> config, Supplier<MetadataStorageTablesConfig> dbTables)
|
||||
{
|
||||
super(config, dbTables);
|
||||
this.dbi = new DBI(getDatasource());
|
||||
|
||||
final BasicDataSource datasource = getDatasource();
|
||||
// MySQL driver is classloader isolated as part of the extension
|
||||
// so we need to help JDBC find the driver
|
||||
datasource.setDriverClassLoader(getClass().getClassLoader());
|
||||
datasource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
|
||||
this.dbi = new DBI(datasource);
|
||||
|
||||
dbi.withHandle(new HandleCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
|
@ -78,6 +86,14 @@ public class MySQLConnector extends SQLMetadataConnector
|
|||
.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTransientException(Throwable e)
|
||||
{
|
||||
return e instanceof MySQLTransientException
|
||||
|| (e instanceof SQLException && ((SQLException) e).getErrorCode() == 1317)
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void insertOrUpdate(
|
||||
final String tableName,
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -389,6 +389,11 @@
|
|||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.jpountz.lz4</groupId>
|
||||
<artifactId>lz4</artifactId>
|
||||
|
|
|
@ -50,19 +50,9 @@
|
|||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.druid</groupId>
|
||||
<artifactId>druid-indexing-hadoop</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.druid</groupId>
|
||||
<artifactId>druid-indexing-service</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.18</version>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.3-1102-jdbc41</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jdbi</groupId>
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.metamx.common.logger.Logger;
|
|||
import io.druid.db.MetadataStorageConnectorConfig;
|
||||
import io.druid.db.MetadataStorageTablesConfig;
|
||||
import io.druid.db.SQLMetadataConnector;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.skife.jdbi.v2.DBI;
|
||||
import org.skife.jdbi.v2.Handle;
|
||||
import org.skife.jdbi.v2.IDBI;
|
||||
|
@ -43,8 +44,14 @@ public class PostgreSQLConnector extends SQLMetadataConnector
|
|||
public PostgreSQLConnector(Supplier<MetadataStorageConnectorConfig> config, Supplier<MetadataStorageTablesConfig> dbTables)
|
||||
{
|
||||
super(config, dbTables);
|
||||
this.dbi = new DBI(getDatasource());
|
||||
|
||||
final BasicDataSource datasource = getDatasource();
|
||||
// PostgreSQL driver is classloader isolated as part of the extension
|
||||
// so we need to help JDBC find the driver
|
||||
datasource.setDriverClassLoader(getClass().getClassLoader());
|
||||
datasource.setDriverClassName("org.postgresql.Driver");
|
||||
|
||||
this.dbi = new DBI(datasource);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -150,11 +150,6 @@
|
|||
<groupId>com.maxmind.geoip2</groupId>
|
||||
<artifactId>geoip2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
<artifactId>derby</artifactId>
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.google.common.base.Supplier;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.metamx.common.ISE;
|
||||
import com.metamx.common.logger.Logger;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.skife.jdbi.v2.Batch;
|
||||
import org.skife.jdbi.v2.DBI;
|
||||
import org.skife.jdbi.v2.Handle;
|
||||
|
@ -31,7 +31,6 @@ import org.skife.jdbi.v2.IDBI;
|
|||
import org.skife.jdbi.v2.tweak.HandleCallback;
|
||||
import org.skife.jdbi.v2.util.ByteArrayMapper;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -77,6 +76,10 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
|
|||
|
||||
protected abstract boolean tableExists(Handle handle, final String tableName);
|
||||
|
||||
protected boolean isTransientException(Throwable e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createTable(final IDBI dbi, final String tableName, final Iterable<String> sql)
|
||||
{
|
||||
try {
|
||||
|
@ -348,7 +351,7 @@ public abstract class SQLMetadataConnector implements MetadataStorageConnector
|
|||
|
||||
public MetadataStorageConnectorConfig getConfig() { return config.get(); }
|
||||
|
||||
protected DataSource getDatasource()
|
||||
protected BasicDataSource getDatasource()
|
||||
{
|
||||
MetadataStorageConnectorConfig connectorConfig = getConfig();
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import com.google.common.base.Predicate;
|
|||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
import com.metamx.common.RetryUtils;
|
||||
import com.mysql.jdbc.exceptions.MySQLTransientException;
|
||||
import io.druid.indexing.overlord.MetadataStorageActionHandler;
|
||||
import org.skife.jdbi.v2.Handle;
|
||||
import org.skife.jdbi.v2.IDBI;
|
||||
|
@ -41,11 +40,16 @@ import java.util.concurrent.Callable;
|
|||
public class SQLMetadataStorageActionHandler implements MetadataStorageActionHandler
|
||||
{
|
||||
private final IDBI dbi;
|
||||
private final SQLMetadataConnector connector;
|
||||
|
||||
@Inject
|
||||
public SQLMetadataStorageActionHandler(final IDBI dbi)
|
||||
public SQLMetadataStorageActionHandler(
|
||||
final IDBI dbi,
|
||||
final SQLMetadataConnector connector
|
||||
)
|
||||
{
|
||||
this.dbi = dbi;
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
/* Insert stuff. @returns number of entries inserted on success */
|
||||
|
@ -332,13 +336,12 @@ public class SQLMetadataStorageActionHandler implements MetadataStorageActionHan
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean shouldRetryException(final Throwable e)
|
||||
protected boolean shouldRetryException(final Throwable e)
|
||||
{
|
||||
return e != null && (e instanceof SQLTransientException
|
||||
|| e instanceof MySQLTransientException
|
||||
|| connector.isTransientException(e)
|
||||
|| e instanceof SQLRecoverableException
|
||||
|| e instanceof UnableToObtainConnectionException
|
||||
|| (e instanceof SQLException && ((SQLException) e).getErrorCode() == 1317)
|
||||
|| (e instanceof SQLException && shouldRetryException(e.getCause()))
|
||||
|| (e instanceof DBIException && shouldRetryException(e.getCause())));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.google.inject.Binder;
|
|||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import io.druid.db.SQLMetadataConnector;
|
||||
import io.druid.db.SQLMetadataRuleManager;
|
||||
import io.druid.db.SQLMetadataRuleManagerProvider;
|
||||
import io.druid.db.SQLMetadataSegmentManager;
|
||||
|
@ -55,6 +56,9 @@ public class DerbyMetadataStorageDruidModule implements Module
|
|||
PolyBind.createChoice(
|
||||
binder, "druid.db.type", Key.get(MetadataStorageConnector.class), Key.get(DerbyConnector.class)
|
||||
);
|
||||
PolyBind.createChoice(
|
||||
binder, "druid.db.type", Key.get(SQLMetadataConnector.class), Key.get(DerbyConnector.class)
|
||||
);
|
||||
PolyBind.createChoice(
|
||||
binder, "druid.db.type", Key.get(MetadataSegmentManager.class), Key.get(SQLMetadataSegmentManager.class)
|
||||
);
|
||||
|
@ -92,6 +96,11 @@ public class DerbyMetadataStorageDruidModule implements Module
|
|||
.to(DerbyConnector.class)
|
||||
.in(LazySingleton.class);
|
||||
|
||||
PolyBind.optionBinder(binder, Key.get(SQLMetadataConnector.class))
|
||||
.addBinding("derby")
|
||||
.to(DerbyConnector.class)
|
||||
.in(LazySingleton.class);
|
||||
|
||||
PolyBind.optionBinder(binder, Key.get(MetadataSegmentManager.class))
|
||||
.addBinding("derby")
|
||||
.to(SQLMetadataSegmentManager.class)
|
||||
|
|
Loading…
Reference in New Issue