8000 デバイスを落とせるようにする by koba-e964 · Pull Request #319 · frugalos/frugalos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

デバイスを落とせるようにする #319

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

Merged
merged 8 commits into from
Oct 23, 2020

Conversation

koba-e964
Copy link
Contributor
@koba-e964 koba-e964 commented Aug 3, 2020

Types of changes

Please check one of the following:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • New release (merge to both master and develop!)

Description of changes

Behavior

/v1/devices/:device_id/state に以下のような JSON を PUT することで、指定されたデバイス ID を持つデバイスを落とせるようにする。

{"state":"stopped"}

制約は以下の通り:

  • 物理デバイスしか落とせない。
  • リクエストの送り先が保持するデバイスしか落とせない。

また、GET /v1/devices/:device_id/state が、指定されたデバイス ID を持つデバイスが現在動作しているかを返すようにする。
レスポンスは以下のうちどちらか:

{"state":"started"} # 動いている
{"state":"stopped"} # 止まっている

Purpose

デバイスを外部から手動で落とせるようにする。

リクエストの流れ

デバイス停止・デバイスの情報取得リクエストの処理の流れ:

config_server

|
V

daemon

|
V

service

 - Service::stop_device, Service::get_device_state

|
V

frugalos_segment/service.rs
Service
stop_device, get_device_state

|
V

cannyls_rpc/DeviceRegistry
stop_device, is_device_running

|
V

cannyls::device::Device::stop (no need of change)

未解決事項

デバイスを落とす時に MDS node が CRIT エラーを出して止まる。これは後の PR で対応する予定。

依存 PR: frugalos/cannyls#48

How to test this PR

scripts/setup_debug_cluster.sh で起動できるローカルクラスタを起動し、以下を実行する:

curl localhost:3100/v1/devices/live_archive_chunk/state

この状態では (まだデバイスを停止していないため) {"state":"started"} が返る。その後、以下を実行する:

curl -XPUT localhost:3100/v1/devices/live_archive_chunk/state -d '{"state":"stopped"}'

その後、以下を実行すると、{"state":"stopped"} が返る。

curl localhost:3100/v1/devices/live_archive_chunk/state

注記事項

cargo のバージョンアップに伴って Cargo.lock のフォーマットが変わっている。おそらく rust-lang/cargo#7579 の変更が入ったことによるものである。本来別の PR として分けるべきであるが、それによって起こるであろう Cargo.lock のコンフリクトを解消する手間を避けるためにこのままにする。

TODOs

  • cannyls_rpc 0.3.1 を取り込む

Checklists

  • Run cargo fmt --all.
  • Run cargo clippy --all --all-targets.

@koba-e964 koba-e964 force-pushed the feature/add-device-state branch 2 times, most recently from 5363bc4 to e633b52 Compare September 30, 2020 09:02
@shinnya shinnya added this to the v1.2.0 milestone Oct 1, 2020
@koba-e964 koba-e964 force-pushed the feature/add-device-state branch from 2274999 to afea4f1 Compare October 6, 2020 09:15
@koba-e964 koba-e964 marked this pull request as ready for review October 14, 2020 01:47
Cargo.toml Outdated
@@ -41,7 +41,7 @@ raftlog = "0.6"
rustracing = "0.1"
rustracing_jaeger = "0.1"
siphasher = "0.2"
slog = "2"
slog = { version = "2", features = ["max_level_debug"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

今回の変更で max_level_debug はなぜ必要なんでしょうか。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

実験用にやっていたのが混入してしまいました。削除します

Copy link
Contributor Author

Choose a reason for hiding this comment

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

削除しました

@koba-e964 koba-e964 force-pushed the feature/add-device-state branch from 5857183 to 1cae6db Compare October 19, 2020 09:12
src/service.rs Outdated
8000
false
}
/// 単にデバイスのデータを取得するだけなら device_seqno は不要だが、ログ出力のために受け取っておく。
pub fn get_device_state(&mut self, device_seqno: u32, device_id: &DeviceId) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

get_device_state の返り値が bool というのは意味が直感的に理解しづらいように思います。DeviceState という struct が追加されているのでそれを返せばいいんじゃないでしょうか。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DeviceState を返すようにしました 50c2c72

src/daemon.rs Outdated
device_id: DeviceId,
) -> impl Future<Item = bool, Error = Error> {
let (reply_tx, reply_rx) = oneshot::monitor();
// TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

何が TODO なのか分からないのでそれも書いておいていただけると助かります。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

この TODO は消し残しだったので消しました 6d7ca2e

do
for device in `seq 1 $DEVICES_PER_SERVER`
do
for server in $SERVERS; do
Copy link
Contributor

Choose a reason for hiding this comment

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

このファイルを変更している理由は何なんでしょうか。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

最後の行に set +x を追加して、 put_devices.sh による余計な行の出力を suppress したかったからでした。(フォーマットが変わっているのはエディタの仕様で勝手にフォーマットされたためです。)
ただ、よく調べてみたら別に必要ではなかったので、このファイルの変更は revert しようと思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

なるほど。set +x を追加するにしても他の行は変更せずにそれだけ追加するのがいいんじゃないかと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

revert しました f7cbb4b

src/service.rs Outdated
@@ -128,6 +128,41 @@ where
pub fn stop(&mut self) {
self.frugalos_segment_service.stop();
}
/// 単に止めるためだけなら device_seqno は不要だが、ログ出力のために受け取っておく。
Copy link
Contributor

Choose a reason for hiding this comment

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

/// には description を書いた方がよくて、コードに対するコメントであれば // で十分じゃないでしょうか。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

修正しました 6d7ca2e

src/daemon.rs Outdated
reply: reply_tx,
};
let _ = self.command_tx.send(command);
StopDevice(reply_rx)
Copy link
Contributor

Choose a reason for hiding this comment

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

get_device_stateStopDevice という struct を返すのは妙な感じがします。別の struct を定義するか、単純に MonitorErrormap_err するだけで十分じゃないでしょうか。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

コピペの変更漏れだと思います。修正します

Copy link
Contributor Author
@koba-e964 koba-e964 Oct 22, 2020

Choose a reason for hiding this comment

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

修正しました (reply_rx を単に map_err しました) 6d7ca2e

@koba-e964 koba-e964 force-pushed the feature/add-device-state branch from b47c26d to 6f0f3ac Compare October 19, 2020 10:58
@koba-e964 koba-e964 force-pushed the feature/add-device-state branch from 6f0f3ac to f7cbb4b Compare October 19, 2020 11:02
@koba-e964 koba-e964 merged commit f4ddf69 into develop Oct 23, 2020
@koba-e964 koba-e964 deleted the feature/add-device-state branch October 23, 2020 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0