提问者:小点点

无法操作在Spring上下文中为嵌入式Apache Geode缓存服务器定义的区域


我创建了存储库SpringbootGeodeexample用于演示目的。

在Gfsh中启动了一个定位器,并在Spring Boot应用程序中嵌入了缓存服务器,其中一些区域在Spring上下文中定义为嵌入式缓存服务器。现在我可以列出区域,但查询失败

gfsh>describe region --name=Region1
..........................................................
Name            : Region1
Data Policy     : partition
Hosting Members :

gfsh>query --query="select * from /Region1"
Result  : false
Message : Cannot find regions <[/Region1]> in any of the members

gfsh>destroy region --name=Region1
Could not find a Region with Region path "Region1" in this Geode cluster. If region was recently created, please wait for at least jmx-manager-update-rate milliseconds to allow the associated Management resources to be federated.

我可以在Gfsh中创建的区域上执行上述操作,我如何在Spring上下文中创建的区域上执行相同的CRUD操作?

我尝试在定位器和缓存服务器中添加--enable-grouster-配置=true和use-grouster-配置="true",但仍然不起作用。

更多详细信息:缓存服务器应用程序配置:

@SpringBootApplication
@CacheServerApplication
@EnableCacheServer(autoStartup = true, port = 41414)
@ImportResource("classpath:spring-cache-context-cluster-side.xml")
public class CacheServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(CacheServerApplication.class, args);
    }
}

Spring上下文中的区域定义:

<gfe:partitioned-region id="Region1" copies="1">
        <gfe:eviction type="MEMORY_SIZE" threshold="512" action="LOCAL_DESTROY"/>
</gfe:partitioned-region>

根据约翰的评论更新:

更新1:

列表成员显示缓存服务器名称为空,这是根本原因吗?

gfsh>list members
  Name   | Id
-------- | -----------------------------------------------
locator2 | 192.168.1.2(locator2:1396:locator)<ec><v0>:1024
         | 192.168.1.2(6032)<v3>:1025

我试图将注释更改为:

@SpringBootApplication
@CacheServerApplication(name = "MyServer", locators="localhost[10334]", autoStartup = true, port = 41415)
@EnableCacheServer(name = "MyServer", autoStartup = true, port = 41414)
@ImportResource("classpath:spring-cache-context-cluster-side.xml")

但仍然没有运气,服务器名称是空的。

更新2:

我正在使用spring-data-gede 2.0.6。释放gede-core 1.2.1我的maven依赖项:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.RC1</spring-cloud.version>
        <spring-cloud-services.version>1.5.0.RELEASE</spring-cloud-services.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        <dependency>
                <groupId>io.pivotal.spring.cloud</groupId>
                <artifactId>spring-cloud-services-dependencies</artifactId>
                <version>${spring-cloud-services.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

更新3:

Spring-缓存-上下文-集群端. xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:gfe="http://www.springframework.org/schema/geode"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:context="http://www.springframework.org/schema/context"
  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
    http://www.springframework.org/schema/geode http://www.springframework.org/schema/gemfire/spring-geode.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 


    <bean id="pdxSerializer" class="org.apache.geode.pdx.ReflectionBasedAutoSerializer">
        <constructor-arg value="com.WMModel.model.*"/>
    </bean>

    <util:properties id="gemfireProperties">
        <prop key="locators">${geode.cache.server.locators}</prop>
        <prop key="mcast-port">0</prop>
    </util:properties>

    <gfe:cache
        properties-ref="gemfireProperties"
        id="gemfireCache"
        use-cluster-configuration="true"
        pdx-serializer-ref="pdxSerializer" 
        copy-on-read="false" 
        critical-heap-percentage="85" 
        eviction-heap-percentage="80">
       <gfe:transaction-listener> 
            <bean class="com.WMCacheServer.db.op.WmTransactionListener"/>
        </gfe:transaction-listener>
        <gfe:transaction-writer> 
            <bean class="com.WMCacheServer.db.op.WmTransactionWriter"/>
        </gfe:transaction-writer>   
        <gfe:dynamic-region-factory/>     
    </gfe:cache>

    <!-- configure the cache and set the port to 0 for it picks the first available port -->
    <gfe:cache-server 
        id="advanced-config"
        port="${geode.cache.server.port}"
        auto-startup="true"
        cache-ref="gemfireCache" />
    <context:property-placeholder location="classpath:cache-server.properties"/>


    <gfe:partitioned-region id="Region1" copies="1">
        <gfe:eviction type="MEMORY_SIZE" threshold="512" action="LOCAL_DESTROY"/>
    </gfe:partitioned-region>
</beans>

cache-server.properties:

### For complete options list: http://gemfire.docs.gopivotal.com/index.html?q=/reference/topics/gemfire_properties.html ###

### Logging ###
log-level=config

### Turn Off Multi Cast ###
mcast-port=0

### Turn on Statistics ###
statistic-archive-file=stats.gfs
statistic-sample-rate=1000
statistic-sampling-enabled=true

enable-network-partition-detection=false

##Conserve Sockets##
conserve-sockets=false
geode.cache.server.port=40434
#geode.cache.server.locators=peer2.com[10334],localhost[10334]
geode.cache.server.locators=localhost[10334]

共2个答案

匿名用户

您使用哪些版本的Apache Geode和Spring Data Geode?

列表成员的输出是什么?

CacheServerApplication类判断,您的Spring(Data Geode)配置和引导的Apache Geode服务器似乎没有连接到Locator。此外,您可以将配置简化为…

@SpringBootApplication
@CacheServerApplication(name = "MyServer", locators="localhost[10334]"
    autoStartup = true, port = 41414)
@ImportResource("classpath:spring-cache-context-cluster-side.xml")
public class CacheServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(CacheServerApplication.class, args);
    }
}

请注意,我在@CacheServerApplication注释中添加了name属性以显式命名服务器。建议这样做,因为成员名称在集群中必须是唯一的,并且如果您使用同一类启动多个服务器,则默认名称(即SpringBasedCacheServerApplication)将发生冲突。当然,它也会在CacheServer端口号上发生冲突,因为它是硬编码的(即“41414”)。您可以使用配置器或属性进行动态配置。

此外,我已将定位器属性设置为localhost[10334]。您应该将定位器的主机和端口(在“host[port]”格式的字符串中)更改为您的定位器正在运行/侦听成员/客户端连接的主机和端口。

在我的Spring Boot GemFire Server示例存储库中,我有一个Spring配置和引导的Pivotal GemFire服务器示例。我刚刚将此示例升级到Spring Boot 2.0.2。释放。这拉入了Spring Data Kay-SR7,其中包括Spring Data GemFire 2.0.7。释放,它基于Pivotal GemFire 9.1.1。

此外,此示例最初基于Java配置,因为它在SDG中采用了新的基于注释的配置模型。因此,使用XML确实没有意义,因为您也可以在JavaConfig中定义区域。

但是,没关系。我们也可以根据XML稍微调整这个例子。

注意:在我的示例repo中,服务器也是一个独立的服务器/集群,具有自己的Locator和Manager配置。但是,我只是将此配置分离为一个嵌套的静态@Configuration类,该类使用Spring Profile启用(即通过设置System属性-Dprint. profile.active=locator-manager)。启用此配置文件后,您不需要运行独立的Locator,尽管您仍然可以。您只需要注意端口冲突等。无论如何…

我刚刚在我的repo中添加了一个xml-config分支。

然后,我使用SDG的XML命名空间配置了“阶乘”分区区域,导入它,并配置定位器endpoint以连接到外部启动的定位器。

接下来,我运行Gfsh,启动一个Locator并继续运行SpringBootGemFireServer示例类…

$ echo $GEMFIRE
/Users/jblum/pivdev/pivotal-gemfire-9.1.1
$ 
$ gfsh
    _________________________     __
   / _____/ ______/ ______/ /____/ /
  / /  __/ /___  /_____  / _____  / 
 / /__/ / ____/  _____/ / /    / /  
/______/_/      /______/_/    /_/    9.1.1

Monitor and Manage Pivotal GemFire

gfsh>list members
Command 'list members' was found but is not currently available (type 'help' then ENTER to learn about this command)
gfsh>
gfsh>start locator --name=LocatorOne --log-level=config --J=-Dgemfire.http-service-port=0
Starting a Geode Locator in /Users/jblum/pivdev/lab/LocatorOne...
...
Locator in /Users/jblum/pivdev/lab/LocatorOne on 10.0.0.121[10334] as LocatorOne is currently online.
Process ID: 33659
Uptime: 3 seconds
Geode Version: 9.1.1
Java Version: 1.8.0_152
Log File: /Users/jblum/pivdev/lab/LocatorOne/LocatorOne.log
JVM Arguments: -Dgemfire.log-level=config -Dgemfire.enable-cluster-configuration=true -Dgemfire.load-cluster-configuration-from-dir=false -Dgemfire.http-service-port=0 -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class-Path: /Users/jblum/pivdev/pivotal-gemfire-9.1.1/lib/geode-core-9.1.1.jar:/Users/jblum/pivdev/pivotal-gemfire-9.1.1/lib/geode-dependencies.jar

Successfully connected to: JMX Manager [host=10.0.0.121, port=1099]

Cluster configuration service is up and running.


gfsh>list members
   Name    | Id
---------- | -------------------------------------------------
LocatorOne | 10.0.0.121(LocatorOne:33659:locator)<ec><v0>:1024

现在,我继续从我的IDE中启动我的SpringBootGemFireServer示例类。请记住,我没有启用“定位器-管理器”Spring配置文件(即-Dprint. profile.active=(空))。我不想启动嵌入式定位器/管理器,因为我想连接到Gfsh启动的定位器,因此这…

@CacheServerApplication(… locators="localhost[10334]")

在我从IDE运行服务器,连接到这个定位器后…

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.2.RELEASE)

[info 2018/05/11 11:53:36.883 PDT <main> tid=0x1] 
---------------------------------------------------------------------------

  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.

---------------------------------------------------------------------------
Build-Date: 2017-09-08 19:39:04 +0000
Build-Id: root 51
Build-Java-Version: 1.8.0_144
Build-Platform: Linux 4.4.0-62-generic amd64
GemFire-Source-Date: 2017-09-01 21:01:32 +0000
GemFire-Source-Repository: support/9.1
GemFire-Source-Revision: ac20a06062204a8f6ba2acaaf2c7dbc1a3d0cfe0
Product-Name: Pivotal GemFire
Product-Version: 9.1.1
Source-Date: 2017-09-08 19:07:34 +0000
Source-Repository: support/9.1
Source-Revision: e756828d0e631cec47f3d027555c022f0fb0e5cc
Native version: native code unavailable
Running on: /10.0.0.121, 8 cpu(s), x86_64 Mac OS X 10.10.5 
Communications version: 65
Process ID: 33670
...
..
.
[info 2018/05/11 11:53:38.454 PDT <main> tid=0x1] CacheServer Configuration:   port=40404 max-connections=800 max-threads=0 notify-by-subscription=true socket-buffer-size=32768 maximum-time-between-pings=60000 maximum-message-count=230000 message-time-to-live=180 eviction-policy=none capacity=1 overflow directory=. groups=[] loadProbe=ConnectionCountProbe loadPollInterval=5000 tcpNoDelay=true

我可以看到服务器加入了Gfsh中Locator定义的集群…

gfsh>list members
         Name           | Id
----------------------- | --------------------------------------------------
LocatorOne              | 10.0.0.121(LocatorOne:33659:locator)<ec><v0>:1024
SpringBootGemFireServer | 10.0.0.121(SpringBootGemFireServer:33670)<v1>:1025

gfsh>describe member --name=SpringBootGemFireServer
Name        : SpringBootGemFireServer
Id          : 10.0.0.121(SpringBootGemFireServer:33670)<v1>:1025
Host        : 10.0.0.121
Regions     : Factorials
PID         : 33670
Groups      : 
Used Heap   : 52M
Max Heap    : 3641M
Working Dir : /Users/jblum/pivdev/spring-data-examples-workspace/spring-boot-gemfire-server-example/build
Log file    : /Users/jblum/pivdev/spring-data-examples-workspace/spring-boot-gemfire-server-example/build
Locators    : localhost[10334]

Cache Server Information
Server Bind              : 
Server Port              : 40404
Running                  : true
Client Connections       : 0

您还可以看到“阶乘”分区区域由“SpringBootGemFireServer”托管,这也从…

gfsh>list regions
List of regions
---------------
Factorials

gfsh>describe region --name

required --name: Name/Path of the region to be described.; no default value
gfsh>describe region --name=/Factorials
..........................................................
Name            : Factorials
Data Policy     : partition
Hosting Members : SpringBootGemFireServer

Non-Default Attributes Shared By Hosting Members  

 Type  |    Name     | Value
------ | ----------- | ---------
Region | size        | 0
       | data-policy | PARTITION

接下来,我使用数字键访问一个值。

注意:此示例将基于“阶乘”计算的CacheLoader附加到“阶乘”分区区域。

gfsh>get --region=/Factorials --key=3 --key-class=java.lang.Long
Result      : true
Key Class   : java.lang.Long
Key         : 3
Value Class : java.lang.Long
Value       : 6


gfsh>get --region=/Factorials --key=5 --key-class=java.lang.Long
Result      : true
Key Class   : java.lang.Long
Key         : 5
Value Class : java.lang.Long
Value       : 120

最后,我可以查询“阶乘”分区区域中的值,如下所示…

gfsh>query --query="SELECT * FROM /Factorials"
Result : true
Limit  : 100
Rows   : 2

Result
------
6
120

当您“描述”区域时,您可以看到它已被更改(请参阅“size”)。

gfsh>describe region --name=/Factorials
..........................................................
Name            : Factorials
Data Policy     : partition
Hosting Members : SpringBootGemFireServer

Non-Default Attributes Shared By Hosting Members  

 Type  |    Name     | Value
------ | ----------- | ---------
Region | size        | 2
       | data-policy | PARTITION

不管怎样,一切都很好。希望这有帮助!

-约翰

匿名用户

好的,通过更改Maven依赖项解决了。谢谢John!看起来spring-bootspring-data-gede之间存在冲突。希望Geode-spring-boot-starter能尽快发布。我更新的依赖项:

<dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-geode</artifactId>
        <version>2.0.1.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>          
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.shell</groupId>
      <artifactId>spring-shell</artifactId>
      <version>1.2.0.RELEASE</version>
       <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
        </exclusion>
      </exclusions>
    </dependency>