Ignite的partition默认是0到1023。这个分区是针对cache级别的,并不是系统级别的参数。如果开启了持久化功能,那么数据会持久化到磁盘的work/db/{nodeid}中。如果数据量比较大,就会导致文件句柄过多。(例如1个cache,最多会持有1024个文件句柄)
我这里是通过SQL创建cache,通过查阅官网,可以预设一个自定义的cache template,在模板中自定义AffinityFunction(关联函数),设置自定义partitions参数,同时可以为cache设置groupName(缓存组),这样的话,相同的groupName的缓存会共享各种内部数据结构比如上面提到的分区映射。在CREATE TABLE的时候使用WITH TEMPLATE=<模板名>的方式引用新模板即可。
修改如下:
创建模板时,需要定义一个缓存配置然后将其加入Ignite
实例中,如下所示。如果希望在XML配置文件中定义缓存模板,需要在模板名后面加一个*
号,这个是用于标示该配置是一个模板而不是实际的缓存。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Enabling Apache Ignite Persistent Store. -->
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="persistenceEnabled" value="true"/>
</bean>
</property>
</bean>
</property>
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration" id="PARTITION_512">
<!-- when you create a template via XML configuration, you must add an asterisk to the name of the template -->
<property name="name" value="PARTITION_512*"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="backups" value="0"/>
<property name="groupName" value="group1"/>
<!-- Other cache parameters -->
<property name="affinity">
<bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
<property name="partitions" value="512"/>
</bean>
</property>
</bean>
</list>
</property>
...
</bean>
</beans>
CREATE TABLE ABC(
id BIGINT PRIMARY KEY,
aa VARCHAR(1024) NOT NULL,
vv VARCHAR(1024) NOT NULL,
description VARCHAR(1024)
) WITH "TEMPLATE=PARTITION_512,ATOMICITY=TRANSACTIONAL_SNAPSHOT";
检查work/db/{nodeid}中的part-{i}.bin的文件名,最大id是配置partition-1。
再查看ll /proc/{进程id}/fd下的句柄,句柄数减少。
功能验证也没什么问题。
参考:
数据建模 | Apache Ignite - 分布式内存数据库
SQL参考 | Apache Ignite - 分布式内存数据库