简介

最近公司需要更改一个旧项目,其中涉及到Ignite作为缓存体系,之前使用的缓存框架通常是redis集群,第一次接触Ignite,想把学习、认知过程记录下来。

ignite作为分布式缓存框架, 首先了解到本来项目是分布式,ignite是直接嵌入项目(java)中,ignite是基于JVM的,所以可以完全嵌入java项目中,随着项目启动而启动关闭而关闭 (我理解为相当于java编写了一个map缓存数据,当然别人是可以分布式的、并且可以做分布式计算的),目前遇到的问题是有时候程序运行中 但是ignite线程挂了,失去功能,并且某个节点挂掉 不能转到其他节点(后续发现问题是集群保存数据有三种模式导致部分数据丢失现象)。目标计划把服务独立出来不再嵌入项目中,构建独立的Ignite服务端集群,项目作为一个客户端。

了解Ignite

Ignite是轻量级分布式内存HTAP数据库及计算平台,中文官网https://liyuj.gitee.io/。

发一张我的脑图:

Ignite是一个大容器(相当于mysql的一个连接服务,cache就是一个数据库),里面可以创建cache,数据放在cache里面。Ignite支持完整的SQL、DDL和DML,键-值形式存储数据,其中值得类型可以基本数据类型,也可以是对象Object映射成table-column。

Ignite可以通过key键来取数据,也支持sql语句取数据:

1、创建一个容器cache<String,Object>

2、通过key查询:调用cache.get()/cache.getAll()方法

3、通过sql查询:调用cache.query()

Ignite本身有原生的持久化机制,可以选择是否开启,也可以集成到第三方数据库进行持久化。缓存策略:部门常用的数据可以放在内存中,通过重写CacheStoreAdapter这个类进行自定义持久化策略,如果在内存取不到数据会通过load/loadAll进行查询。举个例子(目前例子都是基于独立服务启动):

server-cache.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?><!-- 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. --><!-- Ignite Spring configuration file to startup grid cache. When starting a standalone Ignite node, you need to execute the following command: {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/example-cache.xml When starting Ignite from Java IDE, pass path to this file to Ignite: Ignition.start("examples/config/example-cache.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!-- IgniteConfiguration --><bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"><!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. --><property name="discoverySpi"><bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"><!--集群之间的交流端口--><property name="localPort" value="48500"/><property name="localPortRange" value="3"/><property name="joinTimeout" value="1000"/><property name="ipFinder"><!-- Uncomment multicast IP finder to enable multicast-based discoveryof initial nodes. --><!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> --><bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"><property name="addresses"><list><!--集群IP--><value>XXX.1.8.1:48500..48503</value><value>XXX.1.8.2:48500..48503</value></list></property></bean></property></bean></property><property name="cacheConfiguration"><list><bean parent="cache-template"><property name="name" value="CACHE_PURE"/><!--持久化存储  --><property name="cacheStoreFactory"><bean class="javax.cache.configuration.FactoryBuilder"factory-method="factoryOf"><!--重写CacheStoreAdapter  --><constructor-arg value="com.xx.xx.cache.manager.store.CollAdapterStoreMgr"/></bean></property><!--建立索引 PureCache是object-table映射 --><property name="indexedTypes"><list><value type="java.lang.Class">java.lang.String</value><value type="java.lang.Class">com.xx.xx.cache.model.PureCache</value></list></property></bean></list></property><property name="clientConnectorConfiguration"><bean class="org.apache.ignite.configuration.ClientConnectorConfiguration"><!--本机IP--><property name="host" value="XXX.1.8.1"/><!--对thin客户端暴露的端口--><property name="port" value="10811"/><property name="portRange" value="10"/></bean></property>  </bean><bean id="cache-template" abstract="true"class="org.apache.ignite.configuration.CacheConfiguration"><!-- 缓存初始大小[默认1500000] --><!--<property name="startSize" value="2000"/>--><!-- 缓存再平衡模式[默认ASYNC异步平衡模式,分布式缓存会马上启动,然后在后台会从其他节点加载所有必要的数据] --><property name="rebalanceMode" value="SYNC"/><!-- 配置主节点和备份部分的同步和异步更新[默认PRIMARY_SYNC客户端节点会等待主节点的写或者提交完成,但不会等待备份节点的更新完成] --><property name="writeSynchronizationMode" value="FULL_SYNC"/><!-- 缓存模式 [PARTITIONED分区模式]--><property name="cacheMode" value="PARTITIONED"/><!--有备份的分区缓存,当设置为PARTITIONED生效 --><property name="backups" value="2"/><!-- 事务-原子化模式[ATOMIC模式因为避免了事务锁,所以性能更好,但是仍然提供了单个数据的原子性和一致性] --><property name="atomicityMode" value="ATOMIC"/><!-- 如果cache中无法取到数据,自动从数据库中搜索并加载 --><property name="readThrough" value="true"/><!-- 自动写入到数据库 --><property name="writeThrough" value="true"/><!-- 热生存时间 --><property name="eagerTtl" value="true"/></bean><!-- ignite --></beans>

Object-table映射PureCache类:

package com.xx.xx.cache.model;import org.apache.ignite.cache.query.annotations.QuerySqlField;import java.io.Serializable;
import java.util.Date;@SuppressWarnings("serial")
public class PureCache implements Serializable {@QuerySqlField(index = true)private Long id;@QuerySqlFieldprivate String name;@QuerySqlFieldprivate String adapterEnglishName;@QuerySqlFieldprivate String interfaceType;@QuerySqlFieldprivate Integer collAdapterType;@QuerySqlFieldprivate String startupPath;@QuerySqlFieldprivate String shutdownPath;@QuerySqlFieldprivate String params;@QuerySqlFieldprivate String memo;@QuerySqlFieldprivate Integer dataType;@QuerySqlFieldprivate String developFactory;@QuerySqlFieldprivate String adapterVersion;@QuerySqlFieldprivate Integer adapterExecuteType;@QuerySqlFieldprivate Date createTime;@QuerySqlFieldprivate Date updateTime;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAdapterEnglishName() {return adapterEnglishName;}public void setAdapterEnglishName(String adapterEnglishName) {this.adapterEnglishName = adapterEnglishName;}public String getInterfaceType() {return interfaceType;}public void setInterfaceType(String interfaceType) {this.interfaceType = interfaceType;}public Integer getCollAdapterType() {return collAdapterType;}public void setCollAdapterType(Integer collAdapterType) {this.collAdapterType = collAdapterType;}public String getStartupPath() {return startupPath;}public void setStartupPath(String startupPath) {this.startupPath = startupPath;}public String getShutdownPath() {return shutdownPath;}public void setShutdownPath(String shutdownPath) {this.shutdownPath = shutdownPath;}public String getParams() {return params;}public void setParams(String params) {this.params = params;}public String getMemo() {return memo;}public void setMemo(String memo) {this.memo = memo;}public Integer getDataType() {return dataType;}public void setDataType(Integer dataType) {this.dataType = dataType;}public String getDevelopFactory() {return developFactory;}public void setDevelopFactory(String developFactory) {this.developFactory = developFactory;}public String getAdapterVersion() {return adapterVersion;}public void setAdapterVersion(String adapterVersion) {this.adapterVersion = adapterVersion;}public Integer getAdapterExecuteType() {return adapterExecuteType;}public void setAdapterExecuteType(Integer adapterExecuteType) {this.adapterExecuteType = adapterExecuteType;}public Date getCreateTime() {return createTime;}public void setCreateTime(Date createTime) {this.createTime = createTime;}public Date getUpdateTime() {return updateTime;}public void setUpdateTime(Date updateTime) {this.updateTime = updateTime;}//</editor-fold>@Overridepublic String toString() {final StringBuilder sb = new StringBuilder("CollAdapterCache{");sb.append("id=").append(id);sb.append(", name='").append(name).append('\'');sb.append(", adapterEnglishName='").append(adapterEnglishName).append('\'');sb.append(", interfaceType='").append(interfaceType).append('\'');sb.append(", collAdapterType=").append(collAdapterType);sb.append(", startupPath='").append(startupPath).append('\'');sb.append(", shutdownPath='").append(shutdownPath).append('\'');sb.append(", params='").append(params).append('\'');sb.append(", memo='").append(memo).append('\'');sb.append(", dataType=").append(dataType);sb.append(", developFactory='").append(developFactory).append('\'');sb.append(", adapterVersion='").append(adapterVersion).append('\'');sb.append(", adapterExecuteType=").append(adapterExecuteType);sb.append(", createTime=").append(createTime);sb.append(", updateTime=").append(updateTime);sb.append('}');return sb.toString();}}

持久化对象CollAdapterStoreMgr:

package com.xx.xx.cache.manager.store;import org.apache.commons.lang3.StringUtils;
import org.apache.ignite.cache.store.CacheStoreAdapter;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.apache.ignite.resources.SpringResource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;import javax.cache.Cache;
import javax.cache.integration.CacheLoaderException;
import javax.cache.integration.CacheWriterException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;public class PureCacheStoreMgr extends CacheStoreAdapter<String, PureCache> {private static Logger logger = LogManager.getLogger(PureCacheStoreMgr .class.getName());@Overridepublic void loadCache(IgniteBiInClosure<String, ParserAdapterCache> clo, Object... args) {}@Overridepublic Map<String, ParserAdapterCache> loadAll(Iterable<? extends String> keys) {/**实现多key个查询**/return super.loadAll(keys);}@Overridepublic ParserAdapterCache load(String key) throws CacheLoaderException {/**实现单个key查询**/return result;}@Overridepublic void write(Cache.Entry<? extends String, ? extends ParserAdapterCache> entry) throws CacheWriterException {/**持久化**/}@Overridepublic void delete(Object key) throws CacheWriterException {/**删除**/}
}

对Ignite的初始化cache配置,如果服务器独立运行的时候,需要把自己额外的jar放进apache-ignite-fabric-2.5.0-bin\libs里面。

了解运行模式

Ignite运行有三种角色

1、服务端(server节点)

数据存储,参与缓存,参与分布式计算...,并且可以嵌入java代码,使项目本身是一个服务节点,也可以独立节点运行部署。集群节点挂了,其他节点会感知。

2、客户端(client节点)

本身不存储数据,可以通过api对服务器节点进行数据存储,参与分布式计算...集群节点挂了,其他节点会感知。

3、瘦客户端(thin client)

thin client不会加入Ignite的集群拓扑,它也不存储数据,也不参与执行计算和流处理。和Ignite原生的client节点不同,它并不感知集群的拓扑结构变化(增加/删除节点后,thin client并不知道),而且一次只能和Ignite集群中的一个节点连接通讯,当该节点失效后,它会从事先配置好节点列表中挑选一个新的节点,重新连接

ignite集群cache数据保存三种模式:

1、LOCAL:本地模式,数据都存储在本地,无数据再平衡,类似常见的存储服务;(查不到数据再做处理)

2、PARTITIONED:分区模式,数据分散到集群中的各个节点,分区模式适合存储数量庞大的数据

3、REPLICATED:复制模式,有数据再平衡过程,主节点(Primary)数据与分区模式的一致,只是复制模式默认备 份了除主节点数据外的其余数据。复制模式适合存储数据量小,增长不快的数据。

部署Ignite集群

安装包下载地址:百度云,提取码:sv74,也可以官网自行下载:https://ignite.apache.org/download.cgi

服务器位置

部署服务器

部署根路径

x.1.8.1

/home/xx/xx/ignite

x.1.8.2

/home/xx/xx/ignite

发布位置

  1. 上传发布包ignite2.5到/home/xx/xx/ignite目录下

修改配置文件 /home/xx/xx/ignite/ignite2.5/config/server-cache.xml

<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">

<property name="addresses">

<list>

<!--添加集群IP地址-->

<value>x.1.8.1:48500..48510</value>

<value>x.1.8.2:48500..48510</value>

</list>

</property>

</bean>

<bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">

<!--修改为本机IP地址-->

<property name="host" value="x.1.8.1"/>

<property name="port" value="10800"/>

<property name="portRange" value="10"/>

</bean>

程序启动

进入目录 /home/xx/xx/ignite/ignite2.5/bin

命令:nohup bash ignite.sh ../config/server-cache.xml &

成功标识:输入tail -1000 nohup.out

控制台监控,按步骤输入命令

  1. bash ignitevisorcmd.sh
  2. Open

找到config/server-cache.xml选择,输入该选择前面的编号,比如:10

3、top    --查看所有节点信息

4、cache  -a  --查看所有库信息

window安装DBeaver

下载DBeaver5.0.2

下载ignite-core-2.5.0.jar

安装DBeaver5.0.2

  1. 安装ignite驱动

数据库 > 驱动管理 > 新建

URL模板:jdbc:ignite:thin://可用的服务器节点IP/

端口:10800

添加文夹:选择下载好的ignite-core-2.5.0.jar

点击查找类选择:org.apache.ignite.IgniteJdbcThinDriver

确认

数据量 > 新建连接 > 选择ignite

不填写账号、密码

测试链接,显示OK

下一步、完成。

Ignite-初识Ignite相关推荐

  1. ignite mysql_apache ignite系列(三):数据处理(数据加载,数据并置,数据查询)

    ​使用ignite的一个常见思路就是将现有的关系型数据库中的数据导入到ignite中,然后直接使用ignite中的数据,相当于将ignite作为一个缓存服务,当然ignite的功能远不止于此,下面以将 ...

  2. 用Apache Ignite实现可扩展的数据网格

    在本文中,我们将先介绍数据网格(Data Grid)的基本概念.属性.以及能够提供的服务,然后讨论如何设计可扩展的数据网格,以满足实际场景的业务需求. 什么是数据网格? 数据网格是一组能够提供共享数据 ...

  3. Apache Ignite剖析

    1.概述 Apache Ignite和Apache Arrow很类似,属于大数据范畴中的内存分布式管理系统.在<Apache Arrow 内存数据>中介绍了Arrow的相关内容,它统一了大 ...

  4. Apache Ignite(五):Ignite的集群部署

    Ignite具有非常先进的集群能力,本文针对和集群有关的技术点做一个简短的介绍,然后针对实际应用的可能部署形式做了说明和对比,从中我们可以发现,Ignite平台在部署的灵活性上,具有很大的优势.\ 1 ...

  5. apache ignite_Kubernetes集群上的Apache Ignite和Spring第1部分:Spring Boot应用程序

    apache ignite 在之前的一系列博客中,我们在Kubernetes集群上启动了一个Ignite集群. 在本教程中,我们将使用先前在Spring Boot Application上创建的Ign ...

  6. apache ignite_Apache Ignite变得简单:第一个Java应用程序

    apache ignite 在本文中,我们将更进一步,让您完成第一个Ignite应用程序的创建,以从分布式缓存中进行读写操作. 作为第一个示例,我们将尽可能简单地向您展示如何用Java编写用于处理Ap ...

  7. apache ignite_Apache Ignite,Hazelcast,Cassandra和Tarantool之间的主要区别

    apache ignite Apache Ignite在世界范围内得到广泛使用,并且一直在增长. 诸如Barclays,Misys,Sberbank(欧洲第三大银行),ING,JacTravel之类的 ...

  8. apache ignite_从In Memory Data Grid,Apache Ignite快速入门

    apache ignite IMDG或内存数据网格不是内存中关系数据库,NOSQL数据库或关系数据库. 它是另一种软件数据存储库. 数据模型分布在单个位置或多个位置的许多服务器上. 这种分布称为数据结 ...

  9. Kubernetes集群上的Apache Ignite和Spring第1部分:Spring Boot应用程序

    在之前的一系列博客中,我们在Kubernetes集群上启动了一个Ignite集群. 在本教程中,我们将使用先前在Spring Boot Application上创建的Ignite集群. 让我们使用Sp ...

  10. Apache Ignite变得简单:第一个Java应用程序

    在本文中,我们将更进一步,让您完成第一个Ignite应用程序的创建,以从分布式缓存中进行读写操作. 作为第一个示例,我们将尽可能简单地向您展示如何用Java编写用于处理Apache Ignite集群数 ...

最新文章

  1. iOS 4.2 SDK安装
  2. MDaemon无法发送加密附件
  3. 虚拟打印机开发日志(一):使用x64 WIN7编译环境编译的完整步骤
  4. Swift 协议protocol
  5. Mysql Engine【innodb,myisam】
  6. From Apprentice To Artisan 翻译 19
  7. 三种安防监控摄像机供电方式,如何合理选择?
  8. MongoDb随笔,PyMongo简单使用
  9. 【算法分析与设计】最大连续子序列和问题
  10. webstorm 10.0.4 注册码
  11. 第4章 MySQL数据库结构优化
  12. 车机没有carlife可以自己下载吗_路咖评:新宝骏的车机系统 革了百度Carlife的命?...
  13. ListView一些特殊属性
  14. IIC控制设计读写EEPROM
  15. SAP中物料质检视图中检验设置和QM采购的应用区别
  16. 1024我的Java上车日记(二)
  17. Dzz任务板初版完成笔记-仿trello可私有部署的一款轻量团队任务协作工具。
  18. Spread / Reast 操作符(...arr / ...obj)
  19. 【机器学习】对数线性模型之Logistic回归、SoftMax回归和最大熵模型
  20. 计算机屏幕出现条纹w7,电脑屏幕出现条纹,教您电脑屏幕出现条纹闪烁怎么解决...

热门文章

  1. async function
  2. 基于C/C++的PCM编码与解码简单实现
  3. 关闭chrome 的内置PDF 查看器
  4. 如何一小时登上微信头脑王者王者段位
  5. 18年7月最新可用QQ坦白说解密方法
  6. QQ互联登陆(Java)
  7. 谷歌SEO优化排名做法详解,看这篇就都懂了
  8. python 快速排名发包_SEO优化快速排名-发包技术
  9. linux日志过大怎么查看,Linux查看日志常用命令
  10. 田申:《个人信息安全规范》的理解与初探