Skip to content

Commit

Permalink
KYLIN-2896 remove query exception cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kyotoYaho authored and shaofengshi committed Oct 29, 2018
1 parent 95afdb4 commit 6b5f961
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ public void notifyMetadataChange(String entity, Event event, String cacheKey) th
public void cleanDataCache(String project) {
if (cacheManager != null) {
if (getConfig().isQueryCacheSignatureEnabled()) {
logger.info("cleaning cache for project " + project + " (currently remove exception entries)");
cacheManager.getCache(QueryService.EXCEPTION_QUERY_CACHE).removeAll();
logger.info("cleaning cache for project " + project + " (currently remove nothing)");
} else {
logger.info("cleaning cache for project " + project + " (currently remove all entries)");
cacheManager.getCache(QueryService.SUCCESS_QUERY_CACHE).removeAll();
cacheManager.getCache(QueryService.EXCEPTION_QUERY_CACHE).removeAll();
cacheManager.getCache(QueryService.QUERY_CACHE).removeAll();
}
} else {
logger.warn("skip cleaning cache for project " + project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@
@Component("queryService")
public class QueryService extends BasicService {

public static final String SUCCESS_QUERY_CACHE = "StorageCache";
public static final String EXCEPTION_QUERY_CACHE = "ExceptionQueryCache";
public static final String QUERY_CACHE = "StorageCache";
public static final String QUERY_STORE_PATH_PREFIX = "/query/";
private static final Logger logger = LoggerFactory.getLogger(QueryService.class);
final BadQueryDetector badQueryDetector = new BadQueryDetector();
Expand Down Expand Up @@ -481,7 +480,7 @@ && checkCondition(
&& checkCondition(sqlResponse.getResults().size() < kylinConfig.getLargeQueryThreshold(),
"query response is too large: {} ({})", sqlResponse.getResults().size(),
kylinConfig.getLargeQueryThreshold())) {
cacheManager.getCache(SUCCESS_QUERY_CACHE).put(sqlRequest.getCacheKey(), sqlResponse);
cacheManager.getCache(QUERY_CACHE).put(sqlRequest.getCacheKey(), sqlResponse);
}

} catch (Throwable e) { // calcite may throw AssertError
Expand All @@ -495,7 +494,7 @@ && checkCondition(sqlResponse.getResults().size() < kylinConfig.getLargeQueryThr

if (queryCacheEnabled && e.getCause() != null
&& ExceptionUtils.getRootCause(e) instanceof ResourceLimitExceededException) {
Cache exceptionCache = cacheManager.getCache(EXCEPTION_QUERY_CACHE);
Cache exceptionCache = cacheManager.getCache(QUERY_CACHE);
exceptionCache.put(sqlRequest.getCacheKey(), sqlResponse);
}
}
Expand All @@ -521,37 +520,28 @@ private String getUserName() {
}

public SQLResponse searchQueryInCache(SQLRequest sqlRequest) {
String[] cacheTypes = new String[] { EXCEPTION_QUERY_CACHE, SUCCESS_QUERY_CACHE };
for (String cacheType : cacheTypes) {
Cache cache = cacheManager.getCache(cacheType);
Cache.ValueWrapper wrapper = cache.get(sqlRequest.getCacheKey());
if (wrapper == null) {
continue;
}
SQLResponse response = (SQLResponse) wrapper.get();
if (response == null) {
return null;
}
logger.info("The sqlResponse is found in " + cacheType);
if (getConfig().isQueryCacheSignatureEnabled()
&& !SQLResponseSignatureUtil.checkSignature(getConfig(), response, sqlRequest.getProject())) {
logger.info("The sql response signature is changed. Remove it from QUERY_CACHE.");
cache.evict(sqlRequest.getCacheKey());
return null;
} else {
switch (cacheType) {
case EXCEPTION_QUERY_CACHE:
response.setHitExceptionCache(true);
break;
case SUCCESS_QUERY_CACHE:
response.setStorageCacheUsed(true);
break;
default:
}
}
return response;
Cache cache = cacheManager.getCache(QUERY_CACHE);
Cache.ValueWrapper wrapper = cache.get(sqlRequest.getCacheKey());
if (wrapper == null) {
return null;
}
return null;
SQLResponse response = (SQLResponse) wrapper.get();
if (response == null) {
return null;
}
logger.info("The sqlResponse is found in QUERY_CACHE");
if (getConfig().isQueryCacheSignatureEnabled()
&& !SQLResponseSignatureUtil.checkSignature(getConfig(), response, sqlRequest.getProject())) {
logger.info("The sql response signature is changed. Remove it from QUERY_CACHE.");
cache.evict(sqlRequest.getCacheKey());
return null;
}
if (response.getIsException()) {
response.setHitExceptionCache(true);
} else {
response.setStorageCacheUsed(true);
}
return response;
}

private SQLResponse queryWithSqlMassage(SQLRequest sqlRequest) throws Exception {
Expand Down

0 comments on commit 6b5f961

Please sign in to comment.