Skip to content
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

Support "show parts" command #1086

Merged
merged 2 commits into from
Nov 7, 2019
Merged

Conversation

zhangguoqing
Copy link
Contributor

@zhangguoqing zhangguoqing commented Oct 15, 2019

  1. Add the ListPartsProcessor to get all partitions' information(id, leader, peers, losts) of one graph space.
  2. The SHOW PARTS command can show the results displayed by console, after doing USE space_name.

close #930

Example:

Init and start the nebula graph cluster:

(user@172.25.61.1) [(none)]> show hosts;
==============================================================================================
| Ip          | Port  | Status | Leader count | Leader distribution | Partition distribution |
==============================================================================================
| 172.25.61.1 | 44600 | online | 0            | No valid partition  | No valid partition     |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44700 | online | 0            | No valid partition  | No valid partition     |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44500 | online | 0            | No valid partition  | No valid partition     |
----------------------------------------------------------------------------------------------

Create the graph spaces(named myspace) with 9 partitions and 3 replicas:

(user@172.25.61.1) [(none)]> CREATE SPACE myspace(partition_num=9, replica_factor=3);
Execution succeeded (Time spent: 5845/6800 us)

Show the hosts with myspace:

(user@172.25.61.1) [(none)]> show hosts;
==============================================================================================
| Ip          | Port  | Status | Leader count | Leader distribution | Partition distribution |
==============================================================================================
| 172.25.61.1 | 44600 | online | 0            | myspace: 0          | myspace: 9             |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44700 | online | 0            | myspace: 0          | myspace: 9             |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44500 | online | 0            | myspace: 0          | myspace: 9             |
----------------------------------------------------------------------------------------------

Show parts of myspace, before leader election:

(user@172.25.61.1) [(none)]> use myspace;
Execution succeeded (Time spent: 1463/2378 us)

(user@172.25.61.1) [myspace]> show parts;
===========================================================================================
| Partition ID | Leader | Peers                                                   | Losts |
===========================================================================================
| 1            |        | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
-------------------------------------------------------------------------------------------
| 2            |        | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
-------------------------------------------------------------------------------------------
| 3            |        | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
-------------------------------------------------------------------------------------------
| 4            |        | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
-------------------------------------------------------------------------------------------
| 5            |        | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
-------------------------------------------------------------------------------------------
| 6            |        | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
-------------------------------------------------------------------------------------------
| 7            |        | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
-------------------------------------------------------------------------------------------
| 8            |        | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
-------------------------------------------------------------------------------------------
| 9            |        | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
-------------------------------------------------------------------------------------------

Show parts of myspace, after leader election:

(user@172.25.61.1) [myspace]> show parts;
======================================================================================================
| Partition ID | Leader            | Peers                                                   | Losts |
======================================================================================================
| 1            | 172.25.61.1:44500 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 2            | 172.25.61.1:44500 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 3            | 172.25.61.1:44500 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------
| 4            | 172.25.61.1:44500 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 5            | 172.25.61.1:44500 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 6            | 172.25.61.1:44500 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------
| 7            | 172.25.61.1:44500 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 8            | 172.25.61.1:44500 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 9            | 172.25.61.1:44500 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------

Stop the storaged 172.25.61.1:44500:

(user@172.25.61.1) [myspace]> show hosts;
==============================================================================================
| Ip          | Port  | Status | Leader count | Leader distribution | Partition distribution |
==============================================================================================
| 172.25.61.1 | 44600 | online | 7            | myspace: 7          | myspace: 9             |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44700 | online | 2            | myspace: 2          | myspace: 9             |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44500 | online | 0            | myspace: 0          | myspace: 9             |
----------------------------------------------------------------------------------------------
Got 3 rows (Time spent: 155542/156820 us)

(user@172.25.61.1) [myspace]> show parts;
======================================================================================================
| Partition ID | Leader            | Peers                                                   | Losts |
======================================================================================================
| 1            | 172.25.61.1:44600 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 2            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 3            | 172.25.61.1:44600 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------
| 4            | 172.25.61.1:44600 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 5            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 6            | 172.25.61.1:44700 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------
| 7            | 172.25.61.1:44700 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 8            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 9            | 172.25.61.1:44600 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------

Wait for the expired_threshold_sec(10 * 60) seconds:

(user@172.25.61.1) [myspace]> show hosts;
===============================================================================================
| Ip          | Port  | Status  | Leader count | Leader distribution | Partition distribution |
===============================================================================================
| 172.25.61.1 | 44600 | online  | 7            | myspace: 7          | myspace: 9             |
-----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44700 | online  | 2            | myspace: 2          | myspace: 9             |
-----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44500 | offline | 0            | myspace: 0          | myspace: 9             |
-----------------------------------------------------------------------------------------------
Got 3 rows (Time spent: 2928/3980 us)

(user@172.25.61.1) [myspace]> show parts;
==================================================================================================================
| Partition ID | Leader            | Peers                                                   | Losts             |
==================================================================================================================
| 1            | 172.25.61.1:44600 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 2            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 3            | 172.25.61.1:44600 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 4            | 172.25.61.1:44600 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 5            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 6            | 172.25.61.1:44700 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 7            | 172.25.61.1:44700 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 8            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------
| 9            | 172.25.61.1:44600 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 | 172.25.61.1:44500 |
------------------------------------------------------------------------------------------------------------------

Start the storaged 172.25.61.1:44500 again:

[root@YZ-25-61-1 nebula_install1]# ./scripts/nebula-storaged.service start
[INFO] Starting nebula-storaged...
[INFO] Done

[root@YZ-25-61-1 nebula_install1]# bin/nebula --addr=172.25.61.1  --port=8000  --u=user --p=password

Welcome to Nebula Graph

(user@172.25.61.1) [(none)]> show hosts;
==============================================================================================
| Ip          | Port  | Status | Leader count | Leader distribution | Partition distribution |
==============================================================================================
| 172.25.61.1 | 44600 | online | 7            | myspace: 7          | myspace: 9             |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44700 | online | 2            | myspace: 2          | myspace: 9             |
----------------------------------------------------------------------------------------------
| 172.25.61.1 | 44500 | online | 0            | myspace: 0          | myspace: 9             |
----------------------------------------------------------------------------------------------
Got 3 rows (Time spent: 3776/4860 us)

(user@172.25.61.1) [(none)]> use myspace;
Execution succeeded (Time spent: 1473/2444 us)

(user@172.25.61.1) [myspace]> show parts;
======================================================================================================
| Partition ID | Leader            | Peers                                                   | Losts |
======================================================================================================
| 1            | 172.25.61.1:44600 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 2            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 3            | 172.25.61.1:44600 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------
| 4            | 172.25.61.1:44600 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 5            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 6            | 172.25.61.1:44700 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------
| 7            | 172.25.61.1:44700 | 172.25.61.1:44700, 172.25.61.1:44500, 172.25.61.1:44600 |       |
------------------------------------------------------------------------------------------------------
| 8            | 172.25.61.1:44600 | 172.25.61.1:44500, 172.25.61.1:44600, 172.25.61.1:44700 |       |
------------------------------------------------------------------------------------------------------
| 9            | 172.25.61.1:44600 | 172.25.61.1:44600, 172.25.61.1:44700, 172.25.61.1:44500 |       |
------------------------------------------------------------------------------------------------------

@zhangguoqing zhangguoqing force-pushed the show-parts branch 2 times, most recently from 7102a05 to aeeb9ae Compare October 17, 2019 03:58
@zhangguoqing zhangguoqing changed the title [WIP] Support "show parts" command Support "show parts" command Oct 17, 2019
@zhangguoqing zhangguoqing added the ready-for-testing PR: ready for the CI test label Oct 17, 2019
@nebula-community-bot
Copy link
Member

Unit testing failed.

Copy link
Contributor

@dangleptr dangleptr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool. Could we show the results displayed by console?

@dangleptr
Copy link
Contributor

Jenkins go

@nebula-community-bot
Copy link
Member

Unit testing failed.

@zhangguoqing
Copy link
Contributor Author

That's cool. Could we show the results displayed by console?

of course!

@zhangguoqing
Copy link
Contributor Author

Jenkins go

@nebula-community-bot
Copy link
Member

Unit testing passed.

1 similar comment
@nebula-community-bot
Copy link
Member

Unit testing passed.

@zhangguoqing
Copy link
Contributor Author

Jenkins go

@nebula-community-bot
Copy link
Member

Unit testing passed.

1 similar comment
@nebula-community-bot
Copy link
Member

Unit testing passed.

@dangleptr
Copy link
Contributor

That's cool. Could we show the results displayed by console?

of course!

You could post it in the summary.

@zhangguoqing
Copy link
Contributor Author

That's cool. Could we show the results displayed by console?

of course!

You could post it in the summary.

Thanks, I have updated the summary of this PR.

@dangleptr
Copy link
Contributor

That's cool. Could we show the results displayed by console?

of course!

You could post it in the summary.

Thanks, I have updated the summary of this PR.

I means you could post the results displayed by console in this summary.

@zhangguoqing
Copy link
Contributor Author

zhangguoqing commented Oct 30, 2019

That's cool. Could we show the results displayed by console?

of course!

You could post it in the summary.

Thanks, I have updated the summary of this PR.

I means you could post the results displayed by console in this summary.

Done!

dangleptr
dangleptr previously approved these changes Oct 30, 2019
Copy link
Contributor

@dangleptr dangleptr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

std::string addrStr = network::NetworkUtils::ipFromHostAddr(host);
int32_t port = network::NetworkUtils::portFromHostAddr(host);
std::string portStr = folly::to<std::string>(port);
hostsString += addrStr + ":" + portStr + ", ";
Copy link
Contributor

@dangleptr dangleptr Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

folly::stringPrintf("%s:%d,", addrStr.c_str(), port);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@nebula-community-bot
Copy link
Member

Unit testing passed.

@nebula-community-bot
Copy link
Member

Unit testing failed.

namespace nebula {
namespace meta {

void ListPartsProcessor::process(const cpp2::ListPartsReq& req) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we can support list the partition specified in console? If we have to many partitions, it's hard to look for a single partition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We'd better support to show some part information specified too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result is sorted by partition ID.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we could open another pr for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, would it be better to use the LIMIT clause?

Copy link
Contributor

@critical27 critical27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean code! LGTM

@zhangguoqing
Copy link
Contributor Author

Jenkins go!

@@ -306,6 +306,19 @@ StatusOr<std::vector<HostAddr>> NetworkUtils::toHosts(const std::string& peersSt
return hosts;
}

std::string NetworkUtils::toHosts(const std::vector<HostAddr>& hosts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concatHosts may be a better func name to explain this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx. I prefer the toHosts function overload.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concatHosts +1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the Concat generally refers to joining the same kind of things and returning the original form. For example, joining multiple strings returns a string. There is a formal shift here(HostAddr to String, with the meaning of convert to), not a simple join or concat.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toHosts +1

@nebula-community-bot
Copy link
Member

Unit testing passed.

2 similar comments
@nebula-community-bot
Copy link
Member

Unit testing passed.

@nebula-community-bot
Copy link
Member

Unit testing passed.

@nebula-community-bot
Copy link
Member

Unit testing passed.

Copy link
Contributor

@dangleptr dangleptr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dangleptr dangleptr merged commit e0e2530 into vesoft-inc:master Nov 7, 2019
@jude-zhu
Copy link
Contributor

subtask of #724

yixinglu pushed a commit to yixinglu/nebula that referenced this pull request Feb 16, 2020
tong-hao pushed a commit to tong-hao/nebula that referenced this pull request Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "show parts" command
8 participants