remove ServerDiscoverySelector from DruidLeaderClient (#9481)

This commit is contained in:
Himanshu 2020-03-09 12:13:59 -07:00 committed by GitHub
parent f456d2fcf8
commit 072bbe210f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 71 deletions

View File

@ -22,8 +22,6 @@ package org.apache.druid.discovery;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import org.apache.druid.client.selector.DiscoverySelector;
import org.apache.druid.client.selector.Server;
import org.apache.druid.concurrent.LifecycleLock; import org.apache.druid.concurrent.LifecycleLock;
import org.apache.druid.java.util.common.IOE; import org.apache.druid.java.util.common.IOE;
import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.ISE;
@ -72,9 +70,6 @@ public class DruidLeaderClient
private final String leaderRequestPath; private final String leaderRequestPath;
//Note: This is kept for back compatibility with pre 0.11.0 releases and should be removed in future.
private final DiscoverySelector<Server> serverDiscoverySelector;
private LifecycleLock lifecycleLock = new LifecycleLock(); private LifecycleLock lifecycleLock = new LifecycleLock();
private DruidNodeDiscovery druidNodeDiscovery; private DruidNodeDiscovery druidNodeDiscovery;
private AtomicReference<String> currentKnownLeader = new AtomicReference<>(); private AtomicReference<String> currentKnownLeader = new AtomicReference<>();
@ -83,15 +78,13 @@ public class DruidLeaderClient
HttpClient httpClient, HttpClient httpClient,
DruidNodeDiscoveryProvider druidNodeDiscoveryProvider, DruidNodeDiscoveryProvider druidNodeDiscoveryProvider,
NodeRole nodeRoleToWatch, NodeRole nodeRoleToWatch,
String leaderRequestPath, String leaderRequestPath
DiscoverySelector<Server> serverDiscoverySelector
) )
{ {
this.httpClient = httpClient; this.httpClient = httpClient;
this.druidNodeDiscoveryProvider = druidNodeDiscoveryProvider; this.druidNodeDiscoveryProvider = druidNodeDiscoveryProvider;
this.nodeRoleToWatch = nodeRoleToWatch; this.nodeRoleToWatch = nodeRoleToWatch;
this.leaderRequestPath = leaderRequestPath; this.leaderRequestPath = leaderRequestPath;
this.serverDiscoverySelector = serverDiscoverySelector;
} }
@LifecycleStart @LifecycleStart
@ -303,16 +296,6 @@ public class DruidLeaderClient
@Nullable @Nullable
private String pickOneHost() private String pickOneHost()
{ {
Server server = serverDiscoverySelector.pick();
if (server != null) {
return StringUtils.format(
"%s://%s:%s",
server.getScheme(),
server.getAddress(),
server.getPort()
);
}
Iterator<DiscoveryDruidNode> iter = druidNodeDiscovery.getAllNodes().iterator(); Iterator<DiscoveryDruidNode> iter = druidNodeDiscovery.getAllNodes().iterator();
if (iter.hasNext()) { if (iter.hasNext()) {
DiscoveryDruidNode node = iter.next(); DiscoveryDruidNode node = iter.next();

View File

@ -24,8 +24,6 @@ import com.google.inject.Module;
import com.google.inject.Provides; import com.google.inject.Provides;
import org.apache.druid.client.coordinator.Coordinator; import org.apache.druid.client.coordinator.Coordinator;
import org.apache.druid.client.coordinator.CoordinatorSelectorConfig; import org.apache.druid.client.coordinator.CoordinatorSelectorConfig;
import org.apache.druid.curator.discovery.ServerDiscoveryFactory;
import org.apache.druid.curator.discovery.ServerDiscoverySelector;
import org.apache.druid.discovery.DruidLeaderClient; import org.apache.druid.discovery.DruidLeaderClient;
import org.apache.druid.discovery.DruidNodeDiscoveryProvider; import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
import org.apache.druid.discovery.NodeRole; import org.apache.druid.discovery.NodeRole;
@ -42,32 +40,19 @@ public class CoordinatorDiscoveryModule implements Module
JsonConfigProvider.bind(binder, "druid.selectors.coordinator", CoordinatorSelectorConfig.class); JsonConfigProvider.bind(binder, "druid.selectors.coordinator", CoordinatorSelectorConfig.class);
} }
@Provides
@Coordinator
@ManageLifecycle
public ServerDiscoverySelector getServiceProvider(
CoordinatorSelectorConfig config,
ServerDiscoveryFactory serverDiscoveryFactory
)
{
return serverDiscoveryFactory.createSelector(config.getServiceName());
}
@Provides @Provides
@Coordinator @Coordinator
@ManageLifecycle @ManageLifecycle
public DruidLeaderClient getLeaderHttpClient( public DruidLeaderClient getLeaderHttpClient(
@EscalatedGlobal HttpClient httpClient, @EscalatedGlobal HttpClient httpClient,
DruidNodeDiscoveryProvider druidNodeDiscoveryProvider, DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
@Coordinator ServerDiscoverySelector serverDiscoverySelector
) )
{ {
return new DruidLeaderClient( return new DruidLeaderClient(
httpClient, httpClient,
druidNodeDiscoveryProvider, druidNodeDiscoveryProvider,
NodeRole.COORDINATOR, NodeRole.COORDINATOR,
"/druid/coordinator/v1/leader", "/druid/coordinator/v1/leader"
serverDiscoverySelector
); );
} }
} }

View File

@ -24,8 +24,6 @@ import com.google.inject.Module;
import com.google.inject.Provides; import com.google.inject.Provides;
import org.apache.druid.client.indexing.IndexingService; import org.apache.druid.client.indexing.IndexingService;
import org.apache.druid.client.indexing.IndexingServiceSelectorConfig; import org.apache.druid.client.indexing.IndexingServiceSelectorConfig;
import org.apache.druid.curator.discovery.ServerDiscoveryFactory;
import org.apache.druid.curator.discovery.ServerDiscoverySelector;
import org.apache.druid.discovery.DruidLeaderClient; import org.apache.druid.discovery.DruidLeaderClient;
import org.apache.druid.discovery.DruidNodeDiscoveryProvider; import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
import org.apache.druid.discovery.NodeRole; import org.apache.druid.discovery.NodeRole;
@ -42,32 +40,19 @@ public class IndexingServiceDiscoveryModule implements Module
JsonConfigProvider.bind(binder, "druid.selectors.indexing", IndexingServiceSelectorConfig.class); JsonConfigProvider.bind(binder, "druid.selectors.indexing", IndexingServiceSelectorConfig.class);
} }
@Provides
@IndexingService
@ManageLifecycle
public ServerDiscoverySelector getServiceProvider(
IndexingServiceSelectorConfig config,
ServerDiscoveryFactory serverDiscoveryFactory
)
{
return serverDiscoveryFactory.createSelector(config.getServiceName());
}
@Provides @Provides
@IndexingService @IndexingService
@ManageLifecycle @ManageLifecycle
public DruidLeaderClient getLeaderHttpClient( public DruidLeaderClient getLeaderHttpClient(
@EscalatedGlobal HttpClient httpClient, @EscalatedGlobal HttpClient httpClient,
DruidNodeDiscoveryProvider druidNodeDiscoveryProvider, DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
@IndexingService ServerDiscoverySelector serverDiscoverySelector
) )
{ {
return new DruidLeaderClient( return new DruidLeaderClient(
httpClient, httpClient,
druidNodeDiscoveryProvider, druidNodeDiscoveryProvider,
NodeRole.OVERLORD, NodeRole.OVERLORD,
"/druid/indexer/v1/leader", "/druid/indexer/v1/leader"
serverDiscoverySelector
); );
} }
} }

View File

@ -29,7 +29,6 @@ import com.google.inject.Module;
import com.google.inject.name.Named; import com.google.inject.name.Named;
import com.google.inject.name.Names; import com.google.inject.name.Names;
import com.google.inject.servlet.GuiceFilter; import com.google.inject.servlet.GuiceFilter;
import org.apache.druid.curator.discovery.ServerDiscoverySelector;
import org.apache.druid.guice.GuiceInjectors; import org.apache.druid.guice.GuiceInjectors;
import org.apache.druid.guice.Jerseys; import org.apache.druid.guice.Jerseys;
import org.apache.druid.guice.JsonConfigProvider; import org.apache.druid.guice.JsonConfigProvider;
@ -123,8 +122,7 @@ public class DruidLeaderClientTest extends BaseJettyTest
httpClient, httpClient,
druidNodeDiscoveryProvider, druidNodeDiscoveryProvider,
NodeRole.PEON, NodeRole.PEON,
"/simple/leader", "/simple/leader"
EasyMock.createNiceMock(ServerDiscoverySelector.class)
); );
druidLeaderClient.start(); druidLeaderClient.start();
@ -148,8 +146,7 @@ public class DruidLeaderClientTest extends BaseJettyTest
httpClient, httpClient,
druidNodeDiscoveryProvider, druidNodeDiscoveryProvider,
NodeRole.PEON, NodeRole.PEON,
"/simple/leader", "/simple/leader"
EasyMock.createNiceMock(ServerDiscoverySelector.class)
); );
druidLeaderClient.start(); druidLeaderClient.start();
@ -175,8 +172,7 @@ public class DruidLeaderClientTest extends BaseJettyTest
httpClient, httpClient,
druidNodeDiscoveryProvider, druidNodeDiscoveryProvider,
NodeRole.PEON, NodeRole.PEON,
"/simple/leader", "/simple/leader"
EasyMock.createNiceMock(ServerDiscoverySelector.class)
); );
druidLeaderClient.start(); druidLeaderClient.start();
@ -188,9 +184,6 @@ public class DruidLeaderClientTest extends BaseJettyTest
@Test @Test
public void testServerFailureAndRedirect() throws Exception public void testServerFailureAndRedirect() throws Exception
{ {
ServerDiscoverySelector serverDiscoverySelector = EasyMock.createMock(ServerDiscoverySelector.class);
EasyMock.expect(serverDiscoverySelector.pick()).andReturn(null).anyTimes();
DruidNodeDiscovery druidNodeDiscovery = EasyMock.createMock(DruidNodeDiscovery.class); DruidNodeDiscovery druidNodeDiscovery = EasyMock.createMock(DruidNodeDiscovery.class);
DiscoveryDruidNode dummyNode = new DiscoveryDruidNode( DiscoveryDruidNode dummyNode = new DiscoveryDruidNode(
new DruidNode("test", "dummyhost", false, 64231, null, true, false), new DruidNode("test", "dummyhost", false, 64231, null, true, false),
@ -203,14 +196,13 @@ public class DruidLeaderClientTest extends BaseJettyTest
DruidNodeDiscoveryProvider druidNodeDiscoveryProvider = EasyMock.createMock(DruidNodeDiscoveryProvider.class); DruidNodeDiscoveryProvider druidNodeDiscoveryProvider = EasyMock.createMock(DruidNodeDiscoveryProvider.class);
EasyMock.expect(druidNodeDiscoveryProvider.getForNodeRole(NodeRole.PEON)).andReturn(druidNodeDiscovery).anyTimes(); EasyMock.expect(druidNodeDiscoveryProvider.getForNodeRole(NodeRole.PEON)).andReturn(druidNodeDiscovery).anyTimes();
EasyMock.replay(serverDiscoverySelector, druidNodeDiscovery, druidNodeDiscoveryProvider); EasyMock.replay(druidNodeDiscovery, druidNodeDiscoveryProvider);
DruidLeaderClient druidLeaderClient = new DruidLeaderClient( DruidLeaderClient druidLeaderClient = new DruidLeaderClient(
httpClient, httpClient,
druidNodeDiscoveryProvider, druidNodeDiscoveryProvider,
NodeRole.PEON, NodeRole.PEON,
"/simple/leader", "/simple/leader"
serverDiscoverySelector
); );
druidLeaderClient.start(); druidLeaderClient.start();
@ -236,8 +228,7 @@ public class DruidLeaderClientTest extends BaseJettyTest
httpClient, httpClient,
druidNodeDiscoveryProvider, druidNodeDiscoveryProvider,
NodeRole.PEON, NodeRole.PEON,
"/simple/leader", "/simple/leader"
EasyMock.createNiceMock(ServerDiscoverySelector.class)
); );
druidLeaderClient.start(); druidLeaderClient.start();

View File

@ -879,10 +879,7 @@ public class CalciteTests
new FakeHttpClient(), new FakeHttpClient(),
provider, provider,
NodeRole.COORDINATOR, NodeRole.COORDINATOR,
"/simple/leader", "/simple/leader"
() -> {
throw new UnsupportedOperationException();
}
); );
return new SystemSchema( return new SystemSchema(