use of org.apache.druid.java.util.common.lifecycle.LifecycleStart in project druid by druid-io.
the class FileRequestLogger method start.
@LifecycleStart
@Override
public void start() {
try {
FileUtils.mkdirp(baseDir);
MutableDateTime mutableDateTime = DateTimes.nowUtc().toMutableDateTime(ISOChronology.getInstanceUTC());
mutableDateTime.setMillisOfDay(0);
synchronized (lock) {
currentDay = mutableDateTime.toDateTime(ISOChronology.getInstanceUTC());
fileWriter = getFileWriter();
}
long nextDay = currentDay.plusDays(1).getMillis();
Duration initialDelay = new Duration(nextDay - System.currentTimeMillis());
ScheduledExecutors.scheduleWithFixedDelay(exec, initialDelay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() {
@Override
public ScheduledExecutors.Signal call() {
try {
synchronized (lock) {
currentDay = currentDay.plusDays(1);
CloseableUtils.closeAndSuppressExceptions(fileWriter, e -> log.warn("Could not close log file for %s. Creating new log file anyway.", currentDay));
fileWriter = getFileWriter();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return ScheduledExecutors.Signal.REPEAT;
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStart in project druid by druid-io.
the class ZkCoordinator method start.
@LifecycleStart
public void start() throws IOException {
synchronized (lock) {
if (started) {
return;
}
log.info("Starting zkCoordinator for server[%s]", me.getName());
final String loadQueueLocation = ZKPaths.makePath(zkPaths.getLoadQueuePath(), me.getName());
final String servedSegmentsLocation = ZKPaths.makePath(zkPaths.getServedSegmentsPath(), me.getName());
final String liveSegmentsLocation = ZKPaths.makePath(zkPaths.getLiveSegmentsPath(), me.getName());
loadQueueCache = new PathChildrenCache(curator, loadQueueLocation, true, true, Execs.singleThreaded("ZkCoordinator"));
try {
curator.newNamespaceAwareEnsurePath(loadQueueLocation).ensure(curator.getZookeeperClient());
curator.newNamespaceAwareEnsurePath(servedSegmentsLocation).ensure(curator.getZookeeperClient());
curator.newNamespaceAwareEnsurePath(liveSegmentsLocation).ensure(curator.getZookeeperClient());
loadQueueCache.getListenable().addListener((client, event) -> {
final ChildData child = event.getData();
switch(event.getType()) {
case CHILD_ADDED:
childAdded(child);
break;
case CHILD_REMOVED:
log.info("zNode[%s] was removed", event.getData().getPath());
break;
default:
log.info("Ignoring event[%s]", event);
}
});
loadQueueCache.start();
} catch (Exception e) {
Throwables.propagateIfPossible(e, IOException.class);
throw new RuntimeException(e);
}
started = true;
}
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStart in project druid by druid-io.
the class TieredBrokerHostSelector method start.
@LifecycleStart
public void start() {
synchronized (lock) {
if (started) {
return;
}
for (Map.Entry<String, String> entry : tierConfig.getTierToBrokerMap().entrySet()) {
servers.put(entry.getValue(), new NodesHolder());
}
DruidNodeDiscovery druidNodeDiscovery = druidNodeDiscoveryProvider.getForNodeRole(NodeRole.BROKER);
druidNodeDiscovery.registerListener(new DruidNodeDiscovery.Listener() {
@Override
public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach((node) -> {
NodesHolder nodesHolder = servers.get(node.getDruidNode().getServiceName());
if (nodesHolder != null) {
nodesHolder.add(node.getDruidNode().getHostAndPortToUse(), TO_SERVER.apply(node));
}
});
}
@Override
public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach((node) -> {
NodesHolder nodesHolder = servers.get(node.getDruidNode().getServiceName());
if (nodesHolder != null) {
nodesHolder.remove(node.getDruidNode().getHostAndPortToUse());
}
});
}
});
started = true;
}
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStart in project druid by druid-io.
the class HttpServerInventoryView method start.
@LifecycleStart
public void start() {
synchronized (lifecycleLock) {
if (!lifecycleLock.canStart()) {
throw new ISE("can't start.");
}
log.info("Starting %s.", execNamePrefix);
try {
executor = ScheduledExecutors.fixed(config.getNumThreads(), execNamePrefix + "-%s");
DruidNodeDiscovery druidNodeDiscovery = druidNodeDiscoveryProvider.getForService(DataNodeService.DISCOVERY_SERVICE_KEY);
druidNodeDiscovery.registerListener(new DruidNodeDiscovery.Listener() {
private final AtomicBoolean initialized = new AtomicBoolean(false);
@Override
public void nodesAdded(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach(node -> serverAdded(toDruidServer(node)));
}
@Override
public void nodesRemoved(Collection<DiscoveryDruidNode> nodes) {
nodes.forEach(node -> serverRemoved(toDruidServer(node)));
}
@Override
public void nodeViewInitialized() {
if (!initialized.getAndSet(true)) {
executor.execute(HttpServerInventoryView.this::serverInventoryInitialized);
}
}
private DruidServer toDruidServer(DiscoveryDruidNode node) {
return new DruidServer(node.getDruidNode().getHostAndPortToUse(), node.getDruidNode().getHostAndPort(), node.getDruidNode().getHostAndTlsPort(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getMaxSize(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getServerType(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getTier(), ((DataNodeService) node.getServices().get(DataNodeService.DISCOVERY_SERVICE_KEY)).getPriority());
}
});
scheduleSyncMonitoring();
lifecycleLock.started();
} finally {
lifecycleLock.exitStart();
}
log.info("Started %s.", execNamePrefix);
}
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStart in project druid by druid-io.
the class DerivativeDataSourceManager method start.
@LifecycleStart
public void start() {
log.info("starting derivatives manager.");
synchronized (lock) {
if (started) {
return;
}
exec = MoreExecutors.listeningDecorator(Execs.scheduledSingleThreaded("DerivativeDataSourceManager-Exec-%d"));
final Duration delay = config.getPollDuration().toStandardDuration();
future = exec.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
updateDerivatives();
} catch (Exception e) {
log.makeAlert(e, "uncaught exception in derivatives manager updating thread").emit();
}
}
}, 0, delay.getMillis(), TimeUnit.MILLISECONDS);
started = true;
}
log.info("Derivatives manager started.");
}
Aggregations