52
13.04.2011 NoSQL Deep Dive mit Cassandra Kai Spichale 1

NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

13.04.2011

NoSQL Deep Dive mit Cassandra

Kai Spichale

1

Page 2: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

NoSQL

13.04.2011 BerlinExpertDays2

Page 3: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

NoSQL

13.04.2011 BerlinExpertDays3

Graph Databases

Wide Column Stores /

Column FamiliesDocument Stores

Key Value / Tupe Stores

Page 4: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Apache Cassandra - eine Definition

“Apache Cassandra is an open source, distributed, decentralized, elastically scalable, highly available, fault-tolerant, tuneably consistent, column-oriented database that bases its distribution design on Amazon‟s Dynamo and its data model on Google‟s Bigtable. Created at Facebook, it is now used at some of the most popular sites on the Web.”

Hewitt, Eben: Cassandra – The Definite Guide, S. 14

13.04.2011 BerlinExpertDays4

Page 5: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Agenda

► Key Features

► Projektgeschichte

► Verteilung mit DHT

► Konsistenz

► Replikatverteilung

► Datenmodell

► Client API

► Fazit

13.04.2011 BerlinExpertDays5

Page 6: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Keyfeatures

► Verteilte, hochizontal skalierbare Datenbank

► Symmetrisches Design

► Hochverfügbar

► Riesige Datenmenge (Petabytes)

► Flexible Partitionierung, Replikatverteilung

► Eventually consistent: ACID ist nicht immer notwendig

► Flexible Trade-offs zwischen Konsistenz und Performance

► Automated Provisioning (Seek Nodes)

► Erweiterbare Multi-Datacenter Unterstützung

► Schemaloses, strukturiertes Datenmodell

13.04.2011 BerlinExpertDays6

Page 7: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Projektgeschichte

► Ursprunglich von facebook entwickelt

► Projektbeginn 2007, seit 2008 Open Source

► Verwendung für Inbox Search:

> Benutzer können ihre Nachrichten nach Absendernamen oder anderenSchlüsselwörtern durchsuchen

> In-house System zum Indexieren (invertierte Indizes) und Speichern der Nachrichten

► Anforderung:

> kostengünstig (Commodity Server)

> inkrementell skalierbar

13.04.2011 BerlinExpertDays7

Page 8: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Verteilung mit DHT

► Ein Distributed Hash Table (DHT) ist ein Klasse von dezentralen verteilten Systemen

► O(1) Knoten-Lookup

► P2P- Netzwerk

► Daten werden möglichst gleichmäßig auf die Knoten verteilt

13.04.2011 BerlinExpertDays8

► Shared-nothing Architecture

► Symmetrisches Design:

> Kein Single Point ofFailure

> Kein zentraler Controller

> Keine Master/Slaves

► Clients können sich mit beliebigen Knoten verbinden

Page 9: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Verteilung mit DHT

13.04.2011 BerlinExpertDays

Hosts Initial Token

A 0

B 4

C 8

D 12

E 16

F 20

G 24

H 28

Partitioner( RowKey ) = Token

Page 10: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Verteilung mit DHT

13.04.2011 BerlinExpertDays

Hosts Initial Token

A 0

B 4

C 8

D 12

E 16

F 20

G 24

H 28

[0,3]

[4,7]

[8,11]

[12,15][16,19]

[20,23]

[24,27]

[28,31]

Partitioner( RowKey ) = Token

Page 11: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Verteilung mit DHT

13.04.2011 BerlinExpertDays

Hosts Initial Token

A 0

B 4

C 8

D 12

E 16

F 20

G 24

H 28

[0,3]

[4,7]

[8,11]

[12,15][16,19]

[20,23]

[24,27]

[28,31]

Beispiel:

Partitioner( „Cassandra“ ) = 7

Partitioner( RowKey ) = Token

Page 12: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Hosts Initial Token

A 0

B 4

C 8

D 12

E 16

F 20

G 24

H 28

Verteilung mit DHT

13.04.2011 BerlinExpertDays12

Hosts Initial Token

A 0

B 21267647932558653966460912964485513215

C 42535295865117307932921825928971026430

D 63802943797675961899382738893456539645

E 85070591730234615865843651857942052860

F 106338239662793269832304564822427566075

G 127605887595351923798765477786913079290

H 148873535527910577765226390751398592505

Tokens sind Integer von 0 bis 2^127

i * (2^127 / N ) für i = 0 .. N-1

z.B. Random Partitioner mit MD5

Page 13: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Verteilung mit DHT

► Verteilung der Daten im Cluster durch Partitioner

► Random Partitioner ( Consistent Hashing )

> Basiert auf MD5

> Implizites Load Balancing

► Order Preserving Partitioner

> Geeignet für Range Slices

> Evtl. ungleiche Verteilung der Daten im Cluster

► Weitere Implementierungen von org.apache.cassandra.dht.IPartitioner

13.04.2011 BerlinExpertDays13

Page 14: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

CAP-Theorem

► CAP:

> Strong Consistency

> High Availability

> Partition Tolerance

► CAP-Theorem nach Eric Brewer besagt, dass ein verteiltes System nicht gleichzeitig alle drei Anforderungen erfüllen kann, sondern höchstens zwei.

► Cassandra ist ein AP-System

13.04.2011 BerlinExpertDays14

Page 15: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

CAP-Theorem

► CA-System:

> Jeder lebende Knoten, der Requests empfängt, sendet Responses

> Netzwerkpartitionen werden nicht berücksichtigt (Implementierungsdetail)

► CP-System:

> Kann bei Netzwerkpartitionen betrieben werden

> Knoten können absichtlich deaktiviert werden, um Konsistenz sicherzustellen

> Verfügbarkeit wird gegen Konsistenz eingetauscht

► AP-System:

> Verfügbar und tolerant gegenüber Partitionen

> Konsistenz kann nicht garantiert werden

13.04.2011 BerlinExpertDays15

Page 16: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

CAP-Theorem

► B und C erhalten Request:

► CA:

> B kann antworten

> C wird blockiert

► CP:

> C kann antworten

> Lock von A wird aufgehoben

► AP:

> B und C können antworten

> Eventuell inkonsistente Daten

13.04.2011 BerlinExpertDays16

A

B

C

D

E

Quorum NodesNon-quorum Nodes

Hält Lock

Page 17: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Konsistenz

► Vertikale vs. horizontale Skalierung

► ACID vs. BASE (basically available, soft state, eventually consistent)

► Eventually consistency

> Synch nach Berlin, asynch nach New York

> Kompromiss zugunsten Verfügbarkeit und Performance

► Cassandra unterstützt verschiedene Konsistenzstufen

13.04.2011 BerlinExpertDays17

Page 18: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Konsistenz

► Verschiedene Konsistenzstufen für Lese- und Schreiboperationen

► Wenn W + R > N, dann (fast) stark konsistent

13.04.2011 BerlinExpertDays18

Level Write Consistency

ZERO Asynchron, ohne Rückmeldung

ANY 1 Knoten (inkl. HintedHandoff Empfänger)

ONE 1 Knoten

QUORUM (N/2)+1 Knoten R + W > N

LOCAL_QUORUM Quorum im lokalen DC

EACH_QUORUM Quorum in allen DCs

ALL N Knoten

Level Read Consistency

ONE 1 Knoten

QUORUM (N/2)+1 Knoten R + W > N

LOCAL_QUORUM Quorum im lokalen DC

EACH_QUORUM Quorum in allen DCs

ALL N Knoten

Page 19: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Konsistenz

► Hinted Handoff: Bei Knotenausfall wird auf einem anderen Knoten ein Hinthinterlassen, sodass die Schreiboperation nachgeholt werden kann

► Read Repair: Synchronisation aller Replikate (evtl. im Background)

► Anti Entropy: Vergleich der Replikate und Aktualisierung

13.04.2011 BerlinExpertDays19

Page 20: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Konsistenzprobleme beim Löschen

► Eventually consistent: Client liest möglicherweise ein Replikat, das noch nicht alle Updates erhalten hat (bei niedriger Konsistenzstufe)

► Gleiches Problem beim Löschen

► Lösung:

> Nicht sofort Löschen, sondern mit Tombstones markieren

> Wenn GCGraceSeconds < Tombstone Alter, dann Löschen

► Konsequenz: Knoten dürfen nicht länger als GCGraceSeconds down sein!

13.04.2011 BerlinExpertDays20

Page 21: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Replikationsverteilung

► Variabler Replikationsfaktor bestimmt die Anzahl der Kopien im Cluster

► Strategien zur Verteilung der Replikate im Cluster:

> Simple Strategy

> Old Network Topology Strategy

> Network Topology Strategy

13.04.2011 BerlinExpertDays21

Page 22: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Replikationsverteilung

► Simple Strategy (Rack-unaware Strategy): Replikate werden auf nachfolgende Knoten im Ring verteilt

► Datacenters und Racks werden nicht beachtet

► Standardstrategie

13.04.2011 BerlinExpertDays22

Data Center 1

Rack 1 Rack 2

Node 1 Node 5

Node 2 Node 6

Node 3 Node 7

Node 4 Node 8

Page 23: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Replikationsverteilung

► Old Network Topology Strategy (Rack-aware Strategy): Heuristik zur Verteilung der Replikate auf verschiedenen Racks und Datacenters

► Rack-aware Snitch ist notwendig

► Höhere Verfügbarkeit

► Höhere Latenz

13.04.2011 BerlinExpertDays23

Data Center 1 Data Center 2

Rack 1 Rack 2 Rack 3 Rack 4

Node 1 Node 5 Node 1 Node 5

Node 2 Node 6 Node 2 Node 6

Node 3 Node 7 Node 3 Node 7

Node 4 Node 8 Node 4 Node 8

Page 24: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Replikationsverteilung

► Network Topology Strategy (Datacenter Shard Strategy): Für jedes DC kann pro Keyspace die Anzahl der Replikate angegeben werden

► Verteilung auf verschiedene Racks innerhalb eines DCs (wenn möglich)

► Rack-ware Snitch ist notwendig

13.04.2011 BerlinExpertDays24

Konfiguration:

DC 1 hat 2 Replikate

DC 2 hat 2 Replikate

Data Center 1 Data Center 2

Rack 1 Rack 2 Rack 3 Rack 4

Node 1 Node 5 Node 1 Node 5

Node 2 Node 6 Node 2 Node 6

Node 3 Node 7 Node 3 Node 7

Node 4 Node 8 Node 4 Node 8

Page 25: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

► Strukturiertes Datenmodell ohne Schema

► Mehr als nur Key-Value-Modell

► Besteht aus den Konzepten:

Cluster

Keyspace

Column Family

Row

SuperColumn

Column

13.04.2011 BerlinExpertDays25

Page 26: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

► Cluster > Keyspace > Column Family > Row > Column

13.04.2011 BerlinExpertDays26

Column

byte[] name

byte[] value

long timestamp

Page 27: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

► Cluster > Keyspace > Column Family > Row

13.04.2011 BerlinExpertDays27

Row

Key Key Key

Column Column Column

byte[] name byte[] name byte[] name

byte[] value byte[] value byte[] value

long timestamp long timestamp long timestamp

Page 28: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

► Cluster > Keyspace > Column Family

13.04.2011 BerlinExpertDays28

Column Family

Key Row

Key Key Key

Column Column Column

Key Row

Key Key

Column Column

Key Row

Key Key Key Key

Column Column Column Column

Page 29: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

13.04.2011 BerlinExpertDays29

• Cluster > Keyspace Keyspace

Column Family

Key Row

Column Column

Key Row

Column

Key Row

Column Column Column

Column Family

Row

Column Column Column

Row

Column Column

Page 30: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

► Cluster > Keyspace > Column Family > Row > SuperColumn

13.04.2011 BerlinExpertDays30

SuperColumn

Key Column

byte[] name

byte[] value

long timestamp

Key Column

byte[] name

byte[] value

long timestamp

Page 31: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

► Cluster > Keyspace > Column Family > Row

13.04.2011 BerlinExpertDays31

Row

Key Key

SuperColumn SuperColumn

Key Column Key Column

byte[] name byte[] name

byte[] value byte[] value

long timestamp long timestamp

Key Column

byte[] name

byte[] value

long timestamp

Page 32: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodell

► Cluster > Keyspace

13.04.2011 BerlinExpertDays32

Keyspace

Column Family

Key Row

Column Column

Key Row

Column

Key Row

Column Column Column

Column Family

Row

SuperColumn SuperColumn

Column Column Column Column

Row

SuperColumn

Column Column Column

Page 33: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodellbeispiel

13.04.2011 BerlinExpertDays33

Column

name = "firstname"

value = "Kai"

Column

name = "lastname"

value = "Spichale"

Page 34: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodellbeispiel

13.04.2011 BerlinExpertDays34

SuperColumn

"firstname" Column

name = "firstname"

value = "Kai"

"lastname" Column

name = "lastname"

value = "Spichale"

Page 35: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodellbeispiel

13.04.2011 BerlinExpertDays35

Row

"user_name"

SuperColumn

"firstname" Column

name = "firstname"

value = "Kai"

"lastname" Column

name = "lastname"

value = "Spichale"

Page 36: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodellbeispiel

13.04.2011 BerlinExpertDays36

"user" Column Family

"42" Row

"user_name"

SuperColumn

"firstname" Column

name = "firstname"

value = "Kai"

"lastname" Column

name = "lastname"

value = "Spichale"

Page 37: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Datenmodellbeispiel – flexible Struktur

13.04.2011 BerlinExpertDays37

"user_name"

SuperColumn

"firstname" Column "firstname6" Column

name = "firstname" name = "firstname"

value = "Karl" value = "Jacob"

"firstname2" Column "firstname7" Column

name = "firstname" name = "firstname"

value = "Theodor" value = "Philipp"

"firstname3" Column "firstname8" Column

name = "firstname" name = "firstname"

value = "Maria" value = "Franz"

"firstname4" Column "firstname9" Column

name = "firstname" name = "firstname"

value = "Nikolaus" value = "Joseph"

"firstname5" Column "firstname10" Column

name = "firstname" name = "firstname"

value = "Johann" value = "Sylvester "

Page 38: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Cassandra vs. MySQL (50GB Daten)

► MySQL

> 300ms write

> 350ms read

► Cassandra

> 0.12ms write

> 15ms read

Quelle: http://www.odbms.org/download/cassandra.pdf, Zugriff 7.4.2011

13.04.2011 BerlinExpertDays38

Page 39: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Schreibvorgang

13.04.2011 BerlinExpertDays39

Page 40: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Schreibvorgang

► Client schickt Write Request zu beliebigen Knoten im Cluster

► Write Request wird sequentiell ins lokale Disk Commit Log geschrieben

► Partitioner bestimmt verantwortliche Knoten

► Verantwortliche Knoten erhalten Write Request und schreiben in lokales Logdatei

► Memtables (Write-back Cache) werden aktualisiert

► Flush auf Festplatte in SSTable und SSTableIndex

► Eigenschaften:

> Kein Lesen, keine Suche, keine Locks

> Sequentieller Festplattenzugriff

> Atomare Vorgang für eine ColumnFamily

> „Always Writable“ (d.h. akzeptiert auch Write Requests bei partiellen Failure)

13.04.2011 BerlinExpertDays40

Page 41: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Lesevorgang

13.04.2011 BerlinExpertDays41

Page 42: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Lesevorgang

► Client schickt Read Request zu beliebigen Knoten im Cluster

► Partitioner bestimmt verantwortliche Knoten

► Warten auf R Antworten

► Warten auf N – R Antworten für Read Repair im Hintergrund

► Eigenschaften:

> Liest mehrere SSTables

> Langsamer als Schreiben

> Skaliert sehr gut

13.04.2011 BerlinExpertDays42

Page 43: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Client API

► „The API is horrible and it produces pointless verbose code in addition tobeing utterly confusing.“

► „The RCP interface is baroque, and too tightly coupled to Cassandra„sinternals.“

13.04.2011 BerlinExpertDays43

Page 44: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Client API

► Cassandra:

> Thrift-Interface bietet für viele Sprachen (Python, Ruby, Java, PHP) die API

> RPC framework

> CQL ab Version 0.8 (SQL-like)

► Aber besser sind high-level Client Libraries:

> Java: Pelops, Hector

> Python: Pycassa

> Ruby: Cassandra

► Object Mapper:

> Kundera: JPA 1.0 Implementierung für Cassandra

> Hecotor: nicht JPA-complaint, kein Entity Relationship Support

13.04.2011 BerlinExpertDays44

Page 45: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Hector

► High-level Cassandra Client

► Open Source: https://github.com/rantav/hector

► Queries:

> Ein Request bezieht sich auf einen Keyspace und eine ColumnFamily

> Einfache Requests mit ColumnQuery / SuperColumnQuery

> *SliceQuery zur Abfrage von Columns, SuperColumns und Sub-Columns

– Column Range

– Row Range

► Sekundärer Index:

> Abfragen mit IndexedSlicesQuery

13.04.2011 BerlinExpertDays45

Page 46: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Hector – ein Beispiel

Cluster myCluster = HFactory.getOrCreateCluster("MyCluster",

"192.168.178.37:9160");

Keyspace keyspace = HFactory.createKeyspace("MyKeyspace",

myCluster);

StringSerializer se = StringSerializer.get();

13.04.2011 BerlinExpertDays46

Page 47: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Hector – ein Beispiel

List<HColumn<String, String>> subColumns = new

ArrayList<HColumn<String, String>>();

subColumns.add(HFactory.createColumn("firstname", "Kai", se, se));

subColumns.add(HFactory.createColumn("lastname", "Spichale", se, se));

HSuperColumn<String, String, String> superColumn = HFactory

.createSuperColumn("UserName", subColumns, se, se, se);

Mutator<String> mutator = HFactory.createMutator(keyspace, se);

mutator.insert("rowKey1", "User", superColumn);

13.04.2011 BerlinExpertDays47

Page 48: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Hector – ein Beispiel

SuperColumnQuery<String, String, String, String> query = HFactory

.createSuperColumnQuery(keyspace, se, se, se, se);

QueryResult<HSuperColumn<String, String, String>> queryResult = query

.setColumnFamily("User").setKey("rowKey1")

.setSuperName("UserName");

queryResult.execute();

HSuperColumn<String, String, String> hSuperColumn = queryResult.get();

13.04.2011 BerlinExpertDays48

Page 49: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Einschränkungen

► Keine Joins

► Kein ORDERED BY, GROUP BY, LIKE

► Kein kaskadierendes Löschen

► Keine referenzielle Integrität

► Konsequenzen für Datenmodellentwurf

> Bereits beim Entwurf des Datenmodells müssen alle Abfragen identifiziert sein

> Zusätzliche Abfragepfade können schwer hinzugefügt werden

> Denormalisierung, sodass jeder Request mit einer oder mehreren Zeilen einer ColumnFamily beantwortet werden kann

> Client macht Joins

13.04.2011 BerlinExpertDays49

Page 50: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Fazit

► Hochskalierbare Datenbank, kann riesige Datenmengen speichern

► Einfache Administration

► Gewöhnungsbedürftiges Modell

► Eventually Consistent

► Keine Standard-Client-Library

► API-Veränderungen

► Upgrade

13.04.2011 BerlinExpertDays51

Page 51: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

Vielen Dank für Ihre Aufmerksamkeit!

Fragen?

13.04.2011 BerlinExpertDays52

Page 52: NoSQL Deep Dive mit Cassandra - bedcon · NoSQL 13.04.2011 3 BerlinExpertDays Graph Databases Wide Column Stores / Column Families Document Stores Key Value / Tupe Stores. Apache

[email protected]

Wir suchen Sie als

Software-Architekt (m/w)

Projektleiter (m/w)

Senior Software Engineer (m/w)