Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 24, 2021 01:01 pm GMT

Working with Scylla Database

Hello everyone! My intention today is to write about Scylla database. Scylla is a NoSQL database based on Cassandra. One difference between both is that Cassandra is developed in Java language and Scylla in C++ language. The goal of that is to avoid some Java processes that can impact the performance of the application, like garbage collector and stop the world. After this introduction, let's see how we can use Scylla and know some details about it.

Downloading image

For work with Scylla, we will use docker. The first step is to download the image. We can use the command below.

docker run --name scylla-db-test -d scylladb/scylla:4.1.0

After that, we can use some tools of Scylla and guarantee that our database is healthy.

docker exec -it scylla-db-test nodetool status

The result of executing the command above is

Datacenter: datacenter1=======================Status=Up/Down|/ State=Normal/Leaving/Joining/Moving--  Address     Load       Tokens       Owns    Host ID                               RackUN  172.17.0.2  866.47 KB  256          ?       0b8a4db2-b8ea-49cf-b618-4eaf780ba7c7  rack1

There is information about Datacenter, but this is not our focus in this post. At this moment, we should just know that our node (more information about that in the next section) is Up and Normal (UN).

Playtime

For executing commands in Scylla, there is a CLI called cqlsh.

docker exec -it scylla-db-test cqlshConnected to at 172.17.0.2:9042.[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]Use HELP for help.cqlsh> 

The first thing that we can do is create a keyspace. Different from relational databases, Scylla doesn't have the database concept. In Scylla we work with keyspace, which is a top-level container that stores tables. Besides creating a keyspace, we need to configure other attributes like replication strategy.

CREATE KEYSPACE automobiles WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};

Like I said previously, it's necessary to configure replication strategy and how we can see, this is done with attribute replication. Inside brackets has two configurations. The replication_factor which means that the data inserted in a table of automobiles keyspace will be replicated in 3 nodes. Nodes are instances of Scylla DB. The other configuration is class and defines the replication strategy class to use. There are 2 options:

'SimpleStrategy': defines a replication factor for the whole cluster. The only sub-options supported is 'replication_factor' to define that replication factor and is mandatory.

'NetworkTopologyStrategy': A replication strategy that lets you set the replication factor independently for each data center. The rest of the sub-options are key-value pairs where a key is a data-center name and its value is the associated replication factor or a single key-value with Auto-Expand Replication Factor. Recommended for production. (Just for knowledge, we won't talk about this option in this post)

Now we can create our table. The name will be Car.

USE automobiles ;CREATE TABLE car (id uuid, brand text, model text, color text, PRIMARY KEY(id)) ;

How we can see, Scylla syntax is similar to SQL syntax, and to include data, we use the insert clause.

INSERT INTO car (id, brand, color, model) VALUES (123e4567-e89b-12d3-a456-426614174000, 'VW', 'Red', 'Golf');

To see data in the table is just necessary to use the select clause.

SELECT * FROM car; id                                   | brand | color | model--------------------------------------+-------+-------+------- 123e4567-e89b-12d3-a456-426614174000 |    VW |   Red |  Golf

Conclusion

The idea of this post is to presenting Scylla DB and some operations that we can do. There are more details that I intended to present in the future, as partition key and clustering key, and how we can define our primary key mixing up of both concepts. This is crucial for better performance at the moment that we need to filter our searches. For now, that is enough. I will see you in the next post.

References
https://docs.scylladb.com/getting-started/dml/
https://university.scylladb.com/


Original Link: https://dev.to/j_a_o_v_c_t_r/working-with-scylla-database-3al9

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To