mirror of https://github.com/apache/druid.git
make derby instance only on coordinator
This commit is contained in:
parent
6188315293
commit
98d05e63bf
|
@ -29,7 +29,7 @@ public class MetadataStorageConnectorConfig
|
|||
private boolean createTables = true;
|
||||
|
||||
@JsonProperty
|
||||
private String connectURI = null;
|
||||
private String connectURI = "jdbc:derby://localhost:1527/druid;create=true";
|
||||
|
||||
@JsonProperty
|
||||
private String user = null;
|
||||
|
|
|
@ -21,11 +21,11 @@ package io.druid.guice;
|
|||
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import io.druid.metadata.DerbyConnector;
|
||||
import io.druid.metadata.DerbyMetadataStorage;
|
||||
import io.druid.metadata.MetadataStorage;
|
||||
import io.druid.metadata.MetadataStorageConnector;
|
||||
import io.druid.metadata.SQLMetadataConnector;
|
||||
import org.skife.jdbi.v2.IDBI;
|
||||
|
||||
public class DerbyMetadataStorageDruidModule extends SQLMetadataStorageDruidModule
|
||||
{
|
||||
|
@ -42,6 +42,11 @@ public class DerbyMetadataStorageDruidModule extends SQLMetadataStorageDruidModu
|
|||
createBindingChoices(binder, TYPE);
|
||||
super.configure(binder);
|
||||
|
||||
PolyBind.optionBinder(binder, Key.get(MetadataStorage.class))
|
||||
.addBinding(TYPE)
|
||||
.to(DerbyMetadataStorage.class)
|
||||
.in(LazySingleton.class);
|
||||
|
||||
PolyBind.optionBinder(binder, Key.get(MetadataStorageConnector.class))
|
||||
.addBinding(TYPE)
|
||||
.to(DerbyConnector.class)
|
||||
|
|
|
@ -21,12 +21,12 @@ package io.druid.guice;
|
|||
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Module;
|
||||
import io.druid.metadata.MetadataStorageConnectorConfig;
|
||||
import io.druid.metadata.MetadataRuleManagerConfig;
|
||||
import io.druid.metadata.MetadataSegmentManagerConfig;
|
||||
import io.druid.metadata.MetadataStorageConnectorConfig;
|
||||
import io.druid.metadata.MetadataStorageTablesConfig;
|
||||
|
||||
public class MetadataDbConfigModule implements Module
|
||||
public class MetadataConfigModule implements Module
|
||||
{
|
||||
@Override
|
||||
public void configure(Binder binder)
|
|
@ -25,6 +25,7 @@ import com.google.inject.Module;
|
|||
import io.druid.indexer.MetadataStorageUpdaterJobHandler;
|
||||
import io.druid.indexer.SQLMetadataStorageUpdaterJobHandler;
|
||||
import io.druid.indexing.overlord.IndexerMetadataStorageCoordinator;
|
||||
import io.druid.metadata.MetadataStorage;
|
||||
import io.druid.metadata.MetadataStorageActionHandlerFactory;
|
||||
import io.druid.metadata.IndexerSQLMetadataStorageCoordinator;
|
||||
import io.druid.metadata.MetadataRuleManager;
|
||||
|
@ -62,6 +63,9 @@ public class SQLMetadataStorageDruidModule implements Module
|
|||
PolyBind.createChoiceWithDefault(
|
||||
binder, PROPERTY, Key.get(MetadataStorageConnector.class), null, defaultPropertyValue
|
||||
);
|
||||
PolyBind.createChoiceWithDefault(
|
||||
binder, PROPERTY, Key.get(MetadataStorage.class), Key.get(MetadataStorage.class), defaultPropertyValue
|
||||
);
|
||||
PolyBind.createChoiceWithDefault(
|
||||
binder, PROPERTY, Key.get(SQLMetadataConnector.class), null, defaultPropertyValue
|
||||
);
|
||||
|
|
|
@ -45,7 +45,7 @@ import io.druid.guice.IndexingServiceDiscoveryModule;
|
|||
import io.druid.guice.JacksonConfigManagerModule;
|
||||
import io.druid.guice.LifecycleModule;
|
||||
import io.druid.guice.LocalDataStorageDruidModule;
|
||||
import io.druid.guice.MetadataDbConfigModule;
|
||||
import io.druid.guice.MetadataConfigModule;
|
||||
import io.druid.guice.ParsersModule;
|
||||
import io.druid.guice.QueryRunnerFactoryModule;
|
||||
import io.druid.guice.QueryableModule;
|
||||
|
@ -333,7 +333,7 @@ public class Initialization
|
|||
new QueryRunnerFactoryModule(),
|
||||
new DiscoveryModule(),
|
||||
new ServerViewModule(),
|
||||
new MetadataDbConfigModule(),
|
||||
new MetadataConfigModule(),
|
||||
new DerbyMetadataStorageDruidModule(),
|
||||
new JacksonConfigManagerModule(),
|
||||
new IndexingServiceDiscoveryModule(),
|
||||
|
|
|
@ -19,15 +19,11 @@
|
|||
|
||||
package io.druid.metadata;
|
||||
|
||||
import com.google.api.client.repackaged.com.google.common.base.Throwables;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.derby.drda.NetworkServerControl;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.skife.jdbi.v2.DBI;
|
||||
import org.skife.jdbi.v2.Handle;
|
||||
import org.skife.jdbi.v2.tweak.ConnectionFactory;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class DerbyConnector extends SQLMetadataConnector
|
||||
{
|
||||
|
@ -37,10 +33,20 @@ public class DerbyConnector extends SQLMetadataConnector
|
|||
@Inject
|
||||
public DerbyConnector(Supplier<MetadataStorageConnectorConfig> config, Supplier<MetadataStorageTablesConfig> dbTables)
|
||||
{
|
||||
this(config, dbTables, new DBI(getConnectionFactory("druidDerbyDb")));
|
||||
super(config, dbTables);
|
||||
|
||||
final BasicDataSource datasource = getDatasource();
|
||||
datasource.setDriverClassLoader(getClass().getClassLoader());
|
||||
datasource.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
|
||||
|
||||
this.dbi = new DBI(datasource);
|
||||
}
|
||||
|
||||
public DerbyConnector(Supplier<MetadataStorageConnectorConfig> config, Supplier<MetadataStorageTablesConfig> dbTables, DBI dbi)
|
||||
public DerbyConnector(
|
||||
Supplier<MetadataStorageConnectorConfig> config,
|
||||
Supplier<MetadataStorageTablesConfig> dbTables,
|
||||
DBI dbi
|
||||
)
|
||||
{
|
||||
super(config, dbTables);
|
||||
this.dbi = dbi;
|
||||
|
@ -63,15 +69,4 @@ public class DerbyConnector extends SQLMetadataConnector
|
|||
|
||||
@Override
|
||||
public DBI getDBI() { return dbi; }
|
||||
|
||||
private static ConnectionFactory getConnectionFactory(String dbName)
|
||||
{
|
||||
try {
|
||||
NetworkServerControl server = new NetworkServerControl(InetAddress.getByName("localhost"),1527);
|
||||
server.start(null);
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
return new DerbyConnectionFactory(dbName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Druid - a distributed column store.
|
||||
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package io.druid.metadata;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.metamx.common.lifecycle.LifecycleStart;
|
||||
import com.metamx.common.lifecycle.LifecycleStop;
|
||||
import org.apache.derby.drda.NetworkServerControl;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class DerbyMetadataStorage extends MetadataStorage
|
||||
{
|
||||
private final NetworkServerControl server;
|
||||
|
||||
public DerbyMetadataStorage()
|
||||
{
|
||||
try {
|
||||
this.server = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@LifecycleStart
|
||||
public void start()
|
||||
{
|
||||
try {
|
||||
server.start(null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@LifecycleStop
|
||||
public void stop()
|
||||
{
|
||||
try {
|
||||
server.shutdown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package io.druid.metadata;
|
||||
|
||||
import com.metamx.common.lifecycle.LifecycleStart;
|
||||
import com.metamx.common.lifecycle.LifecycleStop;
|
||||
|
||||
/**
|
||||
*/
|
||||
public abstract class MetadataStorage
|
||||
{
|
||||
@LifecycleStart
|
||||
public void start()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@LifecycleStop
|
||||
public void stop()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
|
@ -29,18 +29,19 @@ import com.metamx.common.concurrent.ScheduledExecutorFactory;
|
|||
import com.metamx.common.logger.Logger;
|
||||
import io.airlift.command.Command;
|
||||
import io.druid.client.indexing.IndexingServiceClient;
|
||||
import io.druid.metadata.MetadataRuleManager;
|
||||
import io.druid.metadata.MetadataRuleManagerConfig;
|
||||
import io.druid.metadata.MetadataRuleManagerProvider;
|
||||
import io.druid.metadata.MetadataSegmentManager;
|
||||
import io.druid.metadata.MetadataSegmentManagerConfig;
|
||||
import io.druid.metadata.MetadataSegmentManagerProvider;
|
||||
import io.druid.guice.ConfigProvider;
|
||||
import io.druid.guice.Jerseys;
|
||||
import io.druid.guice.JsonConfigProvider;
|
||||
import io.druid.guice.LazySingleton;
|
||||
import io.druid.guice.LifecycleModule;
|
||||
import io.druid.guice.ManageLifecycle;
|
||||
import io.druid.metadata.MetadataRuleManager;
|
||||
import io.druid.metadata.MetadataRuleManagerConfig;
|
||||
import io.druid.metadata.MetadataRuleManagerProvider;
|
||||
import io.druid.metadata.MetadataSegmentManager;
|
||||
import io.druid.metadata.MetadataSegmentManagerConfig;
|
||||
import io.druid.metadata.MetadataSegmentManagerProvider;
|
||||
import io.druid.metadata.MetadataStorage;
|
||||
import io.druid.server.coordinator.DruidCoordinator;
|
||||
import io.druid.server.coordinator.DruidCoordinatorConfig;
|
||||
import io.druid.server.coordinator.LoadQueueTaskMaster;
|
||||
|
@ -49,9 +50,9 @@ import io.druid.server.http.BackwardsCompatibleInfoResource;
|
|||
import io.druid.server.http.CoordinatorDynamicConfigsResource;
|
||||
import io.druid.server.http.CoordinatorRedirectInfo;
|
||||
import io.druid.server.http.CoordinatorResource;
|
||||
import io.druid.server.http.MetadataResource;
|
||||
import io.druid.server.http.DatasourcesResource;
|
||||
import io.druid.server.http.InfoResource;
|
||||
import io.druid.server.http.MetadataResource;
|
||||
import io.druid.server.http.RedirectFilter;
|
||||
import io.druid.server.http.RedirectInfo;
|
||||
import io.druid.server.http.RulesResource;
|
||||
|
@ -93,6 +94,8 @@ public class CliCoordinator extends ServerRunnable
|
|||
|
||||
ConfigProvider.bind(binder, DruidCoordinatorConfig.class);
|
||||
|
||||
binder.bind(MetadataStorage.class).in(ManageLifecycle.class);
|
||||
|
||||
JsonConfigProvider.bind(binder, "druid.manager.segments", MetadataSegmentManagerConfig.class);
|
||||
JsonConfigProvider.bind(binder, "druid.manager.rules", MetadataRuleManagerConfig.class);
|
||||
|
||||
|
|
Loading…
Reference in New Issue