Search in sources :

Example 1 with LookupsState

use of org.apache.druid.query.lookup.LookupsState in project druid by druid-io.

the class LookupCoordinatorResource method getDetailedAllNodeStatus.

/**
 * Build 'detailed' lookup cluster status, broken down by tier, host, and then the full {@link LookupsState} with
 * complete {@link LookupExtractorFactoryMapContainer} information.
 */
private Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> getDetailedAllNodeStatus(Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts, Collection<String> tiers) {
    Map<String, Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>>> result = new HashMap<>();
    for (String tier : tiers) {
        Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> tierNodesStatus = new HashMap<>();
        result.put(tier, tierNodesStatus);
        Collection<HostAndPort> nodes = lookupCoordinatorManager.discoverNodesInTier(tier);
        for (HostAndPort node : nodes) {
            LookupsState<LookupExtractorFactoryMapContainer> lookupsState = lookupsStateOnHosts.get(node);
            if (lookupsState == null) {
                tierNodesStatus.put(node, new LookupsState<>(null, null, null));
            } else {
                tierNodesStatus.put(node, lookupsState);
            }
        }
    }
    return result;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) HashMap(java.util.HashMap) LookupsState(org.apache.druid.query.lookup.LookupsState) HashMap(java.util.HashMap) Map(java.util.Map) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer)

Example 2 with LookupsState

use of org.apache.druid.query.lookup.LookupsState in project druid by druid-io.

the class LookupCoordinatorManager method lookupManagementLoop.

@VisibleForTesting
void lookupManagementLoop() {
    // Sanity check for if we are shutting down
    if (Thread.currentThread().isInterrupted() || !lifecycleLock.awaitStarted(15, TimeUnit.SECONDS)) {
        LOG.info("Not updating lookups because process was interrupted or not finished starting yet.");
        return;
    }
    final Map<String, Map<String, LookupExtractorFactoryMapContainer>> allLookupTiers = lookupMapConfigRef.get();
    if (allLookupTiers == null) {
        LOG.info("Not updating lookups because no data exists");
        return;
    }
    LOG.debug("Starting lookup sync for on all nodes.");
    try {
        List<ListenableFuture<Map.Entry>> futures = new ArrayList<>();
        Set<String> discoveredLookupTiers = lookupNodeDiscovery.getAllTiers();
        // Check and Log warnings about lookups configured by user in DB but no nodes discovered to load those.
        for (String tierInDB : allLookupTiers.keySet()) {
            if (!discoveredLookupTiers.contains(tierInDB) && !allLookupTiers.getOrDefault(tierInDB, ImmutableMap.of()).isEmpty()) {
                LOG.warn("Found lookups for tier [%s] in DB, but no nodes discovered for it", tierInDB);
            }
        }
        for (String tier : discoveredLookupTiers) {
            LOG.debug("Starting lookup mgmt for tier [%s].", tier);
            final Map<String, LookupExtractorFactoryMapContainer> tierLookups = allLookupTiers.getOrDefault(tier, ImmutableMap.of());
            for (final HostAndPortWithScheme node : lookupNodeDiscovery.getNodesInTier(tier)) {
                LOG.debug("Starting lookup mgmt for tier [%s] and host [%s:%s:%s].", tier, node.getScheme(), node.getHostText(), node.getPort());
                futures.add(executorService.submit(() -> {
                    try {
                        return new AbstractMap.SimpleImmutableEntry<>(node.getHostAndPort(), doLookupManagementOnNode(node, tierLookups));
                    } catch (InterruptedException ex) {
                        LOG.warn(ex, "lookup management on node [%s:%s:%s] interrupted.", node.getScheme(), node.getHostText(), node.getPort());
                        return null;
                    } catch (Exception ex) {
                        LOG.makeAlert(ex, "Failed to finish lookup management on node [%s:%s:%s]", node.getScheme(), node.getHostText(), node.getPort()).emit();
                        return null;
                    }
                }));
            }
        }
        final ListenableFuture<List<Map.Entry>> allFuture = Futures.allAsList(futures);
        try {
            ImmutableMap.Builder<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> stateBuilder = ImmutableMap.builder();
            allFuture.get(lookupCoordinatorManagerConfig.getAllHostTimeout().getMillis(), TimeUnit.MILLISECONDS).stream().filter(Objects::nonNull).forEach(stateBuilder::put);
            knownOldState.set(stateBuilder.build());
        } catch (InterruptedException ex) {
            allFuture.cancel(true);
            Thread.currentThread().interrupt();
            throw ex;
        } catch (Exception ex) {
            allFuture.cancel(true);
            throw ex;
        }
    } catch (Exception ex) {
        LOG.makeAlert(ex, "Failed to finish lookup management loop.").emit();
    }
    LOG.debug("Finished lookup sync for on all nodes.");
}
Also used : ArrayList(java.util.ArrayList) HostAndPortWithScheme(org.apache.druid.server.http.HostAndPortWithScheme) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap) HostAndPort(com.google.common.net.HostAndPort) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LookupsState(org.apache.druid.query.lookup.LookupsState) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with LookupsState

use of org.apache.druid.query.lookup.LookupsState in project druid by druid-io.

the class LookupCoordinatorResource method getSimpleAllNodeStatus.

/**
 * Build 'simple' lookup cluster status, broken down by tier, host, and then the {@link LookupsState} with
 * the lookup name and version ({@link LookupExtractorFactoryMapContainer#version})
 */
private Map<String, Map<HostAndPort, LookupsState<String>>> getSimpleAllNodeStatus(Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts, Collection<String> tiers) {
    Map<String, Map<HostAndPort, LookupsState<String>>> results = new HashMap<>();
    for (String tier : tiers) {
        Map<HostAndPort, LookupsState<String>> tierNodesStatus = new HashMap<>();
        results.put(tier, tierNodesStatus);
        Collection<HostAndPort> nodes = lookupCoordinatorManager.discoverNodesInTier(tier);
        for (HostAndPort node : nodes) {
            LookupsState<LookupExtractorFactoryMapContainer> lookupsState = lookupsStateOnHosts.get(node);
            if (lookupsState == null) {
                tierNodesStatus.put(node, new LookupsState<>(null, null, null));
            } else {
                Map<String, String> current = lookupsState.getCurrent().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getVersion()));
                Map<String, String> toLoad = lookupsState.getToLoad().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getVersion()));
                tierNodesStatus.put(node, new LookupsState<>(current, toLoad, lookupsState.getToDrop()));
            }
        }
    }
    return results;
}
Also used : Logger(org.apache.druid.java.util.common.logger.Logger) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) AuditInfo(org.apache.druid.audit.AuditInfo) PathParam(javax.ws.rs.PathParam) LookupCoordinatorManager(org.apache.druid.server.lookup.cache.LookupCoordinatorManager) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Inject(com.google.inject.Inject) Smile(org.apache.druid.guice.annotations.Smile) Path(javax.ws.rs.Path) LookupsState(org.apache.druid.query.lookup.LookupsState) HashMap(java.util.HashMap) ResourceFilters(com.sun.jersey.spi.container.ResourceFilters) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) ServletResourceUtils(org.apache.druid.common.utils.ServletResourceUtils) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IAE(org.apache.druid.java.util.common.IAE) Nullable(javax.annotation.Nullable) DELETE(javax.ws.rs.DELETE) SmileMediaTypes(com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) RE(org.apache.druid.java.util.common.RE) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigResourceFilter(org.apache.druid.server.http.security.ConfigResourceFilter) Set(java.util.Set) IOException(java.io.IOException) Json(org.apache.druid.guice.annotations.Json) HostAndPort(com.google.common.net.HostAndPort) Collectors(java.util.stream.Collectors) AuditManager(org.apache.druid.audit.AuditManager) Objects(java.util.Objects) List(java.util.List) Response(javax.ws.rs.core.Response) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) InputStream(java.io.InputStream) HashMap(java.util.HashMap) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) HostAndPort(com.google.common.net.HostAndPort) LookupsState(org.apache.druid.query.lookup.LookupsState) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with LookupsState

use of org.apache.druid.query.lookup.LookupsState in project druid by druid-io.

the class LookupCoordinatorResource method getAllNodesStatus.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/nodeStatus")
public Response getAllNodesStatus(@QueryParam("discover") boolean discover, @QueryParam("detailed") @Nullable Boolean detailed) {
    boolean full = detailed == null || detailed;
    try {
        Collection<String> tiers;
        if (discover) {
            tiers = lookupCoordinatorManager.discoverTiers();
        } else {
            Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = lookupCoordinatorManager.getKnownLookups();
            if (configuredLookups == null) {
                return Response.status(Response.Status.NOT_FOUND).entity(ServletResourceUtils.jsonize("No lookups configured.")).build();
            }
            tiers = configuredLookups.keySet();
        }
        Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
        final Map result;
        if (full) {
            result = getDetailedAllNodeStatus(lookupsStateOnHosts, tiers);
        } else {
            // lookups to load per host by version
            result = getSimpleAllNodeStatus(lookupsStateOnHosts, tiers);
        }
        return Response.ok(result).build();
    } catch (Exception ex) {
        LOG.error(ex, "Error getting node status.");
        return Response.serverError().entity(ServletResourceUtils.sanitizeException(ex)).build();
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) LookupsState(org.apache.druid.query.lookup.LookupsState) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with LookupsState

use of org.apache.druid.query.lookup.LookupsState in project druid by druid-io.

the class LookupCoordinatorResource method getNodesStatusInTier.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/nodeStatus/{tier}")
public Response getNodesStatusInTier(@PathParam("tier") String tier) {
    try {
        Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> lookupsStateOnHosts = lookupCoordinatorManager.getLastKnownLookupsStateOnNodes();
        Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> tierNodesStatus = new HashMap<>();
        Collection<HostAndPort> nodes = lookupCoordinatorManager.discoverNodesInTier(tier);
        for (HostAndPort node : nodes) {
            LookupsState<LookupExtractorFactoryMapContainer> lookupsState = lookupsStateOnHosts.get(node);
            if (lookupsState == null) {
                tierNodesStatus.put(node, new LookupsState<>(null, null, null));
            } else {
                tierNodesStatus.put(node, lookupsState);
            }
        }
        return Response.ok(tierNodesStatus).build();
    } catch (Exception ex) {
        LOG.error(ex, "Error getting node status for tier [%s].", tier);
        return Response.serverError().entity(ServletResourceUtils.sanitizeException(ex)).build();
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) HashMap(java.util.HashMap) LookupsState(org.apache.druid.query.lookup.LookupsState) IOException(java.io.IOException) LookupExtractorFactoryMapContainer(org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

LookupsState (org.apache.druid.query.lookup.LookupsState)7 HostAndPort (com.google.common.net.HostAndPort)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 IOException (java.io.IOException)4 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 LookupExtractorFactoryMapContainer (org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Response (javax.ws.rs.core.Response)2 LookupCoordinatorManager (org.apache.druid.server.lookup.cache.LookupCoordinatorManager)2 Test (org.junit.Test)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1