【问题标题】:Cannot operate Regions defined in Spring context for an embedded Apache Geode cache server无法为嵌入式 Apache Geode 缓存服务器操作在 Spring 上下文中定义的区域
【发布时间】:2018-05-11 06:20:11
【问题描述】:

我为演示目的创建了存储库SpringbootGeodeExample

在 Gfsh 中启动了一个定位器,并在 Spring Boot 应用程序中嵌入了缓存服务器,并在 Spring 上下文中为嵌入式缓存服务器定义了一些区域。 现在可以列出 Region,但是查询 & 销毁 Region 失败,执行“describe” Region 显示“Hosting Members”为空。

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 中创建的 Region 上执行上述操作,如何对 Spring 上下文中创建的 Region 执行相同的 CRUD 操作?

我尝试在定位器和缓存服务器中添加 --enable-cluster-configuration=true 和 use-cluster-configuration="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>

根据 John 的评论更新:

更新 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:

我正在使用 弹簧数据geode 2.0.6.RELEASE geode-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-cache-context-cluster-side.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>

缓存服务器属性:

### 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]

【问题讨论】:

  • 您不能使用 Gfsh 销毁在 Spring 上下文中创建的区域。在您的应用程序中直接或间接地注入对这些区域的引用时会发生什么?

标签: gemfire geode spring-data-gemfire


【解决方案1】:

您使用的是什么版本的 Apache GeodeSpring Data Geode

list members 的输出是什么?

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

@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);
    }
}

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

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

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

此外,此示例最初基于 Java 配置,因为它使用了 SDG 中的 new Annotation-based configuration model。因此,使用 XML 确实没有意义,因为您也可以define a Region in JavaConfig

但是,没关系。我们可以稍微调整这个示例,使其也基于 XML。

注意:我的example repo 中的服务器也是一个独立的、独立的服务器/集群,具有自己的定位器和管理器配置。然而,我只是将这个配置分离成一个nested, static @Configuration class,它通过 Spring Profile 启用(即通过设置系统属性-Dspring.profiles.active=locator-manager)。启用此配置文件后,您不需要运行独立的定位器,但您仍然可以。您只需要注意端口冲突等。无论如何...

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

然后,我configuredFactorials”PARTITION Region 使用 SDG 的 XML 命名空间 imported itconfigured Locator 端点连接到外部启动的 Locator。

接下来,我运行 Gfsh,启动定位器并继续运行 SpringBootGemFireServerExample 类...

$ 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 中启动我的 SpringBootGemFireServerExample 类。请记住,我没有启用了“定位器管理器”Spring 配置文件(即-Dspring.profiles.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

您还可以看到“Factorials” PARTITION 区域由“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

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

注意:此示例 attaches 一个 "Factorial" computational based CacheLoader 到“Factorials”分区区域。

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

最后,我可以查询“Factorials”分区区域中的值,就像这样......

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

Result
------
6
120

当你“describe”这个区域时,你可以看到它已经改变了(见“大小”)。

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

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

-约翰

【讨论】:

  • 注意,所有对 Pivotal GemFire 的引用同样适用于带有 Spring Data Geode 的 Apache Geode,尤其是从 SD Kay 开始。我刚刚决定使用 Pivotal GemFire 进行测试,因为目前我的环境已经使用 Pivotal GemFire 而不是 Apache Geode 进行了配置和设置。
  • 谢谢约翰!列表成员显示缓存服务器名称为空,我将添加更多配置的详细信息。
【解决方案2】:

好的,通过更改 Maven 依赖项解决。 谢谢约翰! spring-bootspring-data-geode 之间似乎存在冲突。 希望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>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-09-30
  • 2014-11-13
  • 2019-10-11
  • 1970-01-01
  • 1970-01-01
  • 2011-03-02
  • 1970-01-01
  • 2022-12-03
相关资源
最近更新 更多