Infinispan - NoSQL für den Enterprise Java Alltag

Post on 06-May-2015

255 views 1 download

description

Vortrag auf dem Expertenkreis Java von Christian Dedek, Orientation in Objects GmbH

Transcript of Infinispan - NoSQL für den Enterprise Java Alltag

Infinispan - NoSQL für den Enterprise Java

Orientation in Objects GmbH

Weinheimer Str. 6868309 Mannheim

www.oio.deinfo@oio.deVersion:

Alltag

1.2

Ihr Sprecher

Christian Dedek

Trainer, Berater, Entwickler

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 2

SchwerpunkteSoftwarearchitektur

Qualitätsmanagement Performanceoptimierung

Gliederung

• NoSQL und Java EE

• Infinispan

• Integrationsszenarien

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Ausblick

3

Gliederung

• NoSQL und Java EE

• Infinispan

• Integrationsszenarien

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Ausblick

4

NoSQL vs. Java EE

• NoSQL– Datenspeicher ohne festgelegte Tabellenschemata– skalieren horizontal– keine strenge Spezifikation( viele gut diskutierte/erprobte Konzepte)– viele Implementierungen auf verschiedenen Konzepten basierend

• Java EE– strenge Spezifikation einer Softwarearchitektur

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

– strenge Spezifikation einer Softwarearchitektur – transaktionsbasierte Ausführung von Java-Komponenten– auf transkaktionsbasiertem Konzept beruhende Teilstandards

• JTA/JCA/JPA/JMS/JDBC

– Horizontale Skalierung als Konzept für High Availability• Antwortzeiten• Ausfall von Knoten

– (insbesondere gedacht für Web-Anwendungen)

5

NoSQL

• Dokumentenorientierte Datenbanken• Graphendatenbanken• Key-Value-Stores

– Diskbasiert– RAM-Cache– Sortierte Key-Value-Stores

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Eventually Consistent Stores• MultivalueDatenbanken• Objektdatenbanken• Spaltenorientierte Datenbank

6

CAP-Theorem ( nach E. Brewer PODC Symposium 2000)

• Consistency – roughly meaning that all clients of a data store get responses to

requests that ‘make sense’. For example, if Client A writes 1 then 2 to location X, Client B cannot read 2 followed by 1.

• Availability– all operations on a data store eventually return successfully. We say

that a data store is ‘available’ for, e.g. write operations.

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

that a data store is ‘available’ for, e.g. write operations.

• Partition tolerance– “The network will be allowed to lose arbitrarily many messages sent

from one node to another”– if the network stops delivering messages between two sets of servers,

will the system continue to work correctly?

7

CAP Theorem und JTA

Consistency

JTA JTA

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 8

AvailabilityPartion

Tolerance

n.a.

BASE

JTA JTA

Data Grid vs. Distributed DBMS

Consistency

Data Distributed

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 9

AvailabilityPartion

Tolerance

n.a.

BASE

Data Grid

DistributedDBMS

JSR 107(347) Elastic Data Grid für Java EE

Servlet

Node 1EJB

AppserverJSR 107

Node 1

JSR 107

JSR 107

Node 2

Data Grid

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 10

JSF

Node 3

Node 2

JSR 107

Node 3

Node 2

Secondary Store

JSR 107 API - Standard für einen Distributed HashTable

• Distributed HashTable– javax.cache.Cache

• ähnlich java.util.ConcurrentMap

• Managementschnittstellen– javax.cache.CacheManager– javax.cache..CacheListener

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Annotationen z.B.– @CacheResult,@CacheKeyParam,@CacheRemove.

11

javax.cache.CacheLoader

JEEApplication

Cache

1. Get

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 12

• Secondary Store

CacheLoader

2. load

javax.cache.CacheWriter

JEEApplication

Cache

1. Put

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 13

• Secondary Store

CacheWriter

2. store

Expiration

Cache

I

Y

XMput

get

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 14

F

D

Gliederung

• NoSQL und Java EE

• Infinispan

• Integrationsszenarien

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Ausblick

15

Infinispan

• Key-Value-Store– Distributed HashTable(JSR 107/347)– Transactional (JTA)– Low-latency (RAM)– Optional persist to disk

• Open Source Data Grid Plattform (LGPL)– JBoss/Red Hat

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

– JBoss/Red Hat

• Java and Scala• Nicht nur für die JVM gedacht• in verschiedenen Modi einsetzbar

– Embedded– Client/Server(Data Grid)

16

Consistency

AvailabilityPartion

Tolerance

n.a.

BASE

Infinispan DistributedDBs

Demo

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 17

Local Embedded Mode

JEE

Application

Data Access

UI

0./3. Query

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 18

SecondaryStore

2. Read Cache

1. get4. Read

Local Embedded Mode II

• Code in der gleiche VM wie infinispan• wenig Konfigurationsarbeit

– Mit default EinstellungenDefaultCacheManager cacheManager = new DefaultCacheManager();

Cache<String, String> cache = cacheManager.getCache( );

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

– Mit eigenen Einstellungen z.B: Clustereinstellungen

DefaultCacheManager cacheManager = newDefaultCacheManager(„cluster.xml");

Cache<String, String> cache = cacheManager.getCache( );

19

Infinispan und Java EE Clustering

JEE

Application

Data Access

UI

0./4. Query

JEE

Application

Data Access

UI

0. Update

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 20

Cache

1. get5. get

Cache

1.x Store A1 2. Read A

• Secondary Store

Clustered Embedded Mode

JEE

Application

Data Access

UI

0./4. Query

JEE

Application

Data Access

UI

n.

JEE

Application

Data Access

UI

n+k.

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 21

Cache

2. get5. put

Cache

• Secondary Store

Cache

3./6. load/Store

Demo

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 22

JEEApplication

Data Access

JEEApplication

Data Access

2. Put

0. query

Replication

JEEApplication

Data Access

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

CacheCache

23

Cache

1. Store

• Secondary Store

Replicate Replicate

JEEApplication

Data Access

4. get

3. query

Invalidation

JEEApplication

Data Access

JEEApplication

Data Access

1. Put

0. query

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

Cache

4. get

24

CacheCache

• Secondary Store

Invalidate Invalidate

2. Store

5. load

JEEApplication

Data Access

2. get

0. query

Distribution [numOwner=2]

JEEApplication

Data Access

JEEApplication

Data Access

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

Cache

25

CacheCache

1. Read

• Secondary Store

Copy

Client/Server Mode

Non JavaApplication

Plenty

JEEApplication

Data Access

JSEApplication

Data Access

Hotrod

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 26

Load/Store

JVM

Cache

• Secondary Store

memcachedJVM

Cache

Hotrod

Demo

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 27

Client/Server Mode II

• Starten des Servers erfordert die Angabe des Protokolls– bin/clustered.sh -Djboss.socket.binding.port-offset=xxx -

Djboss.node.name=nodeX

• org.infinispan.client.hotrod.RemoteCacheManagerRemoteCacheManager rcm = new

RemoteCacheManager ("192.168.3.120");

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

RemoteCacheManager ("192.168.3.120");

RemoteCache remoteCace = rcm.getCache();

String key = "hello";

remoteCace.put(key, "world");

28

Client/Server Remoting

RemoteEndpoint

Protokoll Smart Routing

LoadBalancing

Memcached Text - VordefinierteListe

ReSTful Text - http Loadbalancer

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

Loadbalancer

HotRod Binary + DynamischeTopologie

29

JVM

Cache

JEEApplication

Data Access

GroovyApplication

Data Access

CacheStore

JEEApplication

Cache

1. Put

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 30

• Secondary Store

CacheStore

2. store

Eviction

Cache

I

Y

XM FDput

get

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 31

MemorymeterStrategiez.B. LRU

Storage JPA Cache Store

• Implementierung mit JPA 2• Speicherung mit applikationsspezifischem Datenmodell• Key muss Primärschlüssel der Entität sein

– @Id, @EmbeddedId

• Keine generierten Ids

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

Cache<String, User> usersCache = cacheManager.getCache("myJPACache"); // configured f or User entity class

usersCache.put(„Gosling_James", new User());

Cache<Integer, Teacher> teachersCache = cacheManager.getCache("myJPACache"); // cannot do th is whenthis cache is configured to use a JPA cache store

teachersCache.put(1, new Teacher());

32

Storage JPA Cache Store

<namedCache name=„ myJPACache">

<loaders passivation="false" shared="true" preload=" true">

<jpaStore

persistenceUnitName="org.infinispan.loaders.jpa.con figurationTest"

entityClassName="org.infinispan.loaders.jpa.entity. User "

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

er "

/>

</loaders>

</namedCache>

33

Gliederung

• NoSQL und Java EE

• Infinispan

• Integrationsszenarien

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Ausblick

34

DI-Container Integration

DI Container

Tra

nsac

tionI

nter

epto

r

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 35

Rem

oteC

onne

ctor

Ser

vice

Tra

nsac

tionI

nter

epto

r

Cac

he

DA

O

Cac

heS

tore

Spring Integration

• Spring 3.1 Cache Abstraktion• Infinispan Provider • Integration mit Spring DI für CacheManager und Cache

<bean id= "cacheManager"

class= "org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean"

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

actoryBean"

p:configurationFileLocation= "classpath:META-INF/oio-infinispan-config.xml">

</bean>

• Aktivieren des Cache– <cache:annotation-driven />

36

Spring Integration

• Cache Annotation@Cacheable("nachrichtenCache")

public List<Nachricht> findAlleUngeleseneNachrichten () {… }

@Cacheable("nachrichtenCache", key=#" projektId ")

public List<Nachricht> findNachrichtenFuerProjekt(Bi gIntegerprojektId) {… }

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Deklarative Eviction@CacheEvict(value = "nachrichtenCache", allEntries = true)

public void nachrichtMarkieren(BigInteger nachrichtId, booleanungelesen) {… }

37

CDI

• Konfiguration und Injizierung des Infinispan Cache– Cache Injizierung

@Inject

private Cache<String, String> cache;

@Inject

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

@Inject

RemoteCache<String, String> remoteCache;

• Partielle Unterstützung vom JSR 107 Annotationen

38

CDI

• Eigene Cache Qualifier@javax.inject.Qualifier@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface NachrichtenCache {}

public class CacheCreator {

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

public class CacheCreator {@ConfigureCache("nachrichtencache") // cache name.

@NachrichtenCache // cache qualifier.

@Produces

public Configuration specialCacheCfg() {

return new ConfigurationBuilder()

.eviction()

.strategy(EvictionStrategy.LRU)

.maxEntries(10)

.build();

}

}

39

CDI

• Injizierung des eigenen Caches

public class MyCDIComponent {

@Inject @NachrichtenCache

Cache<String, String> nachrichtenCache;

}

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 40

OR/M Integration

Java Virtual Machine

Anwendung

Transient

Transient

PersistenceManager

1.Level Cache

ConnectionInstanzInstanz

Instanz

QueryFacility

Transaction

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH 42

TransientTransient

TransientDB

2.Level Cache

Entity Cache

InstanzInstanz

InstanzInstanz

QueryFacility

QueryCache

TimestampCache

Hibernate 2nd Level Cache

• Entity Cache– Key der Primärschlüssel– Cache lokal(default) oder repliziert – Replizierter Cache nicht empfohlen

• Query Cache– Key ist query-name und Parameter Hash

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

– Key ist query-name und Parameter Hash– Cache lokal(default) oder repliziert

• Timestamps Cache– asynchrone Replikation(default)– keine eviction/expiration

43

Hibernate second level cache

• JTA Transaktion Manager– Hibernate soll/muss JTA Manager nutzen.

<property name= "hibernate.cache.use_second_level_cache" value="true"/>

<property name= "hibernate.cache.use_query_cache" value="true"/>

<property name= "hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>

<property name= "hibernate.cache.infinispan.cfg" value="/oio-infinispan-config.xml"/>

<property name= "hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup"/>

44

Gliederung

• NoSQL und Java EE

• Infinispan

• Integrationsszenarien

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Ausblick

45

Infinispan Ausblick

• Map/Reduce Support

• Versioned Entries

• Support Eventual Consistency (7.0 ?)

Infinispan - NoSQL für den Enterprise Java Alltag© 2014 Orientation in Objects GmbH

• Optimierungen:– Transaktionen– Locking– RPC

46

? ??Fragen ?

Orientation in Objects GmbH

Weinheimer Str. 6868309 Mannheim

www.oio.deinfo@oio.de

??Fragen ?

47

Vielen Dank für ihre

Orientation in Objects GmbH

Weinheimer Str. 6868309 Mannheim

www.oio.deinfo@oio.de

Vielen Dank für ihre Aufmerksamkeit !