At the Forge - Cassandra
Restart Cassandra, and reconnect via the CLI. Then, type:
cassandra> show keyspaces
Your new keyspace, “People”, now should appear in the list:
cassandra> show keyspaces Keyspace1 system People
You can ask for a description of your keyspace:
cassandra> describe keyspace People People.Users Column Family Type: Standard Columns Sorted By: org.apache.cassandra.db.marshal.BytesType@1b22920 Column Family Type: Standard Column Sorted By: org.apache.cassandra.db.marshal.BytesType flush period: null minutes ------
You now can see that your People keyspace contains a single “Users” column family. With this in place, you can start to set and retrieve data:
cassandra> get People.Users['1'] Returned 0 results. cassandra> set People.Users['1']['email'] = 'email@example.com' cassandra> set People.Users['1']['first_name'] = 'Reuven' cassandra> set People.Users['1']['last_name'] = 'Lerner'
In Cassandra-ese, you would say that you now have set three column values ('email', 'first_name' and 'last_name'), for one key ('1') under a single column family (“Users”), within a single Keyspace (“People”). If you're used to working with a language like Ruby or Python, you might feel a bit underwhelmed—after all, it looks like you just set a multilevel hash. But that makes sense, given that Cassandra is a super-version of a key-value store, right?
Now, let's try to retrieve the data. You can do that with the key:
cassandra> get People.Users['1'] => (column=6c6173745f6e616d65, value=Lerner, ↪timestamp=1279024194314000) => (column=66697273745f6e616d65, value=Reuven, ↪timestamp=1279024183326000) => (column=656d61696c, firstname.lastname@example.org, timestamp=1279024170585000) Returned 3 results.
Notice how each column has its own unique ID and that the data was stored with a timestamp. Such timestamps are crucial when you are running multiple Cassandra nodes, and they update one another without your knowledge to achieve complete consistency.
You can add additional information too:
cassandra> set People.Users['2']['first_name'] = 'Atara' cassandra> set People.Users['2']['last_name'] = 'Lerner-Friedman' cassandra> set People.Users['2']['school'] = 'Yachad' cassandra> set People.Users['3']['first_name'] = 'Shikma' cassandra> set People.Users['3']['last_name'] = 'Lerner-Friedman' cassandra> set People.Users['3']['school'] = 'Yachad'
Now you have information about three users, and as you can see, the columns that you used within the “Users” column family were not determined by the configuration file and can be added on the spot. Moreover, there is no rule saying that you must set a value for the “email” column; such enforcement doesn't exist in Cassandra. But what is perhaps most amazing to relational database veterans is that there isn't any way to retrieve all the values that have a last_name of 'Lerner-Friedman' or a school named 'Yachad'. Everything is based on the key (which I have set to an integer in this case); you can drill down, but not across, as it were.
You can ask Cassandra how many columns were set for a given key, but you won't know what columns those were:
cassandra> count People.Users['1'] 3 columns cassandra> count People.Users['2'] 3 columns
However, if you're trying to store information about many users, and those users are going to be updating their information on a regular basis, Cassandra can be quite helpful.
Now that you've got the hang of columns, I'll mention a particularly interesting part of the Cassandra data model. Instead of defining columns, you instead can define “super columns”. Each super column is just like a regular column, except it can contain multiple columns within it (rather than a name-value pair). In order to define a super column, set the ColumnType attribute in the storage-conf.xml file to “Super”. For example:
<ColumnFamily Name="Users" CompareWith="BytesType" ↪ColumnType="Super" />
Note that if you restart Cassandra with this changed definition, and then try to retrieve People.Users['1'], you'll probably get an error. That's because you effectively have changed the schema without changing the data, which always is a bad idea. Now you can store and retrieve finer-grained information:
cassandra> set People.Users['1']['address']['city'] = 'Modiin' cassandra> get People.Users['1']['address']['city'] => (column=63697479, value=Modiin, timestamp=1279026442675000)
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Server Hardening
- BitTorrent Inc.'s Sync
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- New Container Image Standard Promises More Portable Apps
- The Humble Hacker?
- The Death of RoboVM
- Open-Source Project Secretly Funded by CIA
- The US Government and Open-Source Software
- EnterpriseDB's EDB Postgres Advanced Server and EDB Postgres Enterprise Manager
- ACI Worldwide's UP Retail Payments
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide