Outdated Version

You are viewing an older version of this section. View current production version.

Counting Partitions by Role min read


The output of SHOW CLUSTER STATUS is useful for understanding the state of partition databases in a cluster. This output can be used to determine if the number of Master partitions is equal to the number of replica partitions. A cluster configured for High Availability (HA) should always have the same number of Master and replica partition databases.

The purpose of this article is to provide commands for counting the number of master and replica partitions in a cluster.

Consider the following output of SHOW CLUSTER STATUS:

memsql> show cluster status;
+------------+------+----------------+-----------+-------------+------------+---------+
| Host       | Port | Database       | Role      | State       | Position   | Details |
+------------+------+----------------+-----------+-------------+------------+---------+
| 10.0.0.105 | 3307 | memsql_demo    | Reference | replicating | 0:14778    |         |
| 10.0.0.105 | 3307 | memsql_demo_0  | Master    | online      | 0:12959258 |         |
| 10.0.0.105 | 3307 | memsql_demo_10 | Slave     | replicating | 0:13044214 |         |
| 10.0.0.105 | 3307 | memsql_demo_12 | Master    | online      | 0:12965513 |         |
| 10.0.0.105 | 3307 | memsql_demo_14 | Slave     | replicating | 0:12856488 |         |
| 10.0.0.105 | 3307 | memsql_demo_2  | Slave     | replicating | 0:13043324 |         |
| 10.0.0.105 | 3307 | memsql_demo_4  | Master    | online      | 0:12930755 |         |
| 10.0.0.105 | 3307 | memsql_demo_6  | Slave     | replicating | 0:12980970 |         |
| 10.0.0.105 | 3307 | memsql_demo_8  | Master    | online      | 0:12906009 |         |
| 10.0.1.26  | 3307 | memsql_demo    | Reference | replicating | 0:14778    |         |
| 10.0.1.26  | 3307 | memsql_demo_0  | Slave     | replicating | 0:12959258 |         |
| 10.0.1.26  | 3307 | memsql_demo_10 | Master    | online      | 0:13044214 |         |
| 10.0.1.26  | 3307 | memsql_demo_12 | Slave     | replicating | 0:12965513 |         |
| 10.0.1.26  | 3307 | memsql_demo_14 | Master    | online      | 0:12856488 |         |
| 10.0.1.26  | 3307 | memsql_demo_2  | Master    | online      | 0:13043324 |         |
| 10.0.1.26  | 3307 | memsql_demo_4  | Slave     | replicating | 0:12930755 |         |
| 10.0.1.26  | 3307 | memsql_demo_6  | Master    | online      | 0:12980970 |         |
| 10.0.1.26  | 3307 | memsql_demo_8  | Slave     | replicating | 0:12906009 |         |
| 10.0.2.34  | 3307 | memsql_demo    | Reference | replicating | 0:14778    |         |
| 10.0.2.34  | 3307 | memsql_demo_1  | Master    | online      | 0:13064181 |         |
| 10.0.2.34  | 3307 | memsql_demo_11 | Slave     | replicating | 0:12880457 |         |
| 10.0.2.34  | 3307 | memsql_demo_13 | Master    | online      | 0:13001894 |         |
| 10.0.2.34  | 3307 | memsql_demo_15 | Slave     | replicating | 0:13066662 |         |
| 10.0.2.34  | 3307 | memsql_demo_3  | Slave     | replicating | 0:12980834 |         |
| 10.0.2.34  | 3307 | memsql_demo_5  | Master    | online      | 0:13029848 |         |
| 10.0.2.34  | 3307 | memsql_demo_7  | Slave     | replicating | 0:12944227 |         |
| 10.0.2.34  | 3307 | memsql_demo_9  | Master    | online      | 0:13074322 |         |
| 10.0.2.1   | 3307 | memsql_demo    | Reference | replicating | 0:14778    |         |
| 10.0.2.1   | 3307 | memsql_demo_1  | Slave     | replicating | 0:13064181 |         |
| 10.0.2.1   | 3307 | memsql_demo_11 | Master    | online      | 0:12880457 |         |
| 10.0.2.1   | 3307 | memsql_demo_13 | Slave     | replicating | 0:13001894 |         |
| 10.0.2.1   | 3307 | memsql_demo_15 | Master    | online      | 0:13066662 |         |
| 10.0.2.1   | 3307 | memsql_demo_3  | Master    | online      | 0:12980834 |         |
| 10.0.2.1   | 3307 | memsql_demo_5  | Slave     | replicating | 0:13029848 |         |
| 10.0.2.1   | 3307 | memsql_demo_7  | Master    | online      | 0:12944227 |         |
| 10.0.2.1   | 3307 | memsql_demo_9  | Slave     | replicating | 0:13074322 |         |
+------------+------+----------------+-----------+-------------+------------+---------+
36 rows in set (0.00 sec)

Use the following one-line command to determine number of Master partition databases in a cluster:

memsql-master-agg-host /home/admin $ singlestore -e "show cluster status" | cut -f4 -d$'\t' | grep Master | wc -l
16

Use the following one-line command to determine number of replica partition databases in a cluster:

memsql-master-agg-host /home/admin $ singlestore -e "show cluster status" | cut -f4 -d$'\t' | grep Slave | wc -l
16 

Use the following one-line command to determine number of Orphan partition databases in a cluster

memsql-master-agg-host /home/admin $ singlestore -e "show cluster status" | cut -f4 -d$'\t' | grep Orphan | wc -l
0

Any orphaned partitioned databases found in the output of SHOW CLUSTER STATUS should be addressed immediately. The topic Understanding Orphaned Partitions provides an example of addressing an orphan.