cassandra rapid prototyping with achilles

27
@ doanduyhai www.achilles.io Cassandra rapid prototyping with Achilles 1

Upload: duyhai-doan

Post on 02-Dec-2014

467 views

Category:

Technology


4 download

DESCRIPTION

Presentation of Achilles at NoSQLNow! 2014 conference

TRANSCRIPT

Page 1: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Cassandra rapid prototyping with Achilles

1

Page 2: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

DuyHai DOANJava/Cassandra freelance developer !

!

Daytime: + !

!

At night: +

2

Page 3: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

What is Achilles ?

Yet another C* object mapper

3

Page 4: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

What is Achilles ?

More than a C* object mapper

4

Page 5: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Demo

5

TDD with Achilles

Page 6: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Main API

•manager.insert(entity) !

•manager.update(managedEntity) !

•manager.remove(entity) !

•manager.find(Entity.class, primaryKey)

6

Page 7: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Thread safety for persistence manager

No JOINS means

7

Page 8: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Thread safety for persistence manager

No JOINS means !

!

No complex object graph

8

Page 9: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Thread safety for persistence manager

No JOINS means !

!

No complex object graph !

!

No state to keep

9

Page 10: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

What’s about proxy ?

proxifiedEntity = manager.find(Entity.class, primaryKey)

10

ProxifiedEntity

Real Entity

Dirty check

State

Setters interception

Page 11: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Why proxies ?

User einstein = manager.find(User.class,”emc²”); !

einstein.setCountry(“USA”); !

manager.insert(einstein);

11

emc² Albert EINSTEIN GERMANY

emc² Albert EINSTEIN GERMANY emc² Albert EINSTEIN USA

Waste of space !!

Page 12: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Why proxies ?

User einstein = manager.find(User.class,”emc²”); !

einstein.setCountry(“USA”); !

manager.update(einstein);

12

emc² Albert EINSTEIN GERMANY

emc² Albert EINSTEIN GERMANY USA

Page 13: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

List<Message> entities = manager.sliceQuery(Message.class) .forSelect() .withPartitionComponents(10L) .fromClusterings(“forums”).toClusterings(“forums”, uuid1) .limit(10).fromInclusiveToExclusiveBounds() .get();

Slice query

13

SELECT * FROM Message WHERE user_id = 10 AND (message_folder) ≥ (‘forums’) AND (message_folder, date) < (‘forums’, uuid1) ORDER BY message_folder ASC LIMIT 10;

Page 14: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

RegularStatement select = select().from(“user_messages”) .where(eq(“user_id”,bindMarker())) .and(gte(asList(“message_folder”), bindMarker())) .and(lt(asList(“message_folder”, “date”), bindMarker())) .limit(10);

!

List<Message> messages = manager.typedQuery(Message.class, select, userId, asList(“forums”), asList(“forums”, uuid1)) .get();

Typed query

14

Page 15: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Native query

15

RegularStatement nativeQuery = new SimpleStatement(“SELECT * FROM Message WHERE … LIMIT 20”); !

List<TypedMap> messages = manager.nativeQuery(nativeQuery).get(); !

TypedMap firstMessage = messages.get(0); !

// with normal Map<String, Object>// String interlocutor = (String) map.get(“interlocutor”); !

String interlocutor = firstMessage.getTyped(“interlocutor”); String interlocutor = firstMessage.<String>getTyped(“interlocutor”);

Page 16: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Counter API

Special proxy type

16

public Long get(); !

public void incr(); !

public void incr(Long increment); !

public void decr(); !

public void decr(Long decrement);

Page 17: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Options

•Setting C* special options

•Apply to main API insert(), update(), remove() …

17

manager.insert(user, OptionsBuilder .withConsistency(QUORUM) .ttl(10) .timestamp(1357949499999L) .ifNotExists() );

Page 18: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Lifecycle interceptors

Hooks into persistence lifecycle

18

public interface Interceptor<T> { public void onEvent(T entity); public List<Event> events(); }

!

public enum Event { PRE_PERSIST, POST_PERSIST, PRE_UPDATE, POST_UPDATE, PRE_REMOVE, POST_REMOVE, POST_LOAD; }

Page 19: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Bean Validation (JSR-303)

@Entity(table = “entity”) public class Entity { @Id private Long id; !

@Column @NotEmpty private String name; }

Just a built-in interceptor, PRE_PERSIST, PRE_UPDATE

19

Page 20: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Batch mode

Batch batch = manager.createBatch(); !

batch.startBatch(); !

batch.insert(new Entity(…..)); batch.update(…..); batch.remove(…..); batch.removeById(MyEntity.class, primaryKey); !

batch.endBatch();

C* 2.0 atomic batches

20

Page 21: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Documentation

•Comprehensive Github WIKI !

•Twitter-clone demo app (demo.achilles.io) !

•Versioned documentation (HTML & PDF) !

•JavaDoc

21

Page 22: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Documentation

22

Page 23: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Asynchronous

•Available for ➡ main API ( insert(), update(), …) ➡ slice queries ➡ typed & native queries

23

Page 24: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Roadmap for future

•C* 2.1 user defined types (UDT) & tuples !

•Reactive programming (RxJava) !

•Transparent search integration (ElasticSearch, Solr…)

24

Page 25: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Where to download ?

•www.achilles.io !

•Google “Achilles Cassandra” ☞ first result

25

Page 26: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io

Take away

•More than a simple object mapper !

•Productivity-oriented !

•KISS !

•Documented

26

Page 27: Cassandra rapid prototyping with achilles

@doanduyhaiwww.achilles.io 27

Q & A

! "