Sharding

Starting from iBatyr Monitor 4.7, sharding is supported out of the box.

Operating principle

Sharding is a database design principle in which logically independent rows of a database table are stored separately, pre-grouped into sections. These sections, in turn, are located on different, physically and logically independent database servers. In this case, one physical cluster node can contain several database servers.

In iBatyr Monitor, sharding works as follows:

  1. Several tables are created, divided by month from the 1st day, a table for the next month and a default table (agent_event_default).

  2. The current month table is filled in as events arrive.

Illustration 1 — Sharding

Note

agent_event_default is a table that contains events that are not included in any of the created tables. For example, if the time on the agent is set incorrectly (month, year).

If agent_event_default has grown to a large size, then there is a problem somewhere or something is not working correctly.

Useful commands

A list of commands that can be used to perform diagnostics or view information.

Action

Team

Comment

Check if sharding is enabled

sudo ibatyr shard install

If sharding is enabled, the message Sharding already enabled will appear on the screen.

Display a list of shards

sudo ibatyr shard list

Displays a list of all tables, divided by month; indicates their size.

View table data

ibatyr sql "select count(*), min(local_time), max(local_time) from table group by date_trunc('month', local_time)"

The output result will be the number of events in the selected table, as well as the time of the first and last event, where table is the table name: agent_event is all shards; agent_event_YYYY_MM_01 — monthly shard.

Create cold storage

sudo ibatyr shard cold /var/lib/ibatyr/upload/coldbase

Creates cold storage on another disk, for example to create an archive.

“Freeze” table

ibatyr shard freeze <table_name>

The command will freeze table table_name and move it to a slow disk.

Attention: Before starting the freeze, stop nginx: sudo service nginx stop. Once completed, run nginx: sudo service nginx start.

Delete monthly data

ibatyr shard drop <table_name>

Deletes the table table and its associated files.

Delete data for several months

ibatyr shard cleanup n

Deletes all tables except n: 0 — deletes all tables; 1 – leaves only the current month; 2 — leaves the current and previous months; etc. The command deletes shards in PostgreSQL, partitions in ClickHouse and files associated with them.

Delete partition in ClickHouse

ibatyr clickhouse drop <partition>

Deletes the <partition> partition in ClickHouse.

Removing a shard via the web interface

Note

When deleting a shard, all files associated with the specified table will be deleted.

You can delete shards in PostgreSQL and ClickHouse from the web interface of the iBatyr Monitor server. To do this, in the Control Panel - Databases section, select the database you are interested in and in the Perform action drop-down menu, select Delete data.

Illustration 2 — Sharding