-
Notifications
You must be signed in to change notification settings - Fork 16
Feature: add \shards command to track relocations #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 20 commits
22bd78b
4146fdf
880223e
2786f0a
022c19b
e661b1f
2924468
bb2eed7
cbca86d
4300264
09490b6
b5b80b6
210445e
e097681
5d8a4aa
980ce2d
bdc9426
0912903
a1a5d48
7c8fae0
8a51d8e
65132df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| ClusterCheckCommand, | ||
| NodeCheckCommand, | ||
| ReadFileCommand, | ||
| ShardsCommand, | ||
| ToggleAutoCapitalizeCommand, | ||
| ToggleAutocompleteCommand, | ||
| ToggleVerboseCommand, | ||
|
|
@@ -267,6 +268,52 @@ def test_check_command_with_node_check(self, cmd): | |
| cmd.logger.info.assert_called_with('NODE CHECK OK') | ||
|
|
||
|
|
||
| class ShardsCommandTest(TestCase): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd tend to remove this. Given the coverage from |
||
| @patch('crate.crash.command.CrateShell') | ||
| def test_shards_command_default(self,cmd): | ||
| rows = [ | ||
| ['RELOCATING','FALSE','2','33334465','9.307963063940406'], | ||
| ['STARTED','TRUE','1010','166665535','26.309150873683393'], | ||
| ] | ||
| cols = [('state', ), ('primary',), ('shard_count', ), ('num_docs', ), ('size_gb', )] | ||
| cmd._exec.return_value = True | ||
| cmd.cursor.fetchall.return_value = rows | ||
| cmd.cursor.description = cols | ||
|
|
||
| ShardsCommand()(cmd) | ||
| cmd.pprint.assert_called_with(rows, [c[0] for c in cols]) | ||
|
|
||
| @patch('crate.crash.command.CrateShell') | ||
| def test_shards_command_info(self,cmd): | ||
| rows = [ | ||
| ['doc','table1','','1','10','1024','0','100.0'], | ||
| ['doc','table2','','2','20','2048','1','50.0'], | ||
| ['doc','table3','','3','30','3072','2','33.3'], | ||
| ] | ||
| cols = [('schema_name',),('table_name',),('partition_ident',),('total_shards',),('total_size',),('relocating_shards',),('relocating_size',),('relocated_percent',)] | ||
| cmd._exec.return_value = True | ||
| cmd.cursor.fetchall.return_value = rows | ||
| cmd.cursor.description = cols | ||
|
|
||
| ShardsCommand()(cmd, "info") | ||
| cmd.pprint.assert_called_with(rows, [c[0] for c in cols]) | ||
|
|
||
|
|
||
| @patch('crate.crash.command.CrateShell') | ||
| def test_shards_command_default_none(self,cmd): | ||
| cmd._exec.return_value = True | ||
| cmd.cursor.fetchall.return_value = [] | ||
| ShardsCommand()(cmd) | ||
| cmd.logger.info.assert_not_called() | ||
|
|
||
| @patch('crate.crash.command.CrateShell') | ||
| def test_shards_command_info_none(self,cmd): | ||
| cmd._exec.return_value = True | ||
| cmd.cursor.fetchall.return_value = [] | ||
| ShardsCommand()(cmd,"info") | ||
| cmd.logger.info.assert_not_called() | ||
|
|
||
|
|
||
| @patch('crate.client.connection.Cursor', fake_cursor()) | ||
| class CommentsTest(TestCase): | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -653,10 +653,12 @@ def test_help_command(self): | |
| '\\pager set an external pager. Use without argument to reset to internal paging', | ||
| '\\q quit crash', | ||
| '\\r read and execute statements from a file', | ||
| '\\shards shows shards state, optionally per table, e.g. \\shards info', | ||
| '\\sysinfo print system and cluster info', | ||
| '\\verbose toggle verbose mode', | ||
| ]) | ||
|
|
||
|
|
||
| help_ = command.commands['?'] | ||
| self.assertTrue(isinstance(help_, Command)) | ||
| self.assertEqual(expected, help_(command)) | ||
|
|
@@ -870,4 +872,95 @@ def test_connect_info_not_available(self, is_conn_available): | |
| self.assertEqual(crash.connect_info.schema, None) | ||
|
|
||
|
|
||
| class ShardsCommandEmptyDBTest(TestCase): | ||
| def setUp(self): | ||
| node.reset() | ||
|
|
||
| def test_shards_command_output_default(self): | ||
| expected = '\n'.join([ | ||
| '+-------+---------+-------------+----------+---------+', | ||
| '| state | primary | shard_count | num_docs | size_gb |', | ||
| '+-------+---------+-------------+----------+---------+', | ||
| '+-------+---------+-------------+----------+---------+\n', | ||
| ]) | ||
| with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: | ||
| shards_ = cmd.commands['shards'] | ||
| with patch('sys.stdout', new_callable=StringIO) as output: | ||
| text = shards_(cmd) | ||
| self.assertEqual(None, text) | ||
| self.assertEqual(expected, output.getvalue()) | ||
|
|
||
| def test_shards_command_output_info(self): | ||
| expected = '\n'.join([ | ||
| '+-------------+------------+-----------------+--------------+------------+-------------------+-----------------+-------------------+', | ||
| '| schema_name | table_name | partition_ident | total_shards | total_size | relocating_shards | relocating_size | relocated_percent |', | ||
| '+-------------+------------+-----------------+--------------+------------+-------------------+-----------------+-------------------+', | ||
| '+-------------+------------+-----------------+--------------+------------+-------------------+-----------------+-------------------+\n', | ||
| ]) | ||
| with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: | ||
| shards_ = cmd.commands['shards'] | ||
| with patch('sys.stdout', new_callable=StringIO) as output: | ||
| text = shards_(cmd, 'info') | ||
| self.assertEqual(None, text) | ||
| self.assertEqual(expected, output.getvalue()) | ||
|
|
||
|
|
||
| def test_shards_command_output_wrong_argument(self): | ||
| with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: | ||
| shards_ = cmd.commands['shards'] | ||
| with patch('sys.stdout', new_callable=StringIO) as output: | ||
| cmd.logger = ColorPrinter(False, stream=output) | ||
| text = shards_(cmd, 'arg1', 'arg2') | ||
| self.assertEqual(None, text) | ||
| self.assertEqual('Command argument not supported (available options: `info`).\n', output.getvalue()) | ||
|
|
||
|
|
||
|
|
||
| class ShardsCommandWithContentTest(TestCase): | ||
| def tearDown(self): | ||
| with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: | ||
| cmd.process('DROP TABLE IF EXISTS test_table;') | ||
|
|
||
| def setUp(self): | ||
| node.reset() | ||
| with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: | ||
| cmd.process('CREATE TABLE test_table (id INTEGER PRIMARY KEY, data STRING ) CLUSTERED INTO 10 SHARDS WITH (number_of_replicas = 0);\n') | ||
|
|
||
| def test_shards_command_output_default(self): | ||
| expected = [ | ||
| '+---------+---------+-------------+-----------+---------------------+', | ||
| '| state | primary | shard_count | num_docs | size_gb |', | ||
| '+---------+---------+-------------+-----------+---------------------+', | ||
| '| STARTED | FALSEy | ?6 | 1x0000000 | 7. DUMMY VALUE 614 |', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused by this expected output. Where's the |
||
| '+---------+---------+-------------+-----------+---------------------+\n', | ||
| ] | ||
| with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: | ||
| shards_ = cmd.commands['shards'] | ||
| with patch('sys.stdout', new_callable=StringIO) as output: | ||
| text = shards_(cmd) | ||
| self.assertEqual(None, text) | ||
| output_lines = output.getvalue().splitlines() | ||
| self.assertEqual(len(expected), len(output_lines)) | ||
| header = lambda x: [word.strip() for word in x[1].split('|')] | ||
| self.assertEqual(header(expected), header(output_lines)) | ||
|
|
||
|
|
||
| def test_shards_command_output_info(self): | ||
| expected = [ | ||
| '+-------------+------------+-----------------+--------------+------------+-------------------+-----------------+-------------------+', | ||
| '| schema_name | table_name | partition_ident | total_shards | total_size | relocating_shards | relocating_size | relocated_percent |', | ||
| '+-------------+------------+-----------------+--------------+------------+-------------------+-----------------+-------------------+', | ||
| '| doc | test_table | | 10 | 624 | 0 | NULL | 100.0 |', | ||
| '+-------------+------------+-----------------+--------------+------------+-------------------+-----------------+-------------------+\n', | ||
| ] | ||
| with CrateShell(crate_hosts=[node.http_url], is_tty=False) as cmd: | ||
| shards_ = cmd.commands['shards'] | ||
| with patch('sys.stdout', new_callable=StringIO) as output: | ||
| text = shards_(cmd, 'info') | ||
| self.assertEqual(None, text) | ||
| output_lines = output.getvalue().splitlines() | ||
| self.assertEqual(len(expected), len(output_lines)) | ||
| header = lambda x: [word.strip() for word in x[1].split('|')] | ||
| self.assertEqual(header(expected), header(output_lines)) | ||
|
|
||
| setup_logging(level=logging.INFO) | ||
Uh oh!
There was an error while loading. Please reload this page.