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

PPTX
Cassandra via-docker
PDF
Scaling and Managing Cassandra with docker, CoreOS and Presto
PDF
Cassandra and docker
PDF
Cassandra and Docker Lessons Learned
PDF
Docker Container Orchestration
PDF
Leveraging Docker and CoreOS to provide always available Cassandra at Instacl...
PDF
Introduction To Docker
PDF
Introduction openstack-meetup-nov-28
Cassandra via-docker
Scaling and Managing Cassandra with docker, CoreOS and Presto
Cassandra and docker
Cassandra and Docker Lessons Learned
Docker Container Orchestration
Leveraging Docker and CoreOS to provide always available Cassandra at Instacl...
Introduction To Docker
Introduction openstack-meetup-nov-28

What's hot (20)

PDF
Innovating faster with SBT, Continuous Delivery, and LXC
PDF
Wanting distributed volumes - Experiences with ceph-docker
PDF
How we dockerized a startup? #meetup #docker
PDF
Large Scale Data Analytics with Spark and Cassandra on the DSE Platform
PPTX
Building clouds with apache cloudstack apache roadshow 2018
PDF
Basic docker for developer
PDF
Docker and Containers for Development and Deployment — SCALE12X
PDF
Docker and containers : Disrupting the virtual machine(VM)
PPTX
Containers orchestrators: Docker vs. Kubernetes
PPTX
Consuming Cinder from Docker
PPTX
VMware Hybrid Cloud Service - Overview
PPTX
OpenStack Cinder
PPTX
CloudStack Day Japan 2015 - Hypervisor Selection in CloudStack 4.5
PPT
Building your own NSQL store
PDF
Orchestrating Docker containers at scale
ODP
Docker - The Linux Container
PPTX
Hypervisor "versus" Linux Containers with Docker !
PPTX
virtualization-vs-containerization-paas
PDF
Bare Metal to OpenStack with Razor and Chef
PDF
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Innovating faster with SBT, Continuous Delivery, and LXC
Wanting distributed volumes - Experiences with ceph-docker
How we dockerized a startup? #meetup #docker
Large Scale Data Analytics with Spark and Cassandra on the DSE Platform
Building clouds with apache cloudstack apache roadshow 2018
Basic docker for developer
Docker and Containers for Development and Deployment — SCALE12X
Docker and containers : Disrupting the virtual machine(VM)
Containers orchestrators: Docker vs. Kubernetes
Consuming Cinder from Docker
VMware Hybrid Cloud Service - Overview
OpenStack Cinder
CloudStack Day Japan 2015 - Hypervisor Selection in CloudStack 4.5
Building your own NSQL store
Orchestrating Docker containers at scale
Docker - The Linux Container
Hypervisor "versus" Linux Containers with Docker !
virtualization-vs-containerization-paas
Bare Metal to OpenStack with Razor and Chef
Deploying containers and managing them on multiple Docker hosts, Docker Meetu...
Ad

Viewers also liked (20)

PDF
DataStax: Dockerizing Cassandra on Modern Linux
PDF
Cassandra-as-a-Service
PDF
Cassandra Front Lines
PDF
Cassandra Bootstap from Backups
PDF
Micro-batching: High-performance writes
PDF
Securing Cassandra
PDF
Multi-Region Cassandra Clusters
PDF
Instaclustr Webinar 50,000 Transactions Per Second with Apache Spark on Apach...
PDF
Apache Cassandra Management
PDF
Migrating to Cassandra
PPTX
Processing 50,000 events per second with Cassandra and Spark
PPTX
Load Testing Cassandra Applications
PPTX
Economic models for reinventing telco webcast by vision mobile, apigee
PPTX
Apigee centralite io t webinar july 2015 share (2)
PPTX
Hadoop Technology
PPTX
Apigee Insights: Data & Context-Driven Actions
PPTX
Big Data Science with H2O in R
PDF
Introduction to Usergrid - ApacheCon EU 2014
PDF
H2O with Erin LeDell at Portland R User Group
PDF
Rock-solid Magento Deployments (and Development)
DataStax: Dockerizing Cassandra on Modern Linux
Cassandra-as-a-Service
Cassandra Front Lines
Cassandra Bootstap from Backups
Micro-batching: High-performance writes
Securing Cassandra
Multi-Region Cassandra Clusters
Instaclustr Webinar 50,000 Transactions Per Second with Apache Spark on Apach...
Apache Cassandra Management
Migrating to Cassandra
Processing 50,000 events per second with Cassandra and Spark
Load Testing Cassandra Applications
Economic models for reinventing telco webcast by vision mobile, apigee
Apigee centralite io t webinar july 2015 share (2)
Hadoop Technology
Apigee Insights: Data & Context-Driven Actions
Big Data Science with H2O in R
Introduction to Usergrid - ApacheCon EU 2014
H2O with Erin LeDell at Portland R User Group
Rock-solid Magento Deployments (and Development)
Ad

Similar to Cassandra on Docker (20)

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
PDF
Startup guide for kvm on cent os 6
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
Startup guide for kvm on cent os 6

More from Instaclustr (9)

PDF
Apache Cassandra Community Health
PDF
Instaclustr introduction to managing cassandra
PDF
Instaclustr webinar 50,000 transactions per second with Apache Spark on Apach...
PDF
Instaclustr Apache Cassandra Best Practices & Toubleshooting
PPTX
Everyday I’m scaling... Cassandra
PDF
Apache Cassandra in the Cloud
PDF
Introduction to Apache Cassandra
PDF
Cassandra Bootstrap from Backups
PDF
Development Nirvana with Cassandra
Apache Cassandra Community Health
Instaclustr introduction to managing cassandra
Instaclustr webinar 50,000 transactions per second with Apache Spark on Apach...
Instaclustr Apache Cassandra Best Practices & Toubleshooting
Everyday I’m scaling... Cassandra
Apache Cassandra in the Cloud
Introduction to Apache Cassandra
Cassandra Bootstrap from Backups
Development Nirvana with Cassandra

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation theory and applications.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
NewMind AI Monthly Chronicles - July 2025
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...

Cassandra on Docker

  • 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.