Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<artifactId>spring-test</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
Expand All @@ -70,6 +75,10 @@
<artifactId>spymemcached</artifactId>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<!-- Test & Env -->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

import net.spy.memcached.MemcachedClientIF;

public class MemcachedCacheManager extends AbstractCacheManager {
public class MemcachedCacheManager extends AbstractCacheManager implements RemoteCacheManager {

private static final Logger logger = LoggerFactory.getLogger(MemcachedCacheManager.class);
private static final Long ONE_MINUTE = 60 * 1000L;
Expand Down Expand Up @@ -73,12 +73,14 @@ protected Collection<? extends Cache> loadCaches() {
return caches;
}

@Override
public boolean isClusterDown() {
return !clusterHealth.get();
}

@VisibleForTesting
void setClusterHealth(boolean ifHealth) {
@Override
public void setClusterHealth(boolean ifHealth) {
clusterHealth.set(ifHealth);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.kylin.cache.cachemanager;

import java.util.Collection;

import org.springframework.cache.Cache;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisOperations;

public class RedisCacheManagerAdaptor extends RedisCacheManager implements RemoteCacheManager {

public RedisCacheManagerAdaptor(RedisOperations redisOperations) {
super(redisOperations);
}

public RedisCacheManagerAdaptor(RedisOperations redisOperations, Collection<String> cacheNames) {
super(redisOperations, cacheNames);
}

public RedisCacheManagerAdaptor(RedisOperations redisOperations, Collection<String> cacheNames,
boolean cacheNullValues) {
super(redisOperations, cacheNames, cacheNullValues);
}

/**
* Get Redis Cache Object
* @param name
* @return
*/
@Override
public Cache getCache(String name) {
return super.getCache(name);
}

@Override
public boolean isClusterDown() {
return clusterHealth.get();
}

@Override
public void setClusterHealth(boolean ifHealth) {
clusterHealth.set(ifHealth);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.kylin.cache.cachemanager;

import java.util.concurrent.atomic.AtomicBoolean;

public interface RemoteCacheManager {

AtomicBoolean clusterHealth = new AtomicBoolean(false);

/**
* Is this cache not in useful state
* @return
*/
boolean isClusterDown();

/**
* set cluster health state
* @param ifHealth true : isok, false: not ok
*/
void setClusterHealth(boolean ifHealth);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RemoteLocalFailOverCacheManager extends AbstractCacheManager {
private static final Logger logger = LoggerFactory.getLogger(RemoteLocalFailOverCacheManager.class);

@Autowired
private MemcachedCacheManager remoteCacheManager;
private CacheManager remoteCacheManager;

@Autowired
private CacheManager localCacheManager;
Expand All @@ -51,7 +51,8 @@ protected Collection<? extends Cache> loadCaches() {

@Override
public Cache getCache(String name) {
if (remoteCacheManager == null || remoteCacheManager.isClusterDown()) {
if (remoteCacheManager == null || (remoteCacheManager instanceof RemoteCacheManager
&& ((RemoteCacheManager) remoteCacheManager).isClusterDown())) {
logger.info("use local cache, because remote cache is not configured or down");
return localCacheManager.getCache(name);
} else {
Expand All @@ -61,11 +62,16 @@ public Cache getCache(String name) {

@VisibleForTesting
void disableRemoteCacheManager() {
remoteCacheManager.setClusterHealth(false);
if (remoteCacheManager instanceof RemoteCacheManager) {
((RemoteCacheManager) remoteCacheManager).setClusterHealth(false);
}
}

@VisibleForTesting
void enableRemoteCacheManager() {
remoteCacheManager.setClusterHealth(true);
if (remoteCacheManager instanceof RemoteCacheManager) {
((RemoteCacheManager) remoteCacheManager).setClusterHealth(true);
}
}

}
4 changes: 4 additions & 0 deletions cache/src/test/resources/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kylin.cache.redis.port=7777
kylin.cache.redis.host=10.48.186.102
kylin.cache.redis.passwd=123456
kylin.cache.redis.timeout=5000
120 changes: 120 additions & 0 deletions cache/src/test/resources/cacheContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,124 @@
<bean id="cacheManager" class="org.apache.kylin.cache.cachemanager.RemoteLocalFailOverCacheManager"/>
</beans>

<beans profile="testing-redis">

<context:property-placeholder location="classpath:cache.properties"/>
<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:configLocation="classpath:ehcache-test.xml" p:shared="true"/>
<bean id="localCacheManager" class="org.apache.kylin.cache.cachemanager.InstrumentedEhCacheCacheManager"
p:cacheManager-ref="ehcache"/>

<!-- jedis pool config -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="30"/>
<property name="maxIdle" value="10"/>
<property name="numTestsPerEvictionRun" value="1024"/>
<property name="timeBetweenEvictionRunsMillis" value="30000"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="softMinEvictableIdleTimeMillis" value="10000"/>
<property name="maxWaitMillis" value="1500"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="blockWhenExhausted" value="false"/>
</bean>

<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="jedisPoolConfig"/>
<property name="port" value="${kylin.cache.redis.port}"/>
<property name="hostName" value="${kylin.cache.redis.host}"/>
<property name="password" value="${kylin.cache.redis.passwd}"/>
<property name="timeout" value="${kylin.cache.redis.timeout}"/>
</bean>

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
</bean>
<bean id="remoteCacheManager" class="org.apache.kylin.cache.cachemanager.RedisCacheManagerAdaptor">
<constructor-arg name="redisOperations" ref="redisTemplate"/>
<constructor-arg name="cacheNames">
<list>
<value>StorageCache</value>
<value>ExceptionQueryCache</value>
<value>UserCache</value>
</list>
</constructor-arg>
<property name="expires" >
<map key-type="java.lang.String" value-type="java.lang.Long">
<entry key="StorageCache" value="86400"/>
<entry key="ExceptionQueryCache" value="86400"/>
<entry key="UserCache" value="10800"/>
</map>
</property>
</bean>

<bean id="cacheManager" class="org.apache.kylin.cache.cachemanager.RemoteLocalFailOverCacheManager"/>

</beans>

<beans profile="testing-redis-cluster">

<bean id="ehcache"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:configLocation="classpath:ehcache-test.xml" p:shared="true"/>
<bean id="localCacheManager" class="org.apache.kylin.cache.cachemanager.InstrumentedEhCacheCacheManager"
p:cacheManager-ref="ehcache"/>

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="30"/>
<property name="maxIdle" value="10"/>
<property name="numTestsPerEvictionRun" value="1024"/>
<property name="timeBetweenEvictionRunsMillis" value="30000"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="softMinEvictableIdleTimeMillis" value="10000"/>
<property name="maxWaitMillis" value="1500"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="blockWhenExhausted" value="false"/>
</bean>
<bean id="clusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<constructor-arg name="clusterNodes">
<list>
<value>127.0.0.1:7777</value>
<value>127.0.0.1:7778</value>
<value>127.0.0.1:7779</value>
</list>
</constructor-arg>
</bean>

<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<constructor-arg name="clusterConfig" ref="clusterConfiguration"/>
<constructor-arg name="poolConfig" ref="jedisPoolConfig"/>
</bean>

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
</property>
</bean>
<bean id="remoteCacheManager" class="org.apache.kylin.cache.cachemanager.RedisCacheManagerAdaptor">
<constructor-arg name="redisOperations" ref="redisTemplate"/>
<constructor-arg name="cacheNames">
<list>
<value>StorageCache</value>
</list>
</constructor-arg>
</bean>
<bean id="cacheManager" class="org.apache.kylin.cache.cachemanager.RemoteLocalFailOverCacheManager"/>

</beans>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
*/
@SuppressWarnings("serial")
public class SelectedColumnMeta implements Serializable {
public SelectedColumnMeta(boolean isAutoIncrement, boolean isCaseSensitive, boolean isSearchable, boolean isCurrency, int isNullalbe, boolean isSigned, int displaySize, String label, String name, String schemaName, String catelogName, String tableName, int precision, int scale, int columnType, String columnTypeName, boolean isReadOnly, boolean isWritable, boolean isDefinitelyWritable) {

public SelectedColumnMeta() {
this(false, false, false, false, 0, false, 0, null, null, null, null, null, 0, 0, 0, null, false, false, false);
}

public SelectedColumnMeta(boolean isAutoIncrement, boolean isCaseSensitive, boolean isSearchable,
boolean isCurrency, int isNullalbe, boolean isSigned, int displaySize, String label, String name,
String schemaName, String catelogName, String tableName, int precision, int scale, int columnType,
String columnTypeName, boolean isReadOnly, boolean isWritable, boolean isDefinitelyWritable) {
super();
this.isAutoIncrement = isAutoIncrement;
this.isCaseSensitive = isCaseSensitive;
Expand Down
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<xalan.version>2.7.2</xalan.version>
<ehcache.version>2.10.2.2.21</ehcache.version>
<memcached.verion>2.12.3</memcached.verion>
<jedis.version>2.10.2</jedis.version>
<apache-httpclient.version>4.2.5</apache-httpclient.version>
<roaring.version>0.6.18</roaring.version>
<cglib.version>3.2.4</cglib.version>
Expand All @@ -154,6 +155,7 @@
<!-- REST Service, ref https://github.com/spring-projects/spring-boot/blob/v1.3.8.RELEASE/spring-boot-dependencies/pom.xml -->
<spring.boot.version>1.3.8.RELEASE</spring.boot.version>
<spring.framework.version>4.3.10.RELEASE</spring.framework.version>
<spring.framework.data.version>1.8.23.RELEASE</spring.framework.data.version>
<spring.framework.security.version>4.2.3.RELEASE</spring.framework.security.version>
<spring.framework.security.extensions.version>1.0.2.RELEASE</spring.framework.security.extensions.version>
<opensaml.version>2.6.6</opensaml.version>
Expand Down Expand Up @@ -974,12 +976,22 @@
<artifactId>spring-security-saml2-core</artifactId>
<version>${spring.framework.security.extensions.version}</version>
</dependency>
<!--spring data -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring.framework.data.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-cas</artifactId>
<version>${spring.framework.security.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
Expand Down
Loading