\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{connygy} \pdfinfo{ /Title (cassandra-2-0-x.pdf) /Creator (Cheatography) /Author (connygy) /Subject (cassandra 2.0.X Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{cassandra 2.0.X Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{connygy} via \textcolor{DarkBackground}{\uline{cheatography.com/32168/cs/9964/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}connygy \\ \uline{cheatography.com/connygy} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 26th November, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{2.14011 cm} x{2.83689 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{nodetool}} \tn % Row 0 \SetRowColor{LightBackground} bin/nodetool status & get the status of nodes, UN: up + nomal \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} bin/nodetool info -h 127.0.0.1 & detailed infomation of the node 127.0.0.1 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} bin/status ring & get the ring information with the \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.14011 cm} x{2.83689 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{system}} \tn % Row 0 \SetRowColor{LightBackground} bin/cassandra & start the cassandra; with -f run in the foreground \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \$ ps aus | grep cass & get the cassandra pid \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \$ kill pid & close the cassandra service \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{conf/cassandra.yaml} & configuration file \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{config/log4j-server}.properties & where is log fille written, size the max file size \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{cql - crud}} \tn % Row 0 \SetRowColor{LightBackground} source 'filename.cql' & run a file with cql commands \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{insert into} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} insert into \textless{}table\textgreater{} (xxx,xxx) values('xxx','xxx') & insert value to table \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{sstableloader tool} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{select * from \textless{}table\textgreater{}} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{select xxx,xxx from \textless{}table\textgreater{}} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} copy from & import .csv file \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} copy to & export .csv file \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} copy \textless{}table\textgreater{} (xxx,xxx) from 'file path' with header = true and delimiter = '|' & copy csv file example, notice: if a record already there and duplicated with the primary key with the file, thus the record will be simply replaced \tn % Row Count 19 (+ 8) % Row 9 \SetRowColor{white} bin/cassandra-cli & start cli (thrift) \tn % Row Count 20 (+ 1) % Row 10 \SetRowColor{LightBackground} use \textless{}dbname\textgreater{} & cli command, use keyspace \tn % Row Count 22 (+ 2) % Row 11 \SetRowColor{white} list \textless{}tablename\textgreater{} & cli command, list how the table is stored \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{cassandra-cli}} \tn % Row 0 \SetRowColor{LightBackground} bin/cassandra-cli & start cassandra-cli tool \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} use \textless{}keyspace\textgreater{} & go into the keyspace \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} list \textless{}table\textgreater{} & show the storage of the table \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} bin/nodetool flush home\_security & flush the memtable to disk \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} bin/sstable2json /var/lib/cassandra \seqsplit{data/home\_security/activity/home\_security\_activity-jb-1-Data}.db & see the sstable, notice: use the Data.db file \tn % Row Count 12 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{data modeling}} \tn % Row 0 \SetRowColor{LightBackground} no join & no join in cassandra, the query should just work in one talbe \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} select * from \textless{}table\textgreater{} where \textless{}partition key\textgreater{} = 'xxx' and \textless{}primary key\textgreater{} = "xxx" & `where` need to include one partiiton key \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} secondary index & a index beyond the partition key and clustering columns, for each secondary index, cassandra creates a hidden talbe on each node in the cluster, it doesn't improve the speed \tn % Row Count 17 (+ 9) % Row 3 \SetRowColor{white} create a table for each query & this can improve the speed \tn % Row Count 19 (+ 2) % Row 4 \SetRowColor{LightBackground} create index \textless{}index\_name\textgreater{} on \textless{}table\textgreater{} (code\_used) & create a secondary index \tn % Row Count 22 (+ 3) % Row 5 \SetRowColor{white} composite partition key & a partition key with more than one column \tn % Row Count 25 (+ 3) % Row 6 \SetRowColor{LightBackground} create table \textless{}tablename\textgreater{}(XXX XXX, ..., primary key((xxx, xxx), xxx)) & create a composite partition key \tn % Row Count 29 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{cql}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{datastax.com/documentation/cql} & cql documentation \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} bin/cqlsh & start cql comments \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} describe cluster & describe cluster \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} help \textless{}commend\textgreater{} & help \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} exit & exit \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} describe keyspaces & list all the databases \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} describe keyspace \textless{}dbname\textgreater{} & details about the database \tn % Row Count 10 (+ 2) % Row 7 \SetRowColor{white} create keyspace \textless{}dbname\textgreater{} with replication = \{'class':'NetworkTopologyStrategy', 'dc1':3, 'dc2':2\} & create a database across multiple data center \tn % Row Count 15 (+ 5) % Row 8 \SetRowColor{LightBackground} create keyspace \textless{}dbname\textgreater{} with replication = \{'class'='SimpleStrategy', 'replication\_factor'=1\} & create a database in one cluster \tn % Row Count 20 (+ 5) % Row 9 \SetRowColor{white} drop keyspace \textless{}tablename\textgreater{} & delete a database \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} create table \textless{}tablename\textgreater{}(home\_id text, datetime timestamp, event text, code\_used text primary key (home\_id, datetime)) with clustering order by (datetime DESC) & create a table \tn % Row Count 30 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{cql (cont)}} \tn % Row 11 \SetRowColor{LightBackground} drop table \textless{}tablename\textgreater{} & delete table \tn % Row Count 2 (+ 2) % Row 12 \SetRowColor{white} use \textless{}dbname\textgreater{} & use a keyspace \tn % Row Count 3 (+ 1) % Row 13 \SetRowColor{LightBackground} ascii, bigint, blob, boolean, counter, decimal, double, float, inet, int, list, map, set, text, timestamp, uuid, timeuuid, varchar, varint & cql data types \tn % Row Count 10 (+ 7) % Row 14 \SetRowColor{white} primary key & a way to uniquely identify a record in a table \tn % Row Count 13 (+ 3) % Row 15 \SetRowColor{LightBackground} partition key & first primary key, to determine which node store the record. (old name: row key) Partitioner hash the partition key \tn % Row Count 19 (+ 6) % Row 16 \SetRowColor{white} create table \textless{}tablename\textgreater{} (...) with clustering order by (datetime desc) & define the order of table, it default is ascend, if descend, than it takes longer to write, since the record is inserted at the start of a partition, but improves read performance. The order can not be changed by the command "alter \textless{}table\textgreater{}" \tn % Row Count 31 (+ 12) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{applications}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{planetcassandra.org/client-drivers-tool} & cassandra drivers \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Cluster cluster = \seqsplit{Cluster.builder().addContactPoints("127.0.0.1"}, \seqsplit{"127.0.0.2").build();} & build a cluster with java driver, it is better more than one contact point exist \tn % Row Count 7 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{update data}} \tn % Row 0 \SetRowColor{LightBackground} update \textless{}table\textgreater{} set xxx='xxx', xxx='xxx' where xxx='xxx' & update record \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} update location using ttl 100 set XXX=XXX, XXX=XXX where XXX=XXX and XXX= XXX & updating with time to live \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} delete & delete a value in a column, or a row or rows \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} delete column from \textless{}table\textgreater{} where ... & delete the column value where ... \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} delete from \textless{}table\textgreater{} where ... & delete a row where ... \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} truncate & delete all of the rows in a talbe \tn % Row Count 16 (+ 2) % Row 6 \SetRowColor{LightBackground} drop & delete a table or keyspaces \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{drop table \textless{}table\textgreater{}} \tn % Row Count 19 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{drop keyspace \textless{}keyspace\textgreater{}} \tn % Row Count 20 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{tombstone}} \tn % Row 0 \SetRowColor{LightBackground} gc\_grace\_seconds & the minimum existence of the deleted record, it is 864000(10 days) by default \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} compaction & data deleted, then reclaim the disk space from deleted data \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} bin/nodetool compact & manually do the compaction, but it is usually automatically \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} TTL & Time To Live, a way to specify an expiration date for data that is being inserted \tn % Row Count 15 (+ 5) % Row 4 \SetRowColor{LightBackground} insert into location(xxx, xxx) values ('xxx', 'xxx') using ttl 30 & inserted data will live 30 seconds \tn % Row Count 19 (+ 4) % Row 5 \SetRowColor{white} sstable2json \textless{}sstable\textgreater{} & in the records, "d": deletion (after TTL), "e": expire (before TTL) \tn % Row Count 23 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}