一个treecache缓存集群的问题

diaomin81 2008-01-08 07:14:14

各位好,最近在玩jboss和treecache,真是折磨人啊.我现在遇到一个treecache的问题,我配置的集群设置,似乎没有生效,配置内容如下:

<attribute name="ClusterConfig">
<config>
<UDP mcast_addr="224.0.0.1" mcast_port="48866"
ip_ttl="64" ip_mcast="true"
mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
loopback="true"/>
<PING timeout="2000" num_initial_members="3"
up_thread="false" down_thread="false"/>
<MERGE2 min_interval="10000" max_interval="20000"/>
<FD shun="true" up_thread="true" down_thread="true" />
<!-- <FD_SOCK/>-->
<VERIFY_SUSPECT timeout="1500"
up_thread="false" down_thread="false"/>
<pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
max_xmit_size="8192" up_thread="false" down_thread="false"/>
<UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"
down_thread="false"/>
<pbcast.STABLE desired_avg_gossip="20000"
up_thread="false" down_thread="false"/>
<FRAG frag_size="8192"
down_thread="false" up_thread="false"/>
<pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/>
</config>
</attribute>



而我对缓存进行的操作是:第一次查询的时候,把结果放到缓存中,第二次查询的时候,判断缓存中内容是否为null,如果是,查数据库,如果不是,则从缓存中读取,相关代码如下:

List messageList = new ArrayList();
Object obj=cache.get("/bbs/list", "message");


log.info("cache1------------------"+obj);
if(obj==null){
messageList=messageManager.getMessageList(messageForm.getRootId());
cache.put("/bbs/list","message",messageList);
}else{
messageList=(List)obj;
}

添加数据的时候,我会把缓存的值设置成null,像这样:

cache.put("/bbs/list", "message",null);

我遇到的问题是:两台机器只用级联线连接,互相能访问,但是两太机器的缓存都生效时,我做了如下操作:

1:我在2台机器上都做了查询操作,因为连接同一个库,结果当然一样

2:我在server1上增加数据,然后又进行了一次查询,server1上的结果变了,但是server2上的缓存似乎没接到通知,仍然没有改变

以前用过jcs,这种操作很简单,但是其稳定性很不好,不知道我这样操作treecache是否有问题,拜请各位高手指教指教
...全文
825 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
xhalg 2010-11-30
  • 打赏
  • 举报
回复
新手学习中,还不知道具体该怎么用,不知道谁有完整的例子
daichanglin200211 2009-09-27
  • 打赏
  • 举报
回复
配置文件:
<?xml version="1.0" encoding="UTF-8"?>

<!-- ===================================================================== -->
<!-- -->
<!-- Sample TreeCache Service Configuration -->
<!-- -->
<!-- ===================================================================== -->

<server>

<classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>


<!-- ==================================================================== -->
<!-- Defines TreeCache configuration -->
<!-- ==================================================================== -->

<mbean code="org.jboss.cache.TreeCache"
name="jboss.cache:service=TreeCache">

<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>

<!--
Configure the TransactionManager
-->
<attribute name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>

<!--
Isolation level : SERIALIZABLE
REPEATABLE_READ (default)
READ_COMMITTED
READ_UNCOMMITTED
NONE
-->
<attribute name="IsolationLevel">REPEATABLE_READ</attribute>

<!--
Valid modes are LOCAL
REPL_ASYNC
REPL_SYNC
INVALIDATION_ASYNC
INVALIDATION_SYNC
-->
<attribute name="CacheMode">REPL_SYNC</attribute>

<!--
Just used for async repl: use a replication queue
-->
<attribute name="UseReplQueue">false</attribute>

<!--
Replication interval for replication queue (in ms)
-->
<attribute name="ReplQueueInterval">0</attribute>

<!--
Max number of elements which trigger replication
-->
<attribute name="ReplQueueMaxElements">0</attribute>

<!-- Name of cluster. Needs to be the same for all clusters, in order
to find each other
-->
<attribute name="ClusterName">TreeCache-Cluster</attribute>

<!-- JGroups protocol stack properties. Can also be a URL,
e.g. file:/home/bela/default.xml
<attribute name="ClusterProperties"></attribute>
-->

<attribute name="ClusterConfig">
<config>
<!-- UDP: if you have a multihomed machine,
set the bind_addr attribute to the appropriate NIC IP address, e.g bind_addr="192.168.0.2"
-->
<!-- UDP: On Windows machines, because of the media sense feature
being broken with multicast (even after disabling media sense)
set the loopback attribute to true -->
<!-- <UDP mcast_addr="228.1.2.3" mcast_port="48866" -->
<UDP mcast_addr="224.0.0.1" mcast_port="48866"
ip_ttl="64" ip_mcast="true"
mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
loopback="true" bind_addr="192.168.1.3"/>
<PING timeout="2000" num_initial_members="3"
up_thread="false" down_thread="false"/>
<MERGE2 min_interval="10000" max_interval="20000"/>
<!-- <FD shun="true" up_thread="true" down_thread="true" />-->
<FD_SOCK/>
<VERIFY_SUSPECT timeout="1500"
up_thread="false" down_thread="false"/>
<pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
max_xmit_size="8192" up_thread="false" down_thread="false"/>
<UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"
down_thread="false"/>
<pbcast.STABLE desired_avg_gossip="20000"
up_thread="false" down_thread="false"/>
<FRAG frag_size="8192"
down_thread="false" up_thread="false"/>
<pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/>
</config>
</attribute>


<!--
Whether or not to fetch state on joining a cluster
NOTE this used to be called FetchStateOnStartup and has been renamed to be more descriptive.
-->
<attribute name="FetchInMemoryState">true</attribute>

<!--
The max amount of time (in milliseconds) we wait until the
initial state (ie. the contents of the cache) are retrieved from
existing members in a clustered environment
-->
<attribute name="InitialStateRetrievalTimeout">15000</attribute>

<!--
Number of milliseconds to wait until all responses for a
synchronous call have been received.
-->
<attribute name="SyncReplTimeout">15000</attribute>

<!-- Max number of milliseconds to wait for a lock acquisition -->
<attribute name="LockAcquisitionTimeout">10000</attribute>

<!-- Name of the eviction policy class. -->
<attribute name="EvictionPolicyClass"></attribute>

<!--
Indicate whether to use region based marshalling or not. Set this to true if you are running under a scoped
class loader, e.g., inside an application server. Default is "false".
-->
<attribute name="UseRegionBasedMarshalling">true</attribute>
</mbean>


<!-- Uncomment to get a graphical view of the TreeCache MBean above -->
<!-- <mbean code="org.jboss.cache.TreeCacheView" name="jboss.cache:service=TreeCacheView">-->
<!-- <depends>jboss.cache:service=TreeCache</depends>-->
<!-- <attribute name="CacheService">jboss.cache:service=TreeCache</attribute>-->
<!-- </mbean>-->


</server>
daichanglin200211 2009-09-26
  • 打赏
  • 举报
回复
我的cache可以在本地的不同jvm上同步,但是不能实现分布式同步。为什么啊,请高手指点啊?
代码:
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.jboss.cache.TreeCache;


public class TreeCacheTool {

public static final String PRODUCT_NODE = "/Test/Product";

private TreeCache treeCache;
private Logger logger=Logger.getLogger(this.getClass());
/*
* 初始化缓存
*/
public boolean initCache()
{
try
{
treeCache = new TreeCache();
org.jboss.cache.PropertyConfigurator config = new org.jboss.cache.PropertyConfigurator();
config.configure(treeCache, "TreeCache.xml");
treeCache.createService(); // not necessary, but is same as MBean lifecycle
treeCache.startService(); // kick start tree cache
logger.info("����ϵͳ��ʼ���ɹ�!");
}
catch (Exception e)
{
logger.error("初始化缓存失败:" + e.getMessage());

return false;
}

return true;
}

public void addElement(Object key, Object value) throws Exception
{
treeCache.put(PRODUCT_NODE, key, value);
}

public Object getElement(Object key) throws Exception
{
return treeCache.get(PRODUCT_NODE, key);
}
public Object removeElement(Object key) throws Exception
{
return treeCache.remove(PRODUCT_NODE, key);
}

public boolean existElement(Object key) throws Exception
{
return treeCache.exists(PRODUCT_NODE, key);
}
}
zibing522 2008-06-05
  • 打赏
  • 举报
回复
diaomin81 能不发个源码啊。。我也在学习中。最近配了一下,一运行就报错
org.hibernate.HibernateException: could not instantiate CacheProvider: net.sf.hibernate.cache.TreeCacheProvider
diaomin81 2008-01-14
  • 打赏
  • 举报
回复
问题已经解决了,主要是以为我对jboss平台不熟悉,把配置文件搞错了的原因,配置文件的内容确实没问题,经过对配置文件名和代码的一些调整,现在已经可以实现缓存的分布了,谢谢JBossWeek的帮助。
我不知道咋转分给别人, 现在试试,万一收不到还请见谅
JBossWeek 2008-01-11
  • 打赏
  • 举报
回复
1、配置没有问题
2、default模式可以使用jbosscache的集群服务,但是需要将jgroups.jar拷贝到default/lib目录下
3、你遇到的问题是不是代码的问题,给一段测试过的代码:
TreeCache cache = new TreeCache();
PropertyConfigurator config = new PropertyConfigurator();
config.configure(cache, "META-INF/cache-service.xml");
cache.startService();
diaomin81 2008-01-11
  • 打赏
  • 举报
回复
谢谢JBossWeek,我仔细研究下试试看
JBossWeek 2008-01-10
  • 打赏
  • 举报
回复
lz把treecache.xml贴出来看看吧
diaomin81 2008-01-10
  • 打赏
  • 举报
回复
麻烦JBossWeek帮忙看看,不胜感激,另外弱弱的问一句,是不是一定要启动all模式啊?我启动的是default模式
diaomin81 2008-01-10
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<server>
<classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
<mbean code="org.jboss.cache.TreeCache"
name="jboss.cache:service=CustomTreeCache">
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
<attribute name="TransactionManagerLookupClass">
org.jboss.cache.GenericTransactionManagerLookup</attribute>

<attribute name="NodeLockingScheme">PESSIMISTIC</attribute>

<attribute name="IsolationLevel">REPEATABLE_READ</attribute>
<attribute name="CacheMode">REPL_SYNC</attribute>

<attribute name="UseReplQueue">false</attribute>

<attribute name="ReplQueueInterval">0</attribute>
<attribute name="ReplQueueMaxElements">0</attribute>
<attribute name="ClusterName">TreeCache-Cluster</attribute>
<attribute name="ClusterConfig">
<config>
<UDP mcast_addr="224.0.0.10" mcast_port="48866"
ip_ttl="64" ip_mcast="true"
mcast_send_buf_size="150000" mcast_recv_buf_size="80000"
ucast_send_buf_size="150000" ucast_recv_buf_size="80000"
loopback="false"/>
<PING timeout="2000" num_initial_members="3"
up_thread="false" down_thread="false"/>
<MERGE2 min_interval="10000" max_interval="20000"/>
<FD shun="true" up_thread="true" down_thread="true" />
<!-- <FD_SOCK/>-->
<VERIFY_SUSPECT timeout="1500"
up_thread="false" down_thread="false"/>
<pbcast.NAKACK gc_lag="50" retransmit_timeout="600,1200,2400,4800"
max_xmit_size="8192" up_thread="false" down_thread="false"/>
<UNICAST timeout="600,1200,2400" window_size="100" min_threshold="10"
down_thread="false"/>
<pbcast.STABLE desired_avg_gossip="20000"
up_thread="false" down_thread="false"/>
<FRAG frag_size="8192"
down_thread="false" up_thread="false"/>
<pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
shun="true" print_local_addr="true"/>
<pbcast.STATE_TRANSFER up_thread="true" down_thread="true"/>
</config>
</attribute>
<attribute name="FetchInMemoryState">false</attribute>
<attribute name="SyncReplTimeout">20000</attribute>
<attribute name="LockAcquisitionTimeout">15000</attribute>
<attribute name="EvictionPolicyClass"></attribute>
<attribute name="UseMarshalling">false</attribute>
</mbean>
</server>
diaomin81 2008-01-09
  • 打赏
  • 举报
回复
已经是REPL_SYNC了
我用的是jboss4.2.1,我在我的发布目录里放了treecache.xml,并且直接修改里面的内容来用,这也可以吗?还是我需要再写另外一个treecache的配置文件才能实现集群?
JBossWeek 2008-01-08
  • 打赏
  • 举报
回复
请检查一下CacheMode是否为LOCAL,如果是请改为REPL_ASYNC或REPL_SYNC

6,786

社区成员

发帖
与我相关
我的任务
社区描述
JBoss技术交流
社区管理员
  • JBoss技术交流社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧