SlideShare a Scribd company logo
Dockerizing Cassandra on Modern Linux
Myself & Instaclustr
• Adam Zegelin — Founding Software Engineer & Co-founder of Instaclustr

adam@instaclustr.com · @zegelin
• Managed DataStax Enterprise and Apache Cassandra in the ☁ 

(AWS, Azure, SoftLayer)
• Self-service dashboard — create, manage & monitor clusters
• 24/7/365 support, on-call engineers, uptime guarantee
• Focus on developing your awesome apps — we handle the Cassandra
• Grew from a need for Cassandra in a project
2© 2015. All Rights Reserved.
Nodes — Software Stack
• CoreOS — lightweight OS
• Docker — containerisation of everything
• systemd — service managemen
• journald — logging
• D-Bus — controlling systemd from Java from inside containers
3© 2015. All Rights Reserved.
Initial Implementation
• Amazon Web Services only
• Custom Ubuntu AMI (Amazon Machine Image)
• Based on stock Ubuntu AMI
• 2 AMIs (PV/HVM) × 9 regions = 18 images per version!

(became unmaintainable very quickly)
• Custom cloud-init scripts — RAID disks, fetch config, etc.
• Cassandra installed with apt-get install cassandra / dse
4© 2015. All Rights Reserved.
Initial Implementation — AWS
• We selected instance storage backed AWS instances
• Instance storage is fast (SSDs) and low latency (local disk) but is volatile
— terminate the instance and all your data is gone
• The alternative, EBS (Elastic Block Storage), is basically SAN — slower,
higher latency and originally shared instance network bandwidth
• The newer c4.x and m4.x instances are “EBS optimised” and don’t share these limitations
• Only way to change AMI is to start a new machine
• Not possible to use immutable images with persistent ephemeral data
• Only feasible solution for updates is apt-get install
5© 2015. All Rights Reserved.
• One of the first “Docker Operating Systems”
• Available on every provider we support — AWS, Azure, SoftLayer
• CoreOS has pre-built images
• Small and minimalist — not much userland (not even man!)
• Other useful software — etcd, fleet, etc.

(we currently don’t use them — but maybe in the future)
• In-use by some big players (Rackspace, PlayStation, Instaclustr 😀 )
• Recent funding from Google Ventures
6© 2015. All Rights Reserved.
• Container runtime + standardised image distribution & hosting + ecosystem
• Private image hosting options available, such as quay.io
• Immutable images — Yay! 🎉
• Images running in dev, test and production environments are equal
• Software installs, upgrades and uninstalls are clean
• Components are isolated — potentially conflicting components (different library
versions, JVM versions, etc.) can co-exist
• Even different userland layouts (Ubuntu, Debian, CentOS, etc)
7© 2015. All Rights Reserved.
• We containerise everything — C*, internal services, node
management and monitoring apps
• Single, well understood, image build and deploy process —
docker build & docker push
• Executed via Makefiles — one Make target per image — make push-all builds
and pushes everything
• Helps that all our internal apps are Java-based too
8© 2015. All Rights Reserved.
• Docker gives us immutable images for our components without
instance replacement
• CoreOS handles the rest (OS-level) via in-place updates
• Docker is provider agnostic
• CoreOS runs on all major cloud providers and bare-metal
• The result ☞ Instaclustr-managed C* can run anywhere #
9© 2015. All Rights Reserved.
+
systemd
• CoreOS uses systemd for service management
• systemd supports inter-service dependencies
• e.g. cassandra-backups.service “wants” cassandra.service
• aka, cassandra-backups can only run when cassandra is running
• systemd can automatically restart services
• Instaclustr services are fail-fast
• Cassandra not so much — in some cases — watchdog?
10© 2015. All Rights Reserved.
systemd cont’d
• Manages units of different types — service, timer, target, etc.
• service units manage processes
• timers start services on a schedule (ala cron)
• targets are for grouping/sync points
• cassandra.target “wants” cassandra.service, monitoring.serivce, datastax-
agent.service, backups.timer, etc
• All units can define dependencies and conflicts
• Dependencies of different “strengths” — Wants vs. Requires
• In both directions — Requires and RequiredBy
11© 2015. All Rights Reserved.
Basic Integration
• Cassandra runs as PID 1 in the container
• 1 primary process per container model
• Runs in foreground mode (-f)
• Responds to SIGTERM via docker stop, systemctl stop, etc
• Cassandra data and configuration is persistent on host
• Survives container restart
• Cassandra data and configuration directories mounted from host

docker run -v /var/lib/instaclustr/etc/cassandra:/etc/cassandra …
12© 2015. All Rights Reserved.
Basic Integration cont’d
• Docker containers managed via systemd
• cassandra.service execs docker run cassandra …
• systemctl [start|stop|restart|status|…] cassandra
• Cassandra logging configured to write only to stdout
• systemd logging best practice
• Cassandra ⇢ Docker ⇢ systemd ⇢ journald
• journalctl -u cassandra
13© 2015. All Rights Reserved.
Basic Integration — Issues
• systemd starts dependent units when state is active
• process running = service active — unless configured otherwise
• ∴ dependent units start immediately
• process can hang but service stays active
14© 2015. All Rights Reserved.
Cassandra Startup
• JVM starts quickly
• JMX (nodetool) connectivity is available early
• Objects are exposed where they are constructed
• CQL/Thrift available late
• Can be toggled via cassandra.yaml or JMX/nodetool
• When is Cassandra “running”?
• When does cassandra.service transition from activating to active?
• When do dependent services start?
15© 2015. All Rights Reserved.
D-Bus
• RPC between processes
• Notifications
• Socket-based (typically UNIX sockets, but can be TCP)
• Accessible inside a container — mount the socket

docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd …
• Multiple language bindings, including Java
16© 2015. All Rights Reserved.
D-Bus cont’d
• systemd is controlable via D-Bus
• Control host systemd inside a Docker container
• No need to fork/exec to run systemctl and co.

(in-fact, systemctl is a wrapper around D-Bus calls)
17© 2015. All Rights Reserved.
D-Bus cont’d
Java bindings — dbus-java
systemctl restart cassandra
≝
systemdManager.RestartUnit("cassandra.service", "replace");
18© 2015. All Rights Reserved.
Enhanced Integration
• Service status = “active” — process running, or something more?
• Cassandra java process running vs. C* accepting CQL connections
• CQL clients are dependencies, but shouldn’t start until CQL is available
• Clients could fail-fast on no connectivity
• Will be automatically restarted
• Service will oscillate between active and failed — hard to detect
actual failures
• systemd will eventually timeout or give up — configurable
• JVM startup can be expensive — CPU usage spikes
19© 2015. All Rights Reserved.
Enhanced Integration cont’d
• systemd targets for CQL & Thrift — cassandra-cql.target
• Life-cycle tracks internal C* service
• i.e., Starts when CQL is available — not immediate
• nodetool disablebinary implies systemctl stop cassandra-cql.target
• Services that require CQL connectivity use

WantedBy=cassandra-cql.target
• Starting cassandra-cql.target starts these services too
• Inverse of Wants
20© 2015. All Rights Reserved.
Enhanced Integration cont’d
• Java Agent side-loaded into Cassandra JVM
• Hooks into CQL/Thrift service life-cycle
• Implemented using runtime byte-code modification
• Controls systemd via D-Bus to start/stop associated
target units
• But Cassandra is open-source — why not modify‽
• Agents work with DSE & Apache Cassandra
21© 2015. All Rights Reserved.
Java Agent
• Java Agents (java.lang.instrument)
• java -javaagent:instaclustr-agent.jar …
• premain(…) method called at JVM startup
• can hook into JVM class-loading, transform byte-code, etc.
• Javassist, ASM — byte-code modification libraries
22© 2015. All Rights Reserved.
Hooks
public interface Server {

public void start();



public void stop();
⋮

}
// in CassandraDaemon:
// Thrift

thriftServer = new ThriftServer(rpcAddr, rpcPort, listenBacklog);
⋮

thriftServer.start();
⋮

thriftServer.stop();


// CQL

nativeServer = new org.apache.cassandra.transport.Server(nativeAddr, nativePort);
⋮
nativeServer.start();
⋮
nativeServer.stop();
23© 2015. All Rights Reserved.
Hooks
public static void premain(String agentArgs, Instrumentation inst) {

inst.addTransformer((loader, className, classBeingRedefined, protectionDomain, classfileBuffer) -> {

if (!"org/apache/cassandra/transport/Server".equals(className))

return null;



final ClassPool pool = ClassPool.getDefault();

try {

final CtClass ctClass = pool.get("org.apache.cassandra.transport.Server");

// patch start() and stop() methods of the Server class

{

final CtMethod method = ctClass.getDeclaredMethod("start");

method.insertAfter("com.instaclustr.Agent.serverStarted($0);");

}

{

final CtMethod method = ctClass.getDeclaredMethod("stop");

method.insertAfter("com.instaclustr.Agent.serverStopped($0);");

}



byte[] byteCode = ctClass.toBytecode();

ctClass.detach();



return byteCode; // return the modified byte-code



} catch (final Exception e) {…}



return null;

});

}
// called when Server started — call systemd via dbus-java to start cassandra-cql.target
public static void serverStarted(final CassandraDaemon.Server server) {…}

// called when Server stopped — call systemd via dbus-java to stop cassandra-cql.target

public static void serverStopped(final CassandraDaemon.Server server) {…}
24© 2015. All Rights Reserved.
Docker Limitations and Sore Spots
• docker run is just a TTY proxy — actual container process is under
the docker dæmon process/cgroup
• systemd requires startup & watchdog notifications to originate
from started process, child, or process in same cgroup
• docker crash = all containers go bye-bye
• docker … everything — inc. image downloads & builds — runs as
root in the dæmon!
• processes inside containers are run un-elevated
25© 2015. All Rights Reserved.
Future
• Devel. systemd can now launch Docker containers natively via
machinectl
• Tighter integration with systemd
• Process hierarchy is correct — right cgroup and parents
• Java Agent can notify systemd for startup, status &
watchdog — via JNA + libsystemd
26© 2015. All Rights Reserved.
Thanks!

More Related Content

PDF
Cassandra and docker
PDF
Cassandra on Docker
PDF
Scaling and Managing Cassandra with docker, CoreOS and Presto
PPTX
Cassandra via-docker
PDF
Cassandra and Docker Lessons Learned
PDF
Docker Container Orchestration
PDF
Introduction To Docker
PDF
Docker and Containers for Development and Deployment — SCALE12X
Cassandra and docker
Cassandra on Docker
Scaling and Managing Cassandra with docker, CoreOS and Presto
Cassandra via-docker
Cassandra and Docker Lessons Learned
Docker Container Orchestration
Introduction To Docker
Docker and Containers for Development and Deployment — SCALE12X

What's hot (20)

ODP
Docker - The Linux Container
PDF
Introduction openstack-meetup-nov-28
PDF
Optimizing Docker Images
PDF
Basic docker for developer
PDF
Consuming Cinder from Docker
PDF
Bare Metal to OpenStack with Razor and Chef
PDF
How we dockerized a startup? #meetup #docker
PDF
Docker from A to Z, including Swarm and OCCS
PDF
Docker and containers : Disrupting the virtual machine(VM)
PDF
Wanting distributed volumes - Experiences with ceph-docker
PDF
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
PDF
Orchestrating Docker containers at scale
PDF
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
PPTX
Docker Ecosystem on Azure
PDF
Nebulaworks Docker Overview 09-22-2015
PDF
Docker Intro at the Google Developer Group and Google Cloud Platform Meet Up
PPTX
Hypervisor "versus" Linux Containers with Docker !
PPTX
virtualization-vs-containerization-paas
PDF
Introduction to Docker - Docker workshop @Twitter
PDF
Introduction to docker
Docker - The Linux Container
Introduction openstack-meetup-nov-28
Optimizing Docker Images
Basic docker for developer
Consuming Cinder from Docker
Bare Metal to OpenStack with Razor and Chef
How we dockerized a startup? #meetup #docker
Docker from A to Z, including Swarm and OCCS
Docker and containers : Disrupting the virtual machine(VM)
Wanting distributed volumes - Experiences with ceph-docker
Introduction to Docker and all things containers, Docker Meetup at RelateIQ
Orchestrating Docker containers at scale
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Docker Ecosystem on Azure
Nebulaworks Docker Overview 09-22-2015
Docker Intro at the Google Developer Group and Google Cloud Platform Meet Up
Hypervisor "versus" Linux Containers with Docker !
virtualization-vs-containerization-paas
Introduction to Docker - Docker workshop @Twitter
Introduction to docker
Ad

Similar to DataStax: Dockerizing Cassandra on Modern Linux (20)

PDF
Leveraging Docker and CoreOS to provide always available Cassandra at Instacl...
PDF
Building and running cloud native cassandra
PDF
Keeping OpenStack storage trendy with Ceph and containers
PDF
Cisco: Cassandra adoption on Cisco UCS & OpenStack
PDF
You Call that Micro, Mr. Docker? How OSv and Unikernels Help Micro-services S...
PPTX
Why you’re going to fail running java on docker!
PDF
Docker Application to Scientific Computing
PDF
Drupalcamp es 2013 drupal with lxc docker and vagrant
PPTX
Cassandra on Mesos Across Multiple Datacenters at Uber (Abhishek Verma) | C* ...
PDF
Postgre sql linuxcontainers by Jignesh Shah
PPTX
CoreOS Intro
PDF
Docking postgres
PDF
MayaData Datastax webinar - Operating Cassandra on Kubernetes with the help ...
PPTX
Docker and kubernetes
PDF
docker
PPTX
OSv: probably the best OS for cloud workloads you've never hear of
PPTX
Cassandra on Ubuntu AUTOMATIC Install
PDF
Orchestrating Cassandra with Kubernetes
PDF
Cassandra at teads
PPTX
Webinar: OpenEBS - Still Free and now FASTEST Kubernetes storage
Leveraging Docker and CoreOS to provide always available Cassandra at Instacl...
Building and running cloud native cassandra
Keeping OpenStack storage trendy with Ceph and containers
Cisco: Cassandra adoption on Cisco UCS & OpenStack
You Call that Micro, Mr. Docker? How OSv and Unikernels Help Micro-services S...
Why you’re going to fail running java on docker!
Docker Application to Scientific Computing
Drupalcamp es 2013 drupal with lxc docker and vagrant
Cassandra on Mesos Across Multiple Datacenters at Uber (Abhishek Verma) | C* ...
Postgre sql linuxcontainers by Jignesh Shah
CoreOS Intro
Docking postgres
MayaData Datastax webinar - Operating Cassandra on Kubernetes with the help ...
Docker and kubernetes
docker
OSv: probably the best OS for cloud workloads you've never hear of
Cassandra on Ubuntu AUTOMATIC Install
Orchestrating Cassandra with Kubernetes
Cassandra at teads
Webinar: OpenEBS - Still Free and now FASTEST Kubernetes storage
Ad

More from DataStax Academy (20)

PDF
Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
PPTX
Introduction to DataStax Enterprise Graph Database
PPTX
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
PPTX
Cassandra on Docker @ Walmart Labs
PDF
Cassandra 3.0 Data Modeling
PPTX
Cassandra Adoption on Cisco UCS & Open stack
PDF
Data Modeling for Apache Cassandra
PDF
Coursera Cassandra Driver
PDF
Production Ready Cassandra
PDF
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
PPTX
Cassandra @ Sony: The good, the bad, and the ugly part 1
PPTX
Cassandra @ Sony: The good, the bad, and the ugly part 2
PDF
Standing Up Your First Cluster
PDF
Real Time Analytics with Dse
PDF
Introduction to Data Modeling with Apache Cassandra
PDF
Cassandra Core Concepts
PPTX
Enabling Search in your Cassandra Application with DataStax Enterprise
PPTX
Bad Habits Die Hard
PDF
Advanced Data Modeling with Apache Cassandra
PDF
Advanced Cassandra
Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Cassandra on Docker @ Walmart Labs
Cassandra 3.0 Data Modeling
Cassandra Adoption on Cisco UCS & Open stack
Data Modeling for Apache Cassandra
Coursera Cassandra Driver
Production Ready Cassandra
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 2
Standing Up Your First Cluster
Real Time Analytics with Dse
Introduction to Data Modeling with Apache Cassandra
Cassandra Core Concepts
Enabling Search in your Cassandra Application with DataStax Enterprise
Bad Habits Die Hard
Advanced Data Modeling with Apache Cassandra
Advanced Cassandra

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PPT
Teaching material agriculture food technology
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Chapter 3 Spatial Domain Image Processing.pdf
The AUB Centre for AI in Media Proposal.docx
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Building Integrated photovoltaic BIPV_UPV.pdf
MYSQL Presentation for SQL database connectivity
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Digital-Transformation-Roadmap-for-Companies.pptx
20250228 LYD VKU AI Blended-Learning.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
A Presentation on Artificial Intelligence
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Teaching material agriculture food technology

DataStax: Dockerizing Cassandra on Modern Linux

  • 2. Myself & Instaclustr • Adam Zegelin — Founding Software Engineer & Co-founder of Instaclustr
 adam@instaclustr.com · @zegelin • Managed DataStax Enterprise and Apache Cassandra in the ☁ 
 (AWS, Azure, SoftLayer) • Self-service dashboard — create, manage & monitor clusters • 24/7/365 support, on-call engineers, uptime guarantee • Focus on developing your awesome apps — we handle the Cassandra • Grew from a need for Cassandra in a project 2© 2015. All Rights Reserved.
  • 3. Nodes — Software Stack • CoreOS — lightweight OS • Docker — containerisation of everything • systemd — service managemen • journald — logging • D-Bus — controlling systemd from Java from inside containers 3© 2015. All Rights Reserved.
  • 4. Initial Implementation • Amazon Web Services only • Custom Ubuntu AMI (Amazon Machine Image) • Based on stock Ubuntu AMI • 2 AMIs (PV/HVM) × 9 regions = 18 images per version!
 (became unmaintainable very quickly) • Custom cloud-init scripts — RAID disks, fetch config, etc. • Cassandra installed with apt-get install cassandra / dse 4© 2015. All Rights Reserved.
  • 5. Initial Implementation — AWS • We selected instance storage backed AWS instances • Instance storage is fast (SSDs) and low latency (local disk) but is volatile — terminate the instance and all your data is gone • The alternative, EBS (Elastic Block Storage), is basically SAN — slower, higher latency and originally shared instance network bandwidth • The newer c4.x and m4.x instances are “EBS optimised” and don’t share these limitations • Only way to change AMI is to start a new machine • Not possible to use immutable images with persistent ephemeral data • Only feasible solution for updates is apt-get install 5© 2015. All Rights Reserved.
  • 6. • One of the first “Docker Operating Systems” • Available on every provider we support — AWS, Azure, SoftLayer • CoreOS has pre-built images • Small and minimalist — not much userland (not even man!) • Other useful software — etcd, fleet, etc.
 (we currently don’t use them — but maybe in the future) • In-use by some big players (Rackspace, PlayStation, Instaclustr 😀 ) • Recent funding from Google Ventures 6© 2015. All Rights Reserved.
  • 7. • Container runtime + standardised image distribution & hosting + ecosystem • Private image hosting options available, such as quay.io • Immutable images — Yay! 🎉 • Images running in dev, test and production environments are equal • Software installs, upgrades and uninstalls are clean • Components are isolated — potentially conflicting components (different library versions, JVM versions, etc.) can co-exist • Even different userland layouts (Ubuntu, Debian, CentOS, etc) 7© 2015. All Rights Reserved.
  • 8. • We containerise everything — C*, internal services, node management and monitoring apps • Single, well understood, image build and deploy process — docker build & docker push • Executed via Makefiles — one Make target per image — make push-all builds and pushes everything • Helps that all our internal apps are Java-based too 8© 2015. All Rights Reserved.
  • 9. • Docker gives us immutable images for our components without instance replacement • CoreOS handles the rest (OS-level) via in-place updates • Docker is provider agnostic • CoreOS runs on all major cloud providers and bare-metal • The result ☞ Instaclustr-managed C* can run anywhere # 9© 2015. All Rights Reserved. +
  • 10. systemd • CoreOS uses systemd for service management • systemd supports inter-service dependencies • e.g. cassandra-backups.service “wants” cassandra.service • aka, cassandra-backups can only run when cassandra is running • systemd can automatically restart services • Instaclustr services are fail-fast • Cassandra not so much — in some cases — watchdog? 10© 2015. All Rights Reserved.
  • 11. systemd cont’d • Manages units of different types — service, timer, target, etc. • service units manage processes • timers start services on a schedule (ala cron) • targets are for grouping/sync points • cassandra.target “wants” cassandra.service, monitoring.serivce, datastax- agent.service, backups.timer, etc • All units can define dependencies and conflicts • Dependencies of different “strengths” — Wants vs. Requires • In both directions — Requires and RequiredBy 11© 2015. All Rights Reserved.
  • 12. Basic Integration • Cassandra runs as PID 1 in the container • 1 primary process per container model • Runs in foreground mode (-f) • Responds to SIGTERM via docker stop, systemctl stop, etc • Cassandra data and configuration is persistent on host • Survives container restart • Cassandra data and configuration directories mounted from host
 docker run -v /var/lib/instaclustr/etc/cassandra:/etc/cassandra … 12© 2015. All Rights Reserved.
  • 13. Basic Integration cont’d • Docker containers managed via systemd • cassandra.service execs docker run cassandra … • systemctl [start|stop|restart|status|…] cassandra • Cassandra logging configured to write only to stdout • systemd logging best practice • Cassandra ⇢ Docker ⇢ systemd ⇢ journald • journalctl -u cassandra 13© 2015. All Rights Reserved.
  • 14. Basic Integration — Issues • systemd starts dependent units when state is active • process running = service active — unless configured otherwise • ∴ dependent units start immediately • process can hang but service stays active 14© 2015. All Rights Reserved.
  • 15. Cassandra Startup • JVM starts quickly • JMX (nodetool) connectivity is available early • Objects are exposed where they are constructed • CQL/Thrift available late • Can be toggled via cassandra.yaml or JMX/nodetool • When is Cassandra “running”? • When does cassandra.service transition from activating to active? • When do dependent services start? 15© 2015. All Rights Reserved.
  • 16. D-Bus • RPC between processes • Notifications • Socket-based (typically UNIX sockets, but can be TCP) • Accessible inside a container — mount the socket
 docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd … • Multiple language bindings, including Java 16© 2015. All Rights Reserved.
  • 17. D-Bus cont’d • systemd is controlable via D-Bus • Control host systemd inside a Docker container • No need to fork/exec to run systemctl and co.
 (in-fact, systemctl is a wrapper around D-Bus calls) 17© 2015. All Rights Reserved.
  • 18. D-Bus cont’d Java bindings — dbus-java systemctl restart cassandra ≝ systemdManager.RestartUnit("cassandra.service", "replace"); 18© 2015. All Rights Reserved.
  • 19. Enhanced Integration • Service status = “active” — process running, or something more? • Cassandra java process running vs. C* accepting CQL connections • CQL clients are dependencies, but shouldn’t start until CQL is available • Clients could fail-fast on no connectivity • Will be automatically restarted • Service will oscillate between active and failed — hard to detect actual failures • systemd will eventually timeout or give up — configurable • JVM startup can be expensive — CPU usage spikes 19© 2015. All Rights Reserved.
  • 20. Enhanced Integration cont’d • systemd targets for CQL & Thrift — cassandra-cql.target • Life-cycle tracks internal C* service • i.e., Starts when CQL is available — not immediate • nodetool disablebinary implies systemctl stop cassandra-cql.target • Services that require CQL connectivity use
 WantedBy=cassandra-cql.target • Starting cassandra-cql.target starts these services too • Inverse of Wants 20© 2015. All Rights Reserved.
  • 21. Enhanced Integration cont’d • Java Agent side-loaded into Cassandra JVM • Hooks into CQL/Thrift service life-cycle • Implemented using runtime byte-code modification • Controls systemd via D-Bus to start/stop associated target units • But Cassandra is open-source — why not modify‽ • Agents work with DSE & Apache Cassandra 21© 2015. All Rights Reserved.
  • 22. Java Agent • Java Agents (java.lang.instrument) • java -javaagent:instaclustr-agent.jar … • premain(…) method called at JVM startup • can hook into JVM class-loading, transform byte-code, etc. • Javassist, ASM — byte-code modification libraries 22© 2015. All Rights Reserved.
  • 23. Hooks public interface Server {
 public void start();
 
 public void stop(); ⋮
 } // in CassandraDaemon: // Thrift
 thriftServer = new ThriftServer(rpcAddr, rpcPort, listenBacklog); ⋮
 thriftServer.start(); ⋮
 thriftServer.stop(); 
 // CQL
 nativeServer = new org.apache.cassandra.transport.Server(nativeAddr, nativePort); ⋮ nativeServer.start(); ⋮ nativeServer.stop(); 23© 2015. All Rights Reserved.
  • 24. Hooks public static void premain(String agentArgs, Instrumentation inst) {
 inst.addTransformer((loader, className, classBeingRedefined, protectionDomain, classfileBuffer) -> {
 if (!"org/apache/cassandra/transport/Server".equals(className))
 return null;
 
 final ClassPool pool = ClassPool.getDefault();
 try {
 final CtClass ctClass = pool.get("org.apache.cassandra.transport.Server");
 // patch start() and stop() methods of the Server class
 {
 final CtMethod method = ctClass.getDeclaredMethod("start");
 method.insertAfter("com.instaclustr.Agent.serverStarted($0);");
 }
 {
 final CtMethod method = ctClass.getDeclaredMethod("stop");
 method.insertAfter("com.instaclustr.Agent.serverStopped($0);");
 }
 
 byte[] byteCode = ctClass.toBytecode();
 ctClass.detach();
 
 return byteCode; // return the modified byte-code
 
 } catch (final Exception e) {…}
 
 return null;
 });
 } // called when Server started — call systemd via dbus-java to start cassandra-cql.target public static void serverStarted(final CassandraDaemon.Server server) {…}
 // called when Server stopped — call systemd via dbus-java to stop cassandra-cql.target
 public static void serverStopped(final CassandraDaemon.Server server) {…} 24© 2015. All Rights Reserved.
  • 25. Docker Limitations and Sore Spots • docker run is just a TTY proxy — actual container process is under the docker dæmon process/cgroup • systemd requires startup & watchdog notifications to originate from started process, child, or process in same cgroup • docker crash = all containers go bye-bye • docker … everything — inc. image downloads & builds — runs as root in the dæmon! • processes inside containers are run un-elevated 25© 2015. All Rights Reserved.
  • 26. Future • Devel. systemd can now launch Docker containers natively via machinectl • Tighter integration with systemd • Process hierarchy is correct — right cgroup and parents • Java Agent can notify systemd for startup, status & watchdog — via JNA + libsystemd 26© 2015. All Rights Reserved.