geode(三) region

来源:互联网 发布:淘宝伊舜数码靠谱吗 编辑:程序博客网 时间:2024/06/07 03:20

创建region

region命名大小写字母加下划线”“和减号”-“,双下划线开头”_“是保留字

gfsh>create region --name=region1 --type=REPLICATEcache.xml<region name="myRegion" refid="PARTITION_REDUNDANT">    <region-attributes>        <partition-attributes local-max-memory="512" />    </region-attributes></region><region name="myRegion" refid="REPLICATE">    <region-attributes statistics-enabled="true">        <entry-time-to-live>            <expiration-attributes timeout="60" action="destroy"/>        </entry-time-to-live>        <cache-listener>            <class-name>myPackage.MyCacheListener</class-name>        </cache-listener>    </region-attributes></region>Cache cache = CacheFactory.create();RegionFactory rf = cache.createRegionFactory(REPLICATE);Region pfloRegion = rf.create("Portfolios");RegionFactory rf =       cache.createRegionFactory(RegionShortcut.PARTITION);rf.addCacheListener(new LoggingCacheListener());custRegion = rf.create("customer");PartitionAttributesFactory paf = new PartitionAttributesFactory<CustomerId, String>();paf.setPartitionResolver(new CustomerOrderResolver());RegionFactory rf =     cache.createRegionFactory(RegionShortcut.PARTITION);rf.setPartitionAttributes(paf.create());rf.addCacheListener(new LoggingCacheListener());custRegion = rf.create("customer");ClientRegionFactory<String,String> cRegionFactory =     cache.createClientRegionFactory(PROXY);Region<String, String> region =     cRegionFactory.setPoolName("Pool3").create("DATA");<?xml version="1.0"?><cache    xmlns="http://geode.apache.org/schema/cache"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"    version="1.0"    lock-lease="120"    lock-timeout="60"    search-timeout="300"><!-- Create a region named Portfolios -->  <region name="Portfolios" refid="REPLICATE">      <region name="Private" refid="REPLICATE">      ...      </region>  </region></cache>Cache cache = CacheFactory.create();RegionFactory rf = cache.createRegionFactory(REPLICATE);Region pfloRegion = rf.create("Portfolios");Region pvtSubregion = rf.createSubregion(pfloRegion, "Private");// Invalidate the entire distributed region Region.invalidateRegion(); // Invalidate the region within this memberRegion.localInvalidateRegion(); // Remove all entries for the regionRegion.clear(); gfsh>remove --region=Region1 --all // Remove the entire regionRegion.destroyRegion();
<region name="testREP" refid="REPLICATE"/><disk-store name="testDiskStore" >    <disk-dirs>        <disk-dir>PRPersist1</disk-dir>        <disk-dir>PRPersist2</disk-dir>    </disk-dirs></disk-store><region name="testPR" >    <region-attributes id="testPRPersist"        refid="PARTITION_PERSISTENT" disk-store-name="testDiskStore"/></region>
RegionShortcuts for Peers and ServersThese are the primary options available in the region shortcut settings. The names listed appear in the shortcut identifier alone or in combination, like “PARTITION” in PARTITION, PARTITION_PROXY, and PARTITION_REDUNDANT.Cache Data Storage ModePARTITION . Creates a partitioned region. This is a data store for the region. You can also specify these options with PARTITION:PROXY. Data is not stored in the local cache and the member is a data accessor to the region. This requires other members to create non-proxy copies of the region, so the data is stored somewhere.REDUNDANT. The region stores a secondary copy of all data, for high availability.REPLICATE. Creates a replicated region. This is a data store for the region. You can also specify these options with REPLICATE:PROXY. Data is not stored in the local cache and the member is a data accessor to the region. This requires other members to create non-proxy copies of the region, so the data is stored somewhere.LOCAL. Creates a region private to the defining member.Data EvictionHEAP_LRU. Causes least recently used data to be evicted from memory when the Geode resource manager determines that the cache has reached configured storage limits.Disk StorageYou can specify these alone or in combination:PERSISTENT. Backs up all data to disk, in addition to storing it in memory.OVERFLOW. Moves data out of memory and on to disk, when memory use becomes too high.ClientRegionShortcuts for ClientsThese are the primary options available in the client region shortcut settings. The names listed appear in the shortcut identifier alone or in combination, like “PROXY” in PROXY and CACHING_PROXY.Communication with Servers and Data StoragePROXY. Does not store data in the client cache, but connects the region to the servers for data requests and updates, interest registrations, and so on. The client is a data accessor to the region.CACHING_PROXY. Stores data in the client cache and connects the region to the servers for data requests and updates, interest registrations, and so on.LOCAL. Stores data in the client cache and does not connect the region to the servers. This is a client-side-only region. Note that this is not the same as setting the region’s scope attribute to LOCAL.Data EvictionHEAP_LRU. Causes least recently used data to be evicted from memory when the Geode resource manager determines that the cache has reached configured storage limits.Disk StorageWith the LOCAL and CACHING data storage shortcut options, you can also specify these disk storage options, alone or in combination:PERSISTENT. Backs up all data to disk, in addition to storing it in memory.OVERFLOW. Moves data out of memory and on to disk, when memory use becomes too high.

region的参考创建

<!-- Retrieving and storing attributes --><region-attributes id="myPartition" refid="PARTITION_REDUNDANT">    <partition-attributes local-max-memory="512"/></region-attributes><!-- Two partitioned regions, one colocated with the other --><!-- Attributes are retrieved and applied in the first region --><region name="PartitionedRegion1" refid="myPartition"/><!-- Same stored attributes, modification for this region--><region name="PartitionedRegion2" refid="myPartition">    <region-attributes>        <partition-attributes colocated-with="PartitionedRegion1" />    </region-attributes></region>

使用attributes覆盖region快捷定义属性

<cache>   <region name="exampleRegion" refid="REPLICATE">      <region-attributes statistics-enabled="true">        <entry-idle-time>          <expiration-attributes timeout="10" action="destroy"/>        </entry-idle-time>        <cache-listener>          <class-name>quickstart.SimpleCacheListener</class-name>        </cache-listener>      </region-attributes>    </region></cache>

region建好后,可以修改region的属性

<cache>   <region name="exampleRegion" refid="REPLICATE">      <region-attributes statistics-enabled="true">        <entry-idle-time>          <expiration-attributes timeout="10" action="destroy"/>        </entry-idle-time>        <cache-listener>          <class-name>quickstart.SimpleCacheListener</class-name>        </cache-listener>      </region-attributes>    </region></cache>

命令行修改region

alter disk-store --name=value --region=value --disk-dirs=value(,value)*    [--compressor(=value)] [--concurrency-level=value]    [--enable-statistics=value] [--initial-capacity=value] [--load-factor=value]    [--lru-algorithm=value] [--lru-action=value] [--lru-limit=value]    [--off-heap(=value)] [--remove(=value)]

设置和获取region和entry属性

Region.setUserAttribute(userAttributeObject)Region.getEntry(key).setUserAttribute(userAttributeObject)Region.getUserAttribute()Region.getEntry(key).getUserAttribute()// Attach a user attribute to a Region with database info for table portfolioObject myAttribute = "portfolio"; final Region portfolios =       new RegionFactory().setCacheWriter(new PortfolioDBWriter()).create("Portfolios"); Portfolios.setUserAttribute(myAttribute);//Implement a cache writer that reads the user attribute settingpublic class PortfolioDBWriter extends CacheWriterAdapter {  public void beforeCreate(RegionEvent event) {    table = (String)event.getRegion().getUserAttribute();    // update database table using name from attribute        . . .  }}

从region读出的数据,尽量不要直接修改

Object o = (StringBuffer)region.get("stringBuf");StringBuffer s = (StringBuffer) CopyHelper.copy(o);s.append("Changes to value, added using put.");region.put("stringBuf", s);

gfsh修改和获取region数据

put --key=('id':'133abg125') --value=('firstname':'James','lastname':'Gosling') --region=/region1 --key-class=data.ProfileKey --value-class=data.ProfileDetailsput --key=('133abg124') --value=('Hello World!!') --region=/region2put --key=('100F') --value=('2146547689879658564')  --region=/region1/region12 --key-class=java.lang.Float --value-class=java.lang.Longget --key=('id':'133abg124') --region=region1// Retrieving when key type is a wrapper(primitive)/Stringget --key=('133abg124') --region=/region1/region12 --value-class=data.ProfileDetailsget --key=('100L') --region=/region1/region12 --value-class=data.ProfileDetails --key-class=java.lang.Long
原创粉丝点击