Sunday, 6 September 2020

Interview Q and A for Cassandra DB Part - 3

 181. Starting Cassandra 

Bin/Cassandra

Cassandra writes several log messages 

“ State jump to normal”   will   be final message at start 

 

182. Installing and starting Cassandra from a tarball requires extensive setup and configuration.

False

 

183. You must first obtain a license before using DataStax Enteprise edition for development.

False

 

184. What is a repair   ?

Repair is a deliberate action to cope with cluster entropy

Entropy can arise from nodes that were down longer than the hint window, dropped mutations, or other causes 

A repair operates on all of the nodes in replica set by default 

Ensures that all replicas have identical copies of a given partition

Consists of two phases : 

  Build Markle tree of the data per partition

 Replicas then compare the differences between their trees and stream the differences to each other as needed.

 

185. Markle tree exchange ?

Start with the root of the tree ( a list of one hash value)

The origin sends the list of hashes at the current level 

The destination diffs the list of hashes against its own, then requests subtree that are different 

If there are no differences, the request can terminate

Repeat steps 2 and 3 until leaf nodes are reached 

The origin sends the values of the keys in the resulting set 

 

186. Why is repair necessary ?

A node’s data can get inconsistent over time ( Repair is just a maintenance action in this case)

If a node goes down for some time, it misses writes and will need to catch up 

Sometimes it is best to repair a node : 

 

 If the node has been down longer than the length specified in MAX_HINT_WINDOW_IN_MS, the node is out of sync.

Depending on amount of data, might be faster to repair 

 

Sometimes it is better to bring the node back as a new node  :

If there is a significant amount of data, might be faster just to bring in a new node and stream data just to that node 

 

187. What are incremental repairs? 

To avoid the need for constant tree construction, incremental repairs have been introduced 

Idea is to persist already repaired data, and only calculate merkle trees for sstables that haven’t previously undergone repairs 

This allow the repair process to stay performant and lightweight

 

188. What are big data systems?

 Applications involving the "three V's"

•  Volume: gigabytes, growing to terabytes and beyond

•  Velocity: sensor data, click streams, financial transactions

•  Variety: data must be ingested from many different formats

 Characteristics requiring 

•  multi-region availability

•  very fast and reliable response 

•  no single point of failure

 

189. What strategies help manage big data?

•  Distribute data across nodes

•  Relax consistency requirements

•  Relax schema requirements

•  Optimize data to suit actual needs

 

190. What is the NoSQL landscape?

  Four broad classes of non-relational database

•  Graph: data elements each relate to n others in a graph/network

•  Key-Value: keys map to arbitrary values of any data type

•  Document: document sets (JSON) queryable in whole or part

•  Column Family: keys mapped to sets of n-number of typed columns 

 Three key factors help navigate the landscape

•  Consistency: do you get identical results, regardless which node is queried?

 •  Availability: can the cluster respond to very high write and read volumes?

•  Partition Tolerance: is the cluster still available when part of it goes dark?

 

191. What is Cassandra?

Massively linearly scalable NoSQL database

•  Fully distributed, with no single point of failure

•  Free and open source, with deep developer support

•  Highly performant, with near-linear horizontal scaling in proper use cases

• Fully peer-to-peer—no master/slave architecture 
• Data center aware 

No single point of failure, due to horizontal scaling

•  horizontal scaling: add commodity hardware to a cluster

•  vertical scaling: add RAM and CPUs to a specialized high performance box

 

192. When is Cassandra the best solution?

Cassandra excels when you need

•  No single point of failure

•  Real-time writes with live operational data analysis

•  Flexible, easily altered data models

•  Near-linear horizontal scaling across commodity servers 

•  Reliable replication across distributed data centers

•  Clearly defined table schema in a NoSQL environment

 

193. When is Cassandra not the best solution?

Traditional RDBMS excels when you need

•  ACID-compliant transactions, with rollback (e.g., bank transfers)

 •  Justification for high-end hardware

 

194. What are Keyspaces? 

•  A namespace for tables in a cluster 

•  All data will reside in some keyspace 

•  Main function: Control replication 

•  Data with different replication requirements will be in different keyspaces

  •  Somewhat analogous to a schema in the relational model 

 

Replication Factor (RF) and replication strategy specified when creating a keyspace 

•  They may be changed later 

•  Below is the CQL (Cassandra Query Language) to create a keyspace 

•  It uses SimpleStrategy and has an RF of 1 

•  You can change the RF using the ALTER KEYSPACE command

 

CREATE KEYSPACE stockwatcher WITH REPLICATION =
{'class' : 'SimpleStrategy', 'replication_factor': 1};
 

195. What are tables? 

Tables store data in a Cassandra database 

•  Define columns and their metadata (e.g. data type) 

•  Analogous to a relational table 

•  Were called Column Families in the Thrift API 

• CREATE TABLE is used in CQL to define a table 

•  A table must reside in a keyspace 

•  Either selected with USE, or as part of the name of the table, e.g. stockwatcher.user 

•  A table must specify a primary key 

USE stockwatcher;  // Execute any time before the CREATE
CREATE TABLE user ( user)

 

196. What is write operation ?

All writes for a row (including inserts/updates/deletes) are done atomically and in isolation 

• Inserting or updating (multiple) columns in a row is one write operation 

INSERT is Always UPSERT 

• An insert with an existing primary key becomes an update 

• Cassandra will just write the new column value(s) provided 
• Each column inserted will supersede any older values 

• For two concurrent writes with the same primary key, the last write wins 

• i.e. the last write to finish will be returned in subsequent queries 

 

197. What is a cluster? 

• A peer to peer set of nodes 
• Node – one Cassandra instance 
• Rack – a logical set of nodes 
• Data Center – a logical set of racks 

• Cluster – a ring of nodes 

 

198. What are Configuration files ?

• cassandra.yaml 
• One file per node, must agree with other node’s files • Parameters defined throughout 

• cassandra-env.sh • Memory settings • JMX settings 

• log4j-server.properties • Error log settings 

 

199. What key properties are set in cassandra.yaml? 

• cluster_name (default: 'Test Cluster') 

• All nodes in a cluster must have the same value. 

• listen_address (default: localhost) 

• Defines the network interface for gossip connections 

• rpc_address

• Network interface for client connections (0.0.0.0 means all interfaces) 

• rpc_port (default: 9160) 

• port for Thrift client connections

• native_transport_port (default: 9042) 

• port on which CQL native transport listens for clients 

commitlog_directory (default: /var/lib/cassandra/commitlog) 

• Best practice to mount on a separate disk in production (unless SSD) 

• data_file_directories (default: /var/lib/cassandra/data) 

• List of storage directories for data tables (SSTables) 
• saved_caches_directory (default: /var/lib/cassandra/saved_caches) 

• Storage directory for key and row caches 

 

200. What key properties are set in cassandra-env.sh? 

• JVM Heap Size settings 

• MAX_HEAP_SIZE="value" 

• Maximum recommended in production is currently 8G due to current limitations in Java garbage collection 

• HEAP_NEWSIZE="value" 
• Generally set to 1⁄4 of MAX_HEAP_SIZE 

• This file computes the default values, but you can override them as necessary.

 

201. What key properties are set in log4j-server.properties? 

• Cassandra system.log location 
• Default location is /var/log/cassandra/system.log 

• system.log is numerically renamed as it grows over time 

• Cassandra logging level 
• Default logging level is INFO

 

202. What is a node? 

•  Single node database 

•  rpc_address—used to setup how clients come into a cluster 

•  rpc_port (9160)—thrift, how node talks to the application 

•  native_transport_port (9042)—native connections 

•  default—localhost which means you are stuck with only local clients 

 • 0.0.0.0 means clients can come in from anywhere 

 

203. What is a cluster? 

• Nodes join a cluster based on the configuration of their own conf/cassandra.yaml file 

• Key settings include 
• cluster_name – shared name to 

logically distinguish a set of nodes 

• seeds – IP addresses of initial nodes for a new node to contact and discover the cluster topology (best practice to use the same two per data center) 

• listen_address – IP address to determine adaptor through which this particular node communicates to other nodes

204. Where does my data go? 

• Cassandra automatically shards your data. 
• It will put one or more copies of your data on your nodes. 

 

205. What is consistent hashing? 

• Data is stored on nodes in partitions, each identified by a partition key. 

•  Partition – a storage location on a node (analogous to a "table row") 

•  Token – 64 bit integer, generated by a hashing algorithm, identifying a partition's location within a cluster 

• The 264 value token range for a cluster is used as a single ring 

•  So, any partition in a cluster is locatable from one consistent set of hash values, regardless of its node 

•  Specific token range varies by choice of partitioner 

•  Partitioner options discussed ahead 

 

206. What is the partitioner? 

• A system on each node which hashes keys to create a token from designated values in rows being added 

• Hash function – converts a variable length value to a corresponding 
fixed length value 

·       Various partitioners available 

Imagine a 0 to 100 token range (instead of -263 to +263) 

• Each node is assigned a token, just like each of its partitions 

• Node tokens are the highest value in the segment owned by that node 

• This segment is the primary token range of replicas owned by this node 

• Nodes also store replicas keyed to tokens outside this range ("secondary range") 

 

207. How does a partitioner work? 

• A node's partitioner hashes a token 100 from the partition key value of a write request 

• First replica written to node that owns the primary range for this token 

The primary key of a table  determines its partition key values 

Partitioner 

Token 91 'Orange:Oscar' 

 

208. How is data replicated among nodes? 

• SimpleStrategy – create replicas on nodes subsequent  to the primary range node 

CREATE KEYSPACE demo WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':3} 
• replication factor of 3 is a recommended minimum 

 

209. is data replicated between data centers? 

• NetworkTopologyStrategy – distribute replicas across racks and data centers 

CREATE KEYSPACE demo WITH REPLICATION = {'class':'NetworkTopologyStrategy', 

'dc-east':2, 'dc-west’:3} 

 

210. What are virtual nodes? 

• Multiple smaller primary range segments – virtual nodes – can be owned by each machine, instead of one larger range 

•  virtual nodes behave like a regular node 

•  available in Cassandra 1.2+

•  default is 256 per machine 

•  not available on nodes combining Cassandra with Solr or Hadoop 

 

211. How are virtual nodes helpful? 

•  token ranges are distributed, so machines bootstrap faster 

•  impact of virtual node failure is spread across entire cluster 

•  token range assignment automated 

Virtual nodes are enabled in cassandra.yaml

• partitions, regular nodes, and virtual nodes are each identified by a token 

• regular or virtual node tokens are the highest value in one segment of the total token range for a cluster, which is the primary range of that node

 

212. What is a coordinator? 

• The node chosen by the client to receive a particular read or write request to its cluster 

• Any node can coordinate any request 

Each client request may be coordinated by a different node 

 

Coordinator Nodes: Its a node which receive the request from client and send the request to the actual node[hash(key) => token] depending upon the token. So all the nodes acts as coordinator node,because every node can receive a request and proxy that request.

 

 

213. What is No single point of failure 

This principle is fundamental to Cassandra's architecture 

 

214. How are client requests coordinated? 

•  The Cassandra driver chooses the node to which each read or write request is sent 

•  Client library providing APIs to manage client read/write requests 

•  Round-robin pattern by default 

The coordinator manages the Replication Factor (RF) 

• Replication factor (RF) – onto how many nodes should a write be copied? 

•  Possible values range from 1 to the total of planned nodes for the cluster 

•  RF is set for an entire keyspace, or for each data center, if multiple 

·       Every write to every node is individually time-stamped 

·       The coordinator also applies the Consistency Level (CL) 

• Consistency level (CL) – how many nodes must acknowledge a read or write request 

•  CL may vary for each request 

•  On success, coordinator notifies client 

• Possible consistency levels include 

• ONE 
• QUORUM(RF/2)+1 

• ALL 

 

215. What is consistency? 

Consistency means to synchronize and how up-to-date a row of Cassandra data is on all of its replicas.

 

• The partition key determines which nodes are sent any given request 

• Consistency Level – sets how many of the nodes to be sent a given request must acknowledge that request, for a response to be returned to the client 

• The meaning varies by type 
• Write request – how many nodes must acknowledge they received and wrote the write request? • Read request – how many nodes must acknowledge by sending their most recent copy of the data? 

 

216. What is immediate vs. eventual consistency? 

• For any given read, how likely is it the data may be stale? 
• Immediate Consistency – reads always return the most recent data 

• Consistency Level ALL guarantees immediate consistency, because all replica nodes are checked and compared before a result is returned 

• Highest latency because all replicas are checked and compared 

• Eventual Consistency – reads may return stale data 

• Consistency Level ONE carries the highest risk of stale data, because the replica from the first node to respond is immediately returned 

• Lowest latency because the first replica is immediately returned 

 

217. What does it mean to tune consistency? 

• Reads and writes may each be set to a specific consistency level 

if (nodes_written + nodes_read) > replication_factor 
then immediate consistency 

 

218. How do you choose a consistency level? 

• In any given scenario, is the value of immediate consistency worth the latency cost? 

• Netflix uses CL ONE and measures its "eventual" consistency in milliseconds 

• Consistency Level ONE is your friend ... 

Consistency Level ONE 

Consistency Level QUORUM 

Consistency Level ALL 

Lowest latency 

Higher latency (than ONE) 

Highest latency 

Highest throughput 

Lower throughput 

Lowest throughput 

Highest availability 

Higher availability (than ALL) 

Lowest availability 

Stale read possible 
(if read CL + write CL < RF) 

No stale reads 
(if read and write at quorum) 

page37image14864

No stale reads 
(if either read or write at ALL) 

page37image16056

• If "stale" is measured in milliseconds, how much are those milliseconds worth? 

 

219. What is the Gossip protocol? 

• Once per second, each node contacts 1 to 3 others, requesting and sharing updates about 

•  Known node states ("heartbeats") 

•  Known node locations 

•  Requests and acknowledgments are timestamped, so information is continually updated and discarded 

 

220. What is write path 

• On a write, Cassandra first appends writes to the commit log on disk 

• The write is durable once the data is in the commit log 
• Actually - once fsync is called and the OS flushes its own cache to disk 

• The commit log is append only, so there is no seek necessary for the append 

• Assuming a dedicated disk for the commit log (a recommended practice) 

• A write also stores the data in memory

• In a structure called the memtable

• A write is successful once written to the commit log and memory 

• Very fast -Very little disk I/O at time of write 

 

221. Details of Memtables and SSTables 

•  Memtables are organized in sorted order by partition key 

•  There is one memtable per table per node 

•  Updates to a column values in the memtable overwrites the existing column values 

•  Accessing them is very fast since they are in-memory 

•  Updates are also merged in-memory for a given partition key 

•  Memtables are eventually flushed to SSTables (Sorted String Tables) on disk 

•  So they don't grow too large in memory 

• Flushed using sequential I/O - no random seeking so it's fast 

• SSTables are immutable once they are written to disk 

•  Updates to data already in an SSTable go into a memtable, then eventually into a different SSTable 

• So data for a given partition key may be in several places 

After flushing, the memtable is emptied. 

 

222. About SSTables 

• SSTable is immutable once it is written
– Mutations to keys already in an SSTable eventually end up in another SSTable – Never any updates to existing data in SSTable
– Meaning no disk seeks on write - speeds up writes 

• Reads may need to go to multiple SSTables for a given key
– Because multiple writes may have created fragments in multiple SSTables for a given key 

• SSTables contain structures to speed up reads – Bloom filters and indexes

223. What is Compaction 

• Compaction: Merges SSTables for a data table into one SSTable - eliminating fragments 

• Reduces number of SSTables to be accessed for a read request 
• Runs asynchronously in the background 
• Uses sequential I/O - fast 
• When merging multiple column values, latest timestamped value is used

 

224. What is data availability & access in Cassandra ?

• Cassandra must access multiple locations to read data 

• Across replicas 
• Data can be replicated across multiple replicas 
• Replicas may not be consistent at any given time (eventual consistency) 

• Within a replica, data may be 

• In an unflushed memtable 
• In multiple SSTables 
• In a cache 

 

225. What is Client read requests 

• Client requests are made to a coordinator 
• The coordinator contacts replicas based on the request CL (1) 

• In the request below, we have RF=3 (data on nodes R1, R2, and R3) 

• Assume CL=QUORUM - so the coordinator contacts two replicas - in this case R1 and R3 

 

226. What is Merging replica data 

•  The coordinator may read data from multiple replicas 
• The data may not be consistent (a write may not have propagated) 

•  If multiple replicas are contacted, the rows from each replica are compared for consistency 

• If consistent, then the data is just returned 
• If not consistent, then the most recent data is used 

• Based on the timestamp value that is contained in the internal storage cell 

•  Cassandra uses a mechanism, read repair, to ensure that all replicas are updated to the latest version of data

 

227. How Read processing in a node 

• To satisfy a read request for a given partition key, a node combines data from 

– Any unflushed memtables
– All SSTables on the node that contain data for that partition key 

 

228. how to Optimizing reads by bloom filters 

• Cassandra uses Bloom filters to minimize SSTable reads

 • Each SSTable read is a disk I/O, so we want to minimize them 

• Bloom filters are used to check if an SSTable has data for a particular partition key 

•  One per SSTable 

•  Saved on disk, but kept in memory (off heap) 

•  On a read, the node checks the Bloom filter for each SSTable 

•  The SSTable is only read from disk if the Bloom filter indicates there is data for the key 

•  This helps make Cassandra very performant on reads

 

229. What is Full read path 

•  Row Cache (off heap): If found here, just return the data, otherwise continue with steps below 

•  Memtable (on heap): Read current memtable, and memtables awaiting flush. Get row fragments for the given row. 

•  Bloom Filter (off heap): Check for each SSTable to build list of candidate SS Tables 

•  Key Cache (on heap): (If enabled) For each SSTable from above, probe the key cache to get position in data file. This may miss. 

•  SSTable Index summary (on heap): Probe here to find start of range in index file, seek to this position in the index file, then scan until you find the key 

•  SSTable (on disk): Seek to the row position in the SSTable and get the data 

•  Merge all row fragments, and reconcile duplicates via timestamp 

•  Update row cache 

•  Return results to client 

 

 

230. Summary of Cassandra terminology 

•  A Cassandra cluster is comprised of peer-to-peer nodes logically organized into racks within data centers 

•  Any node may coordinate any request issued by a Cassandra client 

•  Data is organized into partitions ("rows") identified by tokens in a 2127-1 integer range 

•  The total token range is treated internally as a ring whose segments are owned by nodes 

•  Nodes are identified by the highest token in their segment of the total range 

•  A node's partitioner hashes a token from the partition key of a value being written 

•  The first replica ("copy") of a partition is written to the node owning the primary range containing its token

•  Replication factor (RF) determines how many replicas ("copies") are made of each partition 

•  Replication strategy determines how replicas are distributed across the cluster 

•  A per-request consistency level (CL) determines how many nodes must acknowledge 

•  Nodes continually exchange state and location information via the Gossip protocol 

•  Each node includes a Snitch which tracks and reports on the current cluster topology 

 

Interview Q and A for Cassandra DB Part - 2

 81. Mention what does the shell commands “Capture” and “Consistency” determines?

There are various Cqlsh shell commands in Cassandra. Command “Capture”, captures the output of a command and adds it to a file while, command “Consistency” display the current consistency level or set a new consistency level.

 

82. What is mandatory while creating a table in Cassandra?

While creating a table primary key is mandatory, it is made up of one or more columns of a table.

 

83. Mention what needs to be taken care while adding a Column?

While adding a column you need to take care that the

·       Column name is not conflicting with the existing column names

·       Table is not defined with compact storage option

 

84. How Can We Maintain Consistency Across Multiple Data Centers?

LOCAL QUORUM: Only local replicas are considered in acknowledging the writes; data still gets written to the other data center. It provides strong consistency along with speed.

All the available consistency levels in Cassandra (weakest to strongest) are as follows:

  • ANY
  • ONE, TWO, THREE
  • QUORUM
  • LOCAL_ONE
  • LOCAL_QUORUM
  • EACH_QUORUM
  • ALL: not in for availability, all in for consistency

For multiple data-centers, the best CL to be chosen are: ONE, QUORUM, LOCAL_ONE.

 

85. How many types of NoSQL databases are there?

There are four types of NoSQL databases, namely:

  1. Document Stores (MongoDB, Couchbase)
  2. Key-Value Stores (Redis, Volgemort)
  3. Column Stores (Cassandra)
  4. Graph Stores (Neo4j, Giraph)

 

86.  What do you understand by Commit log in Cassandra?

Answer: Commit log is a crash-recovery mechanism in Cassandra. Every write operation is written to the commit log.

87. How Cassandra provide High availability feature?

Cassandra is a robust software. Nodes joining and leaving are automatically taken care of. With proper settings, Cassandra can be made failure resistant. That means that if some of the servers fail, the data loss will be zero. So, you can just deploy Cassandra over cheap commodity hardware or a cloud environment, where hardware or infrastructure failures may occur.

88. When should you not use Cassandra? OR When to use RDBMS instead of Cassandra?

Cassandra is based on NoSQL database and does not provide ACID and relational data property. If you have strong requirement of ACID property (for example Financial data), Cassandra would not be a fit in that case. Obviously, you can make work out of it, however you will end up writing lots of application code to handle ACID property and will loose on time to market badly. Also managing that kind of system with Cassandra would be complex and tedious for you.

 

89. What do you understand by Node in Cassandra?

Node is the place where data is stored.

 

90. What do you understand by Data center in Cassandra?

Data center is a collection of related nodes.

 

91. What do you understand by Cluster in Cassandra?

Cluster is a component that contains one or more data centers.

 

92. What is the syntax to create keyspace in Cassandra?

Syntax for creating keyspace in Cassandra is

CREATE KEYSPACE <identifier> WITH <properties>

 

93. Explain what is SStable consist of?

SStable consist of mainly 2 files

·       Index file ( Bloom filter & Key offset pairs)

·       Data file (Actual column data)

 

94.  Explain what is Bloom Filter is used for in Cassandra?

A bloom filter is a space efficient data structure that is used to test whether an element is a member of a set. In other words, it is used to determine whether an SSTable has data for a particular row. In Cassandra it is used to save IO when performing a KEY LOOKUP.

Bloom filter are nothing but quick, nondeterministic, algorithms for testing whether an element is a member of a set. It is a special kind of cache. Bloom filters are accessed after every query.

 

95. Explain how Cassandra delete Data?

SSTables are immutable and cannot remove a row from SSTables.  When a row needs to be deleted, Cassandra assigns the column value with a special value called Tombstone. When the data is read, the Tombstone value is considered as deleted.

 

96. What does JMX stands for?

JMX stands for Java Management Extension

 

97. Cassandra is written in which language?

Java

 

98. What happens to existing data in my cluster when I add new nodes?

When a new nodes joins a cluster, it will automatically contact the other nodes in the cluster and copy the right data to itself.

 

99. What are “Seed Nodes” in Cassandra?

A seed node in Cassandra is a node that is contacted by other nodes when they first start up and join the cluster. A cluster can have multiple seed nodes. Seed node helps the process of bootstrapping for a new node joining a cluster. Its recommended to use the 2 seed node per data center.

 

100.  What is Nodetool Repair ?

Syncs all data in the cluster 

Expensive  -- Grows with amount of data in cluster 

Use with clusters servicing high writes/deletes 

Last line of defense

Run to synchronize a failed node coming back online 

Run on nodes not read from very often 

 

101. Read repair always occurs when consistency level is set to...

ALL

 

102. What does read_repair_chance do?

Sets the probability which Cassandra will perform a read repair with a consistency level less than ALL.

 

103. The purpose of the commit log is...

to replay if a crashed node restarts.

 

104. What is Read repair chance ?

Performed when read is at consistency level less than ALL 

Request reads only a subset of the replicas 

We can’t be sure replicas are in sync 

Generally you are safe, but no guarantees

Response sent immediately when consistency level is met

10 % by default 

 

105. When does a client acknowledge a write?

After the commit log and MemTable are written

 

106. Which are stored sorted by clustering columns? 

SSTable , MemTable

 

107. The partition summary...

stores byte offsets into the partition index.

 

108. The key cache...

stores the byte offset of the most recently accessed records.

 

109. Which of the structures reside on disk? 

            SSTable

            partition index

 

110. Which are benefits from compaction? 

More optimal disk usage

Faster reads

Less memory pressure

 

111. All tombstones are discarded during compaction.

False

 

112. In which scenarios would a new partition on disk be larger than either of its input partition segments after a compaction?

 The input partition segments are made up of mostly INSERT operations.

 

113. Adding Nodes 

You might want to considering adding a new node if you have 

-        Reached data capacity problem  

-- Your data has outgrown the node’s hardware capacity 

-       Reached traffic capacity 

--Your application needs more rapid response with less latency 

-       Need more operational headroom 

--Need more resources for node repair, compaction, and other resource intensive operations

 

114. Adding Nodes Best Practices 

Single-token Nodes  -- Double the size of a cluster (Single token Nodes)

Vnodes – For vnode clusters, we can increments the size of the cluster if more nodes are needed

-Wait a period a time before adding each additional node ( single-token and vnodes)

-Follow the ‘2 Minute rule’

-This ensure the range announcement is known to all nodes before the next one begins entering the cluster.

 

115. What are main parameters to Node setup 

Four main parameters of a node for bootstrapping 

These are configured in the Cassandra.yaml file 

Cluster_name , rpc_address ,listen_address , seeds

 

116. What id Bootstrapping process

Simple process but pretty critical 

Can be a long running process

Node announces itself to ring using seed node

Calculate ranges of new node, notify ring of these pending ranges 

Calculate the nodes that currently own these ranges and will no longer own them once the bootstrap completes 

Stream the data from these nodes to the bootstrapping node ( monitor with nodetool netstats)

Join the new node to the ring so it can serve traffic 

Length of time it takes to join will depend on the amount of data to be streamed 

 

117. What if bootstrap fails ?

Two scenarios 

-       Bootstrapping node could not even connect to cluster 

Fairly easy to deal with 

Something fundamental like could not  find cluster

Examine the log file to understand what’s going on firstly (What types of things, error conditions it should be flagged as soon in process, if bootstrap), change config and try again 

-       Streaming portion fails 

 Node exists in cluster in joining state 

 

Nodetool rebuild to rebootstrap data

 

118. Nodetool Cleanup 

Perform cleanup after a bootstrap on the OTHER nodes 

You don’t have to do this

Reads all SSTables to make sure there is no token out of range for that particular node 

If it’s out of range it just does a copy 

If you don’t run cleanup, will get picked up through compaction over time.

Cleanup is basically a compaction 

 

119. How do we run a cleanup operation 

The nodetool cleanup command cleans up all data in a keyspace and tables that are specified 

Bin/nodetool [options] cleanup – <keyspace> (<table>)

 

Use flags to specify 

-h host/IP address

-p port

-pw password 

-u username

Nodetool cleanup command  will clean all keyspace is  specified 

 

120. Why would I remove a node ?

Two very different scenarios : 

 

You are going to reduce capacity, need to decommission ( some sort of operational requirement) 

The node is offline and will never come back online 

 

121. Removing a live node from the cluster 

Perhaps you want to decrease the size of your cluster 

Perhaps you might want to swap out an older machine with a newer machine 

Decommissioning a node will assign the ranges of the old node to other nodes and replicates the appropriate data on the new nodes 

Decommissioned node’s data will be streamed from the decommissioning node itself

Once data has been moved to other nodes, the process for removing or replacing is similar for both 

 

122. When a node is decommissioned 

Node is marked as ‘LEAVING’ and will stream data to other live nodes.

The data directories will still exist – remove these if the node will go back into production 

The Cassandra JVM is still running – but with Gossip , Thrift and Native Transport ports all down. 

This allows admin to hook up a JMX client to analyze the metrics maintained in the JVM 

Then the JVM process can be shutdown manually 

 

123. Decommission a node using nodetool

/bin/nodetool [option] decommission

 

Removes node specified by host id 

-h host/IP address

-p port 

-pw password 

-u username 

Monitor progress with nodetool netstats

 

124. Can we remove a node ?

Before doing anything, check nodetool status to see the state of the node in question 

Nodetool status   -- status =up/down

 

If the node is down ( and not coming back online), choose the appropriate option:

-Remove the node using the nodetool removenode command 

Adjust your tokens to avoid creating a hot spot if using single-token nodes.

-If removenode fails, run nodetool assassinate

-nodetool repair should be run once the node is removed from the cluster 

 

/bin/nodetool [options] removenode [host id]

 

-h host/IP address

-p port 

-pw password 

-u username

Additional arguments – status  ,  forces 

 

125. The pros  of replacing a downed node 

You don’t have to move the data twice 

Backup for a node will work for a replaced node, because same token are used to bring replaced node into cluster 

 

126. replacing a downed node using nodetool

First find the ip address of the down node using nodetool status 

In the node, open the Cassandra-env.sh file

Swap in the IP address of dead node as the replace_address value in the JVM option. This will enable bootstrapping of the new node.

Use nodetool removenode to remove the dead node

Use the force option if necessary (nodetool assassinate)

You can monitor the process using nodetool netstats

 

127. what if the node was also a seed node ?

Consideration 

Need to add to list of seeds in Cassandra.yaml

Cassandra will not allow seed node to autobootrap

Thus will have to run repair on new seed node to do so.

Steps 

 

Add a new node making the necessary changes to the Cassandra.yaml file

Specify new seed node in Cassandra.yaml file

Start Cassandra on new seed node 

Run nodetool repair on the new seed node to manually bootstrap

Remove the old seed node using nodetool removenode with the Host  ID of the downed node 

Run nodetool cleanup on previously existing nodes 

 

128. By default, how many vnodes does each node have?

256

 

129. Which parameter in the cassandra.yaml file configures vnodes?

num_tokens

 

130. When using vnodes, Cassandra automatically assigns token ranges for you.

True

 

131. Nodes can only gossip with specific other nodes in the cluster.

False

 

132. Which of the statements are true concerning gossip? 

Constant trickle of network traffic

Does not cause network spikes

Minimal compared to data streaming

            

133. In a full network partition, that is, parts of the cluster are completely disconnected from the whole, only the largest group of nodes can still satisfy queries.

False

 

134. What are the three main layers (in order) of data modeling?

Conceptual, Logical, Physical

 

135.  Data modeling 

Analyze requirements 

Identify entities and relationships

Identify queries

Specify the schema 

Optimize 

 

Conceptual Data model / Application workflow  Mapping conceptual to logical  Logical Data Model  Physical Optimization  Physical data Model

 

Think outside of the box

Non standard solution – requires creativity 

Different data models have different costs 

 

136. Keyspaces   

Top level namespace/container

Similar to a relational database schema

Replication parameters required 

Keyspaces contain tables 

Tables contain data

Uniquely identify rows

 

137. How to switch between keyspaces

By USE command 

USE keyspacename

 

138.  What is UUID  & TIMEUUID

UUID -  Universally Unique identifier 

Generate via uuid()

 

TIMEUUID embeds a Timestamp value 

Sortable 

Generate via now()

 

 

 

139. Copy command 

Imports/ exports CSV 

Header parameter skips the first line in the file 

 

Copy table1(c1,c2,c3) from ‘t1.csv’ with Header=true ;

 

140. What command bulk-loads data files?

COPY

 

141.Why do we use UUIDs in Cassandra to uniquely identify records?

To avoid conflicts in auto generating IDs between nodes

 

142. Cassandra requires you to specify the width of texual types, for example VARCHAR(50).

False

 

143. Partition Storage 

Cassandra distributes partitions across nodes 

Where on any field other than partition key would require searching all partitions on all nodes 

Cassandra no likely 

We can WHERE on a partition key value 

Cassandra uses a hashing algorithm to quickly determine which nodes contain the desired partition 

 

144. What is the smallest atomic unit of storage in Cassandra?

paritition

 

145. What is a cell?

key-value pair

 

146. What is a partition?

group of cells

 

147. What is the significance of the partition key?

Cassandra hashes the key value to determine which node the partition resides on

 

148. Clustering columns

Come after partition key within PRIMARY KEY clause

Clustering columns divide CQL rows between partitions.

Clustering column values stored sorted 

Default is ascending 

 

149. Querying clustering columns 

You must first provide a partition key 

Clustering columns can follow thereafter 

You can perform either equality (=) or range queries (<, >) on clustering columns 

All equality comparisons must come before inequality comparisons

Since data is sorted on disk, range searches are a binary search followed by a linear read

 

150. Change default Ordering  of clustering columns

Clustering columns defaults ascending order 

Change ordering direction via WITH CLUSTERING ORDER BY 

Must include all columns including and up to columns you wish to order descending 

 

151. Allow filtering 

ALLOW FILTERING Relaxes the querying on partition key constraint 

You can then query on just clustering columns 

Causes Cassandra to scan all partitions in the table 

Don’t use it    --  Unless you really have to   -- Best on small data sets 

 

152. What is an upsert?

INSERTs may cause UPDATEs; UPDATEs may causes INSERTs

 

153. What purpose do clustering columns serve?

Provide uniqueness within the partition as well as ordering criteria

 

154. What is the relationship between a partition key and a clustering column?

Partition keys determine a grouping criteria whereas clustering columns determine ordering criteria

 

155. What is NODETOOL

Node management 

Located in the bin/ folder 

/bin/nodetool help

 

Help --  Lists all possible sub commands 

Info – Current node settings and stats 

Status – Reports basic node health information 

 

156. Alter Table statement 

Adding column 

Dropping column 

Cannot alter primary key 

 

157. Collection column 

Collection columns are multi valued columns 

Designed to store a small amount of data 

Retrieved in its entirety

Cannot nest a collection inside another collection 

 

158. What is UDTs (user defined types)

UDT group related fields of information 

Allow embedding more complex data within a single column 

Create Type  address ( street text, city text);

Using a UDT by adding frozen keyword.

 

159. What command drops all records from an existing table?

TRUNCATE

 

160. What command adds/removes columns to/from a table?

ALTER

 

161. Which is a Cassandra column type?

            LIST<>

            SET<>

            MAP<>

            

162. Cassandra counters are always 100% accurate.

FALSE

 

163. What command executes a file of CQL statements?

SOURCE

 

164. Conceptual data modeling 

Abstract view of the domain 

Technology independent 

Not specific to any database system 

 

165. Which is an advantage of conceptual data modeling?

            Collaboration between both technical and non-technical team members

            Provides abstraction from the problem details

            Better understanding of the domain

            

166. Which is a type found in a conceptual data model?

            Entity types

            Relationship types

            Attribute types

 

167. Attribute types can be...

            key

            composite

            multi-valued

 

168. How do you determine the key of a 1-1 relationship?

Key attributes of either participating entity types

 

169. How do you determine the key of a 1-n relationship?

Key attributes of entity type on the many side

 

170. How do you determine the key of a m-n relationship?

Key attributes of both participating entity types

 

171. What does disjoint mean?

            An entity can only participate in only one subtype role

 

172. What is an application workflow?

            Tasks formed by causual dependencies

 

173. How do we indicate a partition key in a Chebotko diagram?

K

 

174. How do we indicate a clustering column in a Chebotko diagram?

C with up/down arrow

 

175. What is a table's main purpose in a Cassandra database?

Serve a query

 

176. Data  Modeling Principles

1 --Know  your data

Data captured by conceptual data model 

 Define what is stored in database

Preserve properties so that data is organized correctly 

2 --- Know your queries 

Queries captured by application workflow model 

Table schema design changes if queries changes 

3 ---Nest data 

Nesting organizes multiple entities into a single partition 

Support partition per query data access

 

Three data nesting mechanisms

Clustering column – multi row partitions 

Collection columns

User defined type columns 

4 --- Duplicate data

Better to duplicate than to join data 

Partition per query and data nesting may result in data duplication 

     Query results are pre computed and materialized

     Data can be duplicated across tables, partitions,  or rows 

 

177. What are the two preferrable table query strategies?

            Partition per query and partition+ per query

 

178. Why do we nest data in Cassandra?

Support a partition per query access pattern

 

179. Mapping Rules For the query driven methodology 

Mapping rules ensure that a logical data model is correct 

Each query has a corresponding table 

Tables are designed to allow queries to execute properly 

Tables return data in the correct order

MR1 --  Entities and Relationships 

 

Entity and relationship types map to tables 

Entity and relationship map to partitions or rows 

Partition may have data about one or more entities and  relationships

Attributes are represented by columns 

 

180. Choose the option that lists the mapping rules in proper order

Entities and relationships, equality search attributes, inequiality search attributes, ordering attributes, key attributes