private TimelineStore getCachedStore(TimelineEntityGroupId groupId, List<EntityCacheItem> cacheItems) throws IOException { EntityCacheItem cacheItem; synchronized (this.cachedLogs) { // Note that the content in the cache log storage may be stale. cacheItem = this.cachedLogs.get(groupId); if (cacheItem == null) { LOG.debug("Set up new cache item for id {}", groupId); cacheItem = new EntityCacheItem(groupId, getConfig()); AppLogs appLogs = getAndSetAppLogs(groupId.getApplicationId()); if (appLogs != null) { LOG.debug("Set applogs {} for group id {}", appLogs, groupId); cacheItem.setAppLogs(appLogs); this.cachedLogs.put(groupId, cacheItem); } else { LOG.warn("AppLogs for groupId {} is set to null!", groupId); } } } TimelineStore store = null; if (cacheItem.getAppLogs() != null) { AppLogs appLogs = cacheItem.getAppLogs(); LOG.debug("try refresh cache {} {}", groupId, appLogs.getAppId()); cacheItems.add(cacheItem); store = cacheItem.refreshCache(aclManager, metrics); } else { LOG.warn("AppLogs for group id {} is null", groupId); } return store; }
@Override protected boolean removeEldestEntry( Map.Entry<TimelineEntityGroupId, EntityCacheItem> eldest) { if (super.size() > appCacheMaxSize) { TimelineEntityGroupId groupId = eldest.getKey(); LOG.debug("Evicting {} due to space limitations", groupId); EntityCacheItem cacheItem = eldest.getValue(); LOG.debug("Force release cache {}.", groupId); cacheItem.forceRelease(); if (cacheItem.getAppLogs().isDone()) { appIdLogMap.remove(groupId.getApplicationId()); } metrics.incrCacheEvicts(); return true; } return false; } });
@Override protected boolean removeEldestEntry( Map.Entry<TimelineEntityGroupId, EntityCacheItem> eldest) { if (super.size() > appCacheMaxSize) { TimelineEntityGroupId groupId = eldest.getKey(); LOG.debug("Evicting {} due to space limitations", groupId); EntityCacheItem cacheItem = eldest.getValue(); cacheItem.releaseCache(groupId); if (cacheItem.getAppLogs().isDone()) { appIdLogMap.remove(groupId.getApplicationId()); } return true; } return false; } });
store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED); EntityCacheItem cacheItem = new EntityCacheItem( EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), config); cacheItem.setAppLogs(appLogs); store.setCachedLogs( EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId),
public synchronized TimelineStore refreshCache(TimelineEntityGroupId groupId, TimelineACLsManager aclManager, JsonFactory jsonFactory, ObjectMapper objMapper) throws IOException { if (needRefresh()) { if (!appLogs.isDone()) { appLogs.parseSummaryLogs(); tdm.close(); updateRefreshTimeToNow(); } else { LOG.debug("Cache new enough, skip refreshing");
@Override protected void serviceStop() throws Exception { LOG.info("Stopping {}", getName()); stopExecutors.set(true); if (executor != null) { executor.shutdown(); if (executor.isTerminating()) { LOG.info("Waiting for executor to terminate"); boolean terminated = executor.awaitTermination(10, TimeUnit.SECONDS); if (terminated) { LOG.info("Executor terminated"); } else { LOG.warn("Executor did not terminate"); executor.shutdownNow(); } } } synchronized (cachedLogs) { for (EntityCacheItem cacheItem : cachedLogs.values()) { ServiceOperations.stopQuietly(cacheItem.getStore()); } } CallerContext.setCurrent(null); super.serviceStop(); }
if (needRefresh()) { long startTime = Time.monotonicNow(); updateRefreshTimeToNow(); metrics.addCacheRefreshTime(Time.monotonicNow() - startTime); } else {
private TimelineStore getCachedStore(TimelineEntityGroupId groupId) throws IOException { EntityCacheItem cacheItem; synchronized (this.cachedLogs) { // Note that the content in the cache log storage may be stale. cacheItem = this.cachedLogs.get(groupId); if (cacheItem == null) { LOG.debug("Set up new cache item for id {}", groupId); cacheItem = new EntityCacheItem(getConfig(), fs); AppLogs appLogs = getAndSetAppLogs(groupId.getApplicationId()); if (appLogs != null) { LOG.debug("Set applogs {} for group id {}", appLogs, groupId); cacheItem.setAppLogs(appLogs); this.cachedLogs.put(groupId, cacheItem); } else { LOG.warn("AppLogs for groupId {} is set to null!", groupId); } } } TimelineStore store = null; if (cacheItem.getAppLogs() != null) { AppLogs appLogs = cacheItem.getAppLogs(); LOG.debug("try refresh cache {} {}", groupId, appLogs.getAppId()); store = cacheItem.refreshCache(groupId, aclManager, jsonFactory, objMapper); } else { LOG.warn("AppLogs for group id {} is null", groupId); } return store; }