Search in sources :

Example 1 with RemovalListener

use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project pinot by linkedin.

the class ThirdEyeCacheRegistry method initCaches.

private static void initCaches(ThirdEyeConfiguration config) {
    ThirdEyeCacheRegistry cacheRegistry = ThirdEyeCacheRegistry.getInstance();
    RemovalListener<PinotQuery, ResultSetGroup> listener = new RemovalListener<PinotQuery, ResultSetGroup>() {

        @Override
        public void onRemoval(RemovalNotification<PinotQuery, ResultSetGroup> notification) {
            LOGGER.info("Expired {}", notification.getKey().getPql());
        }
    };
    // ResultSetGroup Cache. The size of this cache is limited by the total number of buckets in all ResultSetGroup.
    // We estimate that 1 bucket (including overhead) consumes 1KB and this cache is allowed to use up to 50% of max
    // heap space.
    long maxBucketNumber = getApproximateMaxBucketNumber(DEFAULT_HEAP_PERCENTAGE_FOR_RESULTSETGROUP_CACHE);
    LoadingCache<PinotQuery, ResultSetGroup> resultSetGroupCache = CacheBuilder.newBuilder().removalListener(listener).expireAfterAccess(1, TimeUnit.HOURS).maximumWeight(maxBucketNumber).weigher((pinotQuery, resultSetGroup) -> {
        int resultSetCount = resultSetGroup.getResultSetCount();
        int weight = 0;
        for (int idx = 0; idx < resultSetCount; ++idx) {
            com.linkedin.pinot.client.ResultSet resultSet = resultSetGroup.getResultSet(idx);
            weight += (resultSet.getColumnCount() * resultSet.getRowCount());
        }
        return weight;
    }).build(new ResultSetGroupCacheLoader(pinotThirdeyeClientConfig));
    cacheRegistry.registerResultSetGroupCache(resultSetGroupCache);
    LOGGER.info("Max bucket number for ResultSetGroup cache is set to {}", maxBucketNumber);
    // CollectionMaxDataTime Cache
    LoadingCache<String, Long> collectionMaxDataTimeCache = CacheBuilder.newBuilder().refreshAfterWrite(5, TimeUnit.MINUTES).build(new CollectionMaxDataTimeCacheLoader(resultSetGroupCache, datasetConfigDAO));
    cacheRegistry.registerCollectionMaxDataTimeCache(collectionMaxDataTimeCache);
    // Query Cache
    QueryCache queryCache = new QueryCache(thirdEyeClient, Executors.newFixedThreadPool(10));
    cacheRegistry.registerQueryCache(queryCache);
    // Dimension Filter cache
    LoadingCache<String, String> dimensionFiltersCache = CacheBuilder.newBuilder().build(new DimensionFiltersCacheLoader(cacheRegistry.getQueryCache()));
    cacheRegistry.registerDimensionFiltersCache(dimensionFiltersCache);
    // Dashboards cache
    LoadingCache<String, String> dashboardsCache = CacheBuilder.newBuilder().build(new DashboardsCacheLoader(dashboardConfigDAO));
    cacheRegistry.registerDashboardsCache(dashboardsCache);
    // Collections cache
    CollectionsCache collectionsCache = new CollectionsCache(datasetConfigDAO, config);
    cacheRegistry.registerCollectionsCache(collectionsCache);
    // DatasetConfig cache
    LoadingCache<String, DatasetConfigDTO> datasetConfigCache = CacheBuilder.newBuilder().build(new DatasetConfigCacheLoader(datasetConfigDAO));
    cacheRegistry.registerDatasetConfigCache(datasetConfigCache);
    // MetricConfig cache
    LoadingCache<MetricDataset, MetricConfigDTO> metricConfigCache = CacheBuilder.newBuilder().build(new MetricConfigCacheLoader(metricConfigDAO));
    cacheRegistry.registerMetricConfigCache(metricConfigCache);
    // DashboardConfigs cache
    LoadingCache<String, List<DashboardConfigDTO>> dashboardConfigsCache = CacheBuilder.newBuilder().build(new DashboardConfigCacheLoader(dashboardConfigDAO));
    cacheRegistry.registerDashboardConfigsCache(dashboardConfigsCache);
}
Also used : ResultSetGroup(com.linkedin.pinot.client.ResultSetGroup) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) LoadingCache(com.google.common.cache.LoadingCache) DimensionFiltersCacheLoader(com.linkedin.thirdeye.client.cache.DimensionFiltersCacheLoader) PinotQuery(com.linkedin.thirdeye.client.pinot.PinotQuery) DashboardConfigManager(com.linkedin.thirdeye.datalayer.bao.DashboardConfigManager) LoggerFactory(org.slf4j.LoggerFactory) ThirdEyeConfiguration(com.linkedin.thirdeye.common.ThirdEyeConfiguration) DatasetConfigManager(com.linkedin.thirdeye.datalayer.bao.DatasetConfigManager) MetricDataset(com.linkedin.thirdeye.client.cache.MetricDataset) MetricConfigManager(com.linkedin.thirdeye.datalayer.bao.MetricConfigManager) PinotThirdEyeClient(com.linkedin.thirdeye.client.pinot.PinotThirdEyeClient) QueryCache(com.linkedin.thirdeye.client.cache.QueryCache) CollectionMaxDataTimeCacheLoader(com.linkedin.thirdeye.client.cache.CollectionMaxDataTimeCacheLoader) MetricConfigCacheLoader(com.linkedin.thirdeye.client.cache.MetricConfigCacheLoader) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CacheResource(com.linkedin.thirdeye.dashboard.resources.CacheResource) DashboardConfigCacheLoader(com.linkedin.thirdeye.client.cache.DashboardConfigCacheLoader) RemovalNotification(com.google.common.cache.RemovalNotification) CollectionsCache(com.linkedin.thirdeye.client.cache.CollectionsCache) Logger(org.slf4j.Logger) PinotThirdEyeClientConfig(com.linkedin.thirdeye.client.pinot.PinotThirdEyeClientConfig) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) DatasetConfigCacheLoader(com.linkedin.thirdeye.client.cache.DatasetConfigCacheLoader) List(java.util.List) DashboardsCacheLoader(com.linkedin.thirdeye.client.cache.DashboardsCacheLoader) ResultSetGroupCacheLoader(com.linkedin.thirdeye.client.cache.ResultSetGroupCacheLoader) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) RemovalListener(com.google.common.cache.RemovalListener) CacheBuilder(com.google.common.cache.CacheBuilder) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) ResultSetGroupCacheLoader(com.linkedin.thirdeye.client.cache.ResultSetGroupCacheLoader) QueryCache(com.linkedin.thirdeye.client.cache.QueryCache) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) DatasetConfigCacheLoader(com.linkedin.thirdeye.client.cache.DatasetConfigCacheLoader) DimensionFiltersCacheLoader(com.linkedin.thirdeye.client.cache.DimensionFiltersCacheLoader) List(java.util.List) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) DashboardConfigCacheLoader(com.linkedin.thirdeye.client.cache.DashboardConfigCacheLoader) RemovalListener(com.google.common.cache.RemovalListener) ResultSetGroup(com.linkedin.pinot.client.ResultSetGroup) DashboardsCacheLoader(com.linkedin.thirdeye.client.cache.DashboardsCacheLoader) MetricDataset(com.linkedin.thirdeye.client.cache.MetricDataset) CollectionMaxDataTimeCacheLoader(com.linkedin.thirdeye.client.cache.CollectionMaxDataTimeCacheLoader) PinotQuery(com.linkedin.thirdeye.client.pinot.PinotQuery) MetricConfigCacheLoader(com.linkedin.thirdeye.client.cache.MetricConfigCacheLoader) RemovalNotification(com.google.common.cache.RemovalNotification) CollectionsCache(com.linkedin.thirdeye.client.cache.CollectionsCache)

Example 2 with RemovalListener

use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project airavata by apache.

the class Factory method loadConfiguration.

public static void loadConfiguration() throws GFacException {
    GFacYamlConfigruation config = new GFacYamlConfigruation();
    try {
        for (JobSubmitterTaskConfig jobSubmitterTaskConfig : config.getJobSbumitters()) {
            String taskClass = jobSubmitterTaskConfig.getTaskClass();
            Class<?> aClass = Class.forName(taskClass);
            Constructor<?> constructor = aClass.getConstructor();
            JobSubmissionTask task = (JobSubmissionTask) constructor.newInstance();
            task.init(jobSubmitterTaskConfig.getProperties());
            jobSubmissionTask.put(jobSubmitterTaskConfig.getSubmissionProtocol(), task);
        }
        for (DataTransferTaskConfig dataTransferTaskConfig : config.getFileTransferTasks()) {
            String taskClass = dataTransferTaskConfig.getTaskClass();
            Class<?> aClass = Class.forName(taskClass);
            Constructor<?> constructor = aClass.getConstructor();
            Task task = (Task) constructor.newInstance();
            task.init(dataTransferTaskConfig.getProperties());
            dataMovementTask.put(dataTransferTaskConfig.getTransferProtocol(), task);
        }
        for (ResourceConfig resourceConfig : config.getResourceConfiguration()) {
            resources.put(resourceConfig.getJobManagerType(), resourceConfig);
        }
    } catch (Exception e) {
        throw new GFacException("Gfac config issue", e);
    }
    sessionCache = CacheBuilder.newBuilder().expireAfterAccess(ServerSettings.getSessionCacheAccessTimeout(), TimeUnit.MINUTES).removalListener((RemovalListener<String, Session>) removalNotification -> {
        if (removalNotification.getValue().isConnected()) {
            log.info("Disconnecting ssh session with key: " + removalNotification.getKey());
            removalNotification.getValue().disconnect();
        }
        log.info("Removed ssh session with key: " + removalNotification.getKey());
    }).build();
}
Also used : JobSubmitterTaskConfig(org.apache.airavata.gfac.core.config.JobSubmitterTaskConfig) JobManagerConfiguration(org.apache.airavata.gfac.core.JobManagerConfiguration) ArchiveTask(org.apache.airavata.gfac.impl.task.ArchiveTask) ExperimentCatalog(org.apache.airavata.registry.cpi.ExperimentCatalog) JobMonitor(org.apache.airavata.gfac.core.monitor.JobMonitor) LoggerFactory(org.slf4j.LoggerFactory) CancelRequestWatcherImpl(org.apache.airavata.gfac.impl.watcher.CancelRequestWatcherImpl) ResourceJobManagerType(org.apache.airavata.model.appcatalog.computeresource.ResourceJobManagerType) Credential(org.apache.airavata.credential.store.credential.Credential) ServerSettings(org.apache.airavata.common.utils.ServerSettings) Publisher(org.apache.airavata.messaging.core.Publisher) Map(java.util.Map) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) SlurmJobConfiguration(org.apache.airavata.gfac.impl.job.SlurmJobConfiguration) MessagingFactory(org.apache.airavata.messaging.core.MessagingFactory) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) SSHKeyAuthentication(org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication) RabbitMQPublisher(org.apache.airavata.messaging.core.impl.RabbitMQPublisher) UUID(java.util.UUID) HostScheduler(org.apache.airavata.gfac.core.scheduler.HostScheduler) RedeliveryRequestWatcherImpl(org.apache.airavata.gfac.impl.watcher.RedeliveryRequestWatcherImpl) MessageHandler(org.apache.airavata.messaging.core.MessageHandler) AppCatalog(org.apache.airavata.registry.cpi.AppCatalog) List(java.util.List) AuroraJobMonitor(org.apache.airavata.gfac.monitor.cloud.AuroraJobMonitor) CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryPolicy(org.apache.curator.RetryPolicy) RedeliveryRequestWatcher(org.apache.airavata.gfac.core.watcher.RedeliveryRequestWatcher) CacheBuilder(com.google.common.cache.CacheBuilder) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) DataTransferTaskConfig(org.apache.airavata.gfac.core.config.DataTransferTaskConfig) JobSubmitterTaskConfig(org.apache.airavata.gfac.core.config.JobSubmitterTaskConfig) Task(org.apache.airavata.gfac.core.task.Task) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ForkJobConfiguration(org.apache.airavata.gfac.impl.job.ForkJobConfiguration) PBSJobConfiguration(org.apache.airavata.gfac.impl.job.PBSJobConfiguration) Type(org.apache.airavata.messaging.core.Type) DataMovementProtocol(org.apache.airavata.model.data.movement.DataMovementProtocol) HashMap(java.util.HashMap) UGEJobConfiguration(org.apache.airavata.gfac.impl.job.UGEJobConfiguration) Constructor(java.lang.reflect.Constructor) CancelRequestWatcher(org.apache.airavata.gfac.core.watcher.CancelRequestWatcher) ArrayList(java.util.ArrayList) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ResourceJobManager(org.apache.airavata.model.appcatalog.computeresource.ResourceJobManager) JobSubmissionTask(org.apache.airavata.gfac.core.task.JobSubmissionTask) RegistryException(org.apache.airavata.registry.cpi.RegistryException) MonitorMode(org.apache.airavata.model.appcatalog.computeresource.MonitorMode) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacUtils(org.apache.airavata.gfac.core.GFacUtils) LSFJobConfiguration(org.apache.airavata.gfac.impl.job.LSFJobConfiguration) RegistryFactory(org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory) ResourceConfig(org.apache.airavata.gfac.core.config.ResourceConfig) Logger(org.slf4j.Logger) GFacException(org.apache.airavata.gfac.core.GFacException) RemoteCluster(org.apache.airavata.gfac.core.cluster.RemoteCluster) GFacYamlConfigruation(org.apache.airavata.gfac.core.config.GFacYamlConfigruation) JobSubmissionProtocol(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol) EmailBasedMonitor(org.apache.airavata.gfac.monitor.email.EmailBasedMonitor) TimeUnit(java.util.concurrent.TimeUnit) AuthenticationInfo(org.apache.airavata.gfac.core.authentication.AuthenticationInfo) GFacContext(org.apache.airavata.gfac.core.context.GFacContext) GFacEngine(org.apache.airavata.gfac.core.GFacEngine) RemovalListener(com.google.common.cache.RemovalListener) Cache(com.google.common.cache.Cache) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) OutputParser(org.apache.airavata.gfac.core.cluster.OutputParser) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo) com.jcraft.jsch(com.jcraft.jsch) Subscriber(org.apache.airavata.messaging.core.Subscriber) ArchiveTask(org.apache.airavata.gfac.impl.task.ArchiveTask) Task(org.apache.airavata.gfac.core.task.Task) JobSubmissionTask(org.apache.airavata.gfac.core.task.JobSubmissionTask) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacException(org.apache.airavata.gfac.core.GFacException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) GFacException(org.apache.airavata.gfac.core.GFacException) JobSubmissionTask(org.apache.airavata.gfac.core.task.JobSubmissionTask) ResourceConfig(org.apache.airavata.gfac.core.config.ResourceConfig) DataTransferTaskConfig(org.apache.airavata.gfac.core.config.DataTransferTaskConfig) GFacYamlConfigruation(org.apache.airavata.gfac.core.config.GFacYamlConfigruation)

Example 3 with RemovalListener

use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project EventHub by Codecademy.

the class UserEventIndexModule method getBlockFactory.

@Provides
public UserEventIndex.Block.Factory getBlockFactory(@Named("eventhub.usereventindex.directory") final String directory, @Named("eventhub.usereventindex.blockCacheSize") int blockCacheSize, @Named("eventhub.usereventindex.numRecordsPerBlock") int numRecordsPerBlock, @Named("eventhub.usereventindex.numBlocksPerFile") int numBlocksPerFile) {
    final int fileSize = numBlocksPerFile * (numRecordsPerBlock * UserEventIndex.ID_SIZE + UserEventIndex.Block.MetaData.SIZE);
    LoadingCache<Integer, MappedByteBuffer> buffers = CacheBuilder.newBuilder().maximumSize(blockCacheSize).recordStats().removalListener(new RemovalListener<Integer, MappedByteBuffer>() {

        @Override
        public void onRemoval(RemovalNotification<Integer, MappedByteBuffer> notification) {
            MappedByteBuffer value = notification.getValue();
            if (value != null) {
                value.force();
            }
        }
    }).build(new CacheLoader<Integer, MappedByteBuffer>() {

        @Override
        public MappedByteBuffer load(Integer key) throws Exception {
            return ByteBufferUtil.createNewBuffer(String.format("%s/block_%d.mem", directory, key), fileSize);
        }
    });
    String filename = directory + "block_factory.ser";
    File file = new File(filename);
    if (file.exists()) {
        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
            long currentPointer = ois.readLong();
            return new UserEventIndex.Block.Factory(filename, buffers, numRecordsPerBlock, numBlocksPerFile, currentPointer);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return new UserEventIndex.Block.Factory(filename, buffers, numRecordsPerBlock, numBlocksPerFile, 0);
}
Also used : IOException(java.io.IOException) RemovalListener(com.google.common.cache.RemovalListener) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MappedByteBuffer(java.nio.MappedByteBuffer) RemovalNotification(com.google.common.cache.RemovalNotification) File(java.io.File) ObjectInputStream(java.io.ObjectInputStream) Provides(com.google.inject.Provides)

Example 4 with RemovalListener

use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project EventHub by Codecademy.

the class DmaList method build.

public static <T> DmaList<T> build(final Schema<T> schema, final String directory, final int numRecordsPerFile, int cacheSize) {
    // noinspection ResultOfMethodCallIgnored
    new File(directory).mkdirs();
    try (RandomAccessFile raf = new RandomAccessFile(new File(String.format("%s/meta_data.mem", directory)), "rw")) {
        MappedByteBuffer metaDataBuffer = raf.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, 8);
        long numRecords = metaDataBuffer.getLong();
        final int fileSize = numRecordsPerFile * schema.getObjectSize();
        LoadingCache<Integer, MappedByteBuffer> buffers = CacheBuilder.newBuilder().maximumSize(cacheSize).recordStats().removalListener(new RemovalListener<Integer, MappedByteBuffer>() {

            @Override
            public void onRemoval(RemovalNotification<Integer, MappedByteBuffer> notification) {
                MappedByteBuffer value = notification.getValue();
                if (value != null) {
                    value.force();
                }
            }
        }).build(new CacheLoader<Integer, MappedByteBuffer>() {

            @Override
            public MappedByteBuffer load(Integer key) throws Exception {
                return ByteBufferUtil.createNewBuffer(String.format("%s/dma_list_%d.mem", directory, key), fileSize);
            }
        });
        return new DmaList<>(directory, schema, metaDataBuffer, buffers, numRecords, numRecordsPerFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) RemovalListener(com.google.common.cache.RemovalListener) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) MappedByteBuffer(java.nio.MappedByteBuffer) RemovalNotification(com.google.common.cache.RemovalNotification) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 5 with RemovalListener

use of org.apache.flink.shaded.guava30.com.google.common.cache.RemovalListener in project kylo by Teradata.

the class JobTrackerService method createCache.

/**
 * Creates a job cache.
 */
@Nonnull
private Cache<String, Job<?>> createCache() {
    final Cache<String, Job<?>> cache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).removalListener(new RemovalListener<String, Job<?>>() {

        @Override
        public void onRemoval(@Nonnull final RemovalNotification<String, Job<?>> notification) {
            // noinspection ConstantConditions
            final Optional<Integer> jobId = notification.getValue().getJobId();
            if (jobId.isPresent()) {
                jobs.remove(jobId.get());
            }
            for (final StageInfo stage : notification.getValue().getStages()) {
                stages.remove(stage.stageId());
            }
        }
    }).build();
    // Schedule clean-up of groups
    executor.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            groups.cleanUp();
        }
    }, 1, 1, TimeUnit.HOURS);
    return cache;
}
Also used : Nonnull(javax.annotation.Nonnull) StageInfo(org.apache.spark.scheduler.StageInfo) RemovalNotification(com.google.common.cache.RemovalNotification) SaveJob(com.thinkbiganalytics.spark.metadata.SaveJob) Job(com.thinkbiganalytics.spark.metadata.Job) TransformJob(com.thinkbiganalytics.spark.metadata.TransformJob) RemovalListener(com.google.common.cache.RemovalListener) Nonnull(javax.annotation.Nonnull)

Aggregations

RemovalListener (com.google.common.cache.RemovalListener)7 RemovalNotification (com.google.common.cache.RemovalNotification)5 CacheBuilder (com.google.common.cache.CacheBuilder)3 TimeUnit (java.util.concurrent.TimeUnit)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 LoadingCache (com.google.common.cache.LoadingCache)2 File (java.io.File)2 IOException (java.io.IOException)2 MappedByteBuffer (java.nio.MappedByteBuffer)2 List (java.util.List)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Cache (com.google.common.cache.Cache)1 CacheLoader (com.google.common.cache.CacheLoader)1 Provides (com.google.inject.Provides)1 PreparedStatementBuilder (com.hortonworks.registries.storage.impl.jdbc.provider.sql.statement.PreparedStatementBuilder)1 com.jcraft.jsch (com.jcraft.jsch)1 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)1 CollectionMaxDataTimeCacheLoader (com.linkedin.thirdeye.client.cache.CollectionMaxDataTimeCacheLoader)1 CollectionsCache (com.linkedin.thirdeye.client.cache.CollectionsCache)1