Building an IDE for Apache Cassandra
With Eclipse RCP, e4 and XText
Michaël Figuière
Software Architect
© 2014 DataStax, All Rights Reserved.
Cassandra Peer to Peer Architecture
2
Node
Node Node
Node
Node
Node
Clients can reach any of the
Cassandra nodes
Every node have the same role,
there’s no Master or Slave
© 2014 DataStax, All Rights Reserved.
Cassandra Peer to Peer Architecture
3
Node
Node Replica
Replica
Replica
Node
Each partition is stored in
several Replicas to ensure
durability and high availability
© 2014 DataStax, All Rights Reserved.
Linear Scalability
4
Client Writes/s by Node Count - Replication Factor = 3
© 2014 DataStax, All Rights Reserved.
Cassandra Query Language (CQL)
• Similar to SQL, mostly a subset
• Without joins, sub-queries, and aggregations
• Primary Key contains:
• A Partition Key used to select the partition that will store the Row
• Some Clustering Columns, used to define how Rows should be grouped
and sorted on the disk
• Supports Collections
• Supports User Defined Types (UDT)
5
© 2014 DataStax, All Rights Reserved. 6
CQL: Create Table
CREATE TABLE users (
login text,
name text,
age int,
...
PRIMARY KEY (login));
login is the partition key, it will
be hashed and rows will be
spread over the cluster on
different partitions
Just like in SQL!
© 2014 DataStax, All Rights Reserved. 7
CQL: Clustered Table
CREATE TABLE mailbox (
login text,
message_id timeuuid,
interlocutor text,
message text,
PRIMARY KEY(login, message_id)
);
message_id is a clustering column,
it means that all the rows with a
same login will be grouped and
sorted by message_id on the disk
A TimeUUID is a UUID that
can be sorted chronologically
© 2014 DataStax, All Rights Reserved. 8
CQL: Queries
SELECT * FROM mailbox
WHERE login = jdoe
AND message_id = '2014-09-25 16:00:00';
Get message by user and message_id (date)
SELECT * FROM mailbox WHERE login = jdoe
AND message_id <= '2014-09-25 16:00:00'
AND message_id >= '2014-09-20 16:00:00';
Get message by user and date interval
WHERE clauses can only be constraints
on the primary key and range queries are
not possible on the partition key
© 2014 DataStax, All Rights Reserved.
DataStax DevCenter
• Eclipse RCP standalone application
• Eclipse 3.x + e4
• CQL editor based on Xtext
• 1.0.0 in October 2013 - 1.3.0 March 2015
• Supports Cassandra 1.2 - 2.1
• Tens of thousands of downloads / month
9
DataStax DevCenter
Demo
© 2014 DataStax, All Rights Reserved.
Xtext with CQL
11
ValidationCQL Grammar
Content Assist Quick Fixes
Syntax HighlightingFormatting
Can be extracted as a standalone library
© 2014 DataStax, All Rights Reserved. 12
Validation and Quick Fix
Validation
@Fix(CqlConstants.KEYSPACE_EXIST)
public void addIfNotExistst(final Issue issue, IssueResolutionAcceptor acceptor)
{
...
createKeyspaceStmt.setIfNotExists(true);
...
}
Quick Fix
@Check
public void checkKeyspaceNotExist(CreateKeyspaceStatement stmt)
{
if (context.isKeyspaceExistInDatabase(stmt.getKeyspaceEntity()))
error(KEYSPACE_ALREADY_EXISTS, stmt, CqlConstants.KEYSPACE_EXIST);
}
© 2014 DataStax, All Rights Reserved.
Cassandra + Script Context
13
© 2014 DataStax, All Rights Reserved.
Current Schema for Each Statement
14
© 2014 DataStax, All Rights Reserved. 15
Xtext Embedded Editor
@Inject
private EmbeddedEditorFactory factory;
editor = factory
.newEditor(resourceProvider)
.readOnly()
.withResourceValidator(resourceValidator)
.processIssuesBy(issueProcessor)
.withParent(container);
partialEditor = editor.createPartialEditor();
Injected through
Xtext’s Guice context
The SWT Container
the editor should be
inserted in
© 2014 DataStax, All Rights Reserved. 16
Benefits of e4
Dependency Injection
@Inject
IEventBroker broker;
public void doSomething() {
broker.send(TOPIC, "some data");
}
Events Handling
@Inject
public void create(Composite parent, IWorkbenchHelpSystem help) {
Button button = ...;
help.setHelp(button, "com.example.button.help.id");
}
@Inject
public void receive(@EventTopic(TOPIC) Object data) {
fullRefresh();
}
© 2014 DataStax, All Rights Reserved.
DevCenter and e4
• DevCenter cannot be a pure e4 application…
• Relies on Xtext and Eclipse Editor
• Eclipse IDE doesn’t rely on the e4 Application Model yet
• …but can still use e4 through adapters on top of Eclipse 3.x
17
© 2014 DataStax, All Rights Reserved.
E4 in a Eclipse 3.x Plugin
18
DIViewPart Adapter
E4View
Eclipse 3.x Plugin
Eclipse technical
code goes here
Application
logic sits here
Questions?
@mfiguiere
blog.datastax.com
github.com/datastax

EclipseCon - Building an IDE for Apache Cassandra

  • 1.
    Building an IDEfor Apache Cassandra With Eclipse RCP, e4 and XText Michaël Figuière Software Architect
  • 2.
    © 2014 DataStax,All Rights Reserved. Cassandra Peer to Peer Architecture 2 Node Node Node Node Node Node Clients can reach any of the Cassandra nodes Every node have the same role, there’s no Master or Slave
  • 3.
    © 2014 DataStax,All Rights Reserved. Cassandra Peer to Peer Architecture 3 Node Node Replica Replica Replica Node Each partition is stored in several Replicas to ensure durability and high availability
  • 4.
    © 2014 DataStax,All Rights Reserved. Linear Scalability 4 Client Writes/s by Node Count - Replication Factor = 3
  • 5.
    © 2014 DataStax,All Rights Reserved. Cassandra Query Language (CQL) • Similar to SQL, mostly a subset • Without joins, sub-queries, and aggregations • Primary Key contains: • A Partition Key used to select the partition that will store the Row • Some Clustering Columns, used to define how Rows should be grouped and sorted on the disk • Supports Collections • Supports User Defined Types (UDT) 5
  • 6.
    © 2014 DataStax,All Rights Reserved. 6 CQL: Create Table CREATE TABLE users ( login text, name text, age int, ... PRIMARY KEY (login)); login is the partition key, it will be hashed and rows will be spread over the cluster on different partitions Just like in SQL!
  • 7.
    © 2014 DataStax,All Rights Reserved. 7 CQL: Clustered Table CREATE TABLE mailbox ( login text, message_id timeuuid, interlocutor text, message text, PRIMARY KEY(login, message_id) ); message_id is a clustering column, it means that all the rows with a same login will be grouped and sorted by message_id on the disk A TimeUUID is a UUID that can be sorted chronologically
  • 8.
    © 2014 DataStax,All Rights Reserved. 8 CQL: Queries SELECT * FROM mailbox WHERE login = jdoe AND message_id = '2014-09-25 16:00:00'; Get message by user and message_id (date) SELECT * FROM mailbox WHERE login = jdoe AND message_id <= '2014-09-25 16:00:00' AND message_id >= '2014-09-20 16:00:00'; Get message by user and date interval WHERE clauses can only be constraints on the primary key and range queries are not possible on the partition key
  • 9.
    © 2014 DataStax,All Rights Reserved. DataStax DevCenter • Eclipse RCP standalone application • Eclipse 3.x + e4 • CQL editor based on Xtext • 1.0.0 in October 2013 - 1.3.0 March 2015 • Supports Cassandra 1.2 - 2.1 • Tens of thousands of downloads / month 9
  • 10.
  • 11.
    © 2014 DataStax,All Rights Reserved. Xtext with CQL 11 ValidationCQL Grammar Content Assist Quick Fixes Syntax HighlightingFormatting Can be extracted as a standalone library
  • 12.
    © 2014 DataStax,All Rights Reserved. 12 Validation and Quick Fix Validation @Fix(CqlConstants.KEYSPACE_EXIST) public void addIfNotExistst(final Issue issue, IssueResolutionAcceptor acceptor) { ... createKeyspaceStmt.setIfNotExists(true); ... } Quick Fix @Check public void checkKeyspaceNotExist(CreateKeyspaceStatement stmt) { if (context.isKeyspaceExistInDatabase(stmt.getKeyspaceEntity())) error(KEYSPACE_ALREADY_EXISTS, stmt, CqlConstants.KEYSPACE_EXIST); }
  • 13.
    © 2014 DataStax,All Rights Reserved. Cassandra + Script Context 13
  • 14.
    © 2014 DataStax,All Rights Reserved. Current Schema for Each Statement 14
  • 15.
    © 2014 DataStax,All Rights Reserved. 15 Xtext Embedded Editor @Inject private EmbeddedEditorFactory factory; editor = factory .newEditor(resourceProvider) .readOnly() .withResourceValidator(resourceValidator) .processIssuesBy(issueProcessor) .withParent(container); partialEditor = editor.createPartialEditor(); Injected through Xtext’s Guice context The SWT Container the editor should be inserted in
  • 16.
    © 2014 DataStax,All Rights Reserved. 16 Benefits of e4 Dependency Injection @Inject IEventBroker broker; public void doSomething() { broker.send(TOPIC, "some data"); } Events Handling @Inject public void create(Composite parent, IWorkbenchHelpSystem help) { Button button = ...; help.setHelp(button, "com.example.button.help.id"); } @Inject public void receive(@EventTopic(TOPIC) Object data) { fullRefresh(); }
  • 17.
    © 2014 DataStax,All Rights Reserved. DevCenter and e4 • DevCenter cannot be a pure e4 application… • Relies on Xtext and Eclipse Editor • Eclipse IDE doesn’t rely on the e4 Application Model yet • …but can still use e4 through adapters on top of Eclipse 3.x 17
  • 18.
    © 2014 DataStax,All Rights Reserved. E4 in a Eclipse 3.x Plugin 18 DIViewPart Adapter E4View Eclipse 3.x Plugin Eclipse technical code goes here Application logic sits here
  • 19.