# pruningの予定を決める

> Participant NodeのAdmin APIで、自動pruningの予定をcron式と最大の長さと保持の期間で決め、読み、消す8つのRPCを、日程の型と要求と応答の欄で追います。

- URL: https://cardene.dev/diagrams/canton-pruning-schedule-api
- 公開日: 2026-11-23
- 更新日: 2026-11-23
- トピック: Blockchain
- タグ: Canton
- 親の図解: [ACS commitmentとpruning](https://cardene.dev/diagrams/canton-commitment-and-pruning.md): Participant NodeのAdmin APIで、ACS commitmentの点検と遅れた相手の見張り、安全なoffsetまでのpruning、pruningの予定の設定を、gRPCでどう呼ぶかを4頁で追います。

頁「pruningを自動で回す」では、自動pruningの日程を、Canton Consoleのコマンドで設定し、読み、変え、消しました。
この頁は、同じ操作を、Admin APIの`PruningService`の8つのRPCで行う呼び方を、日程の型と、要求と応答の欄で追います。
前の頁「安全なoffsetまでpruningする」が追った5つと合わせて、`PruningService`の13の操作が、全てそろいます。
RPCは、ネットワーク越しに、別のプログラムの処理を呼び出す操作で、gRPCで呼びます。

:::details gRPC
gRPCは、Googleが開発した、ネットワーク越しに別のプログラムの処理を呼び出すための通信の仕組みです。
:::

日程を組むcron式と最大の長さと保持の期間の意味は、頁「pruningを自動で回す」が追っています。

https://cardene.dev/diagrams/canton-pruning-schedule

前の頁は、`PruningService`の5つのRPCと、待たない相手の型を追っています。

https://cardene.dev/diagrams/canton-pn-pruning

## 日程の型は2つの層で入れ子になる

8つのRPCは、どれも、パッケージ`com.digitalasset.canton.admin.pruning.v30`の型を、要求と応答に使います。
このパッケージは、サービスもエンドポイントも列挙型も持たず、28のメッセージだけを持つgRPCのパッケージです。
ソースのファイルは、`community/admin-api/src/main/protobuf/com/digitalasset/canton/admin/pruning/v30/pruning.proto`の1つで、公式の参照はv3.7.4のタグを指します。

日程を表す型は、2つあります。
1つ目の`PruningSchedule`は、cron式と最大の長さと保持の期間の3つの欄を持ち、内部の状態だけの指定は持ちません。
Durationは、時間の長さを表す型です。

| 欄 | 型 | 持つ物 |
|---|---|---|
| `cron` | 文字列 | cron式 |
| `max_duration` | Duration | 最大の長さ |
| `retention` | Duration | 保持の期間 |

2つ目の`ParticipantPruningSchedule`は、`PruningSchedule`の`schedule`と、boolの`prune_internally_only`を持ちます。
boolは、真か偽のどちらかの値を持つ型です。
`prune_internally_only`は、内部の状態だけの指定です。
内部の状態だけをpruningする事の意味は、頁「台帳を手でpruningする」の`prune_internally`が追っています。

`PruningSchedule`と`ParticipantPruningSchedule`は、型の名前で対になります。
`schedule`は、どちらの型の中でも、`PruningSchedule`を入れる欄の名前です。

図Aは、`ParticipantPruningSchedule`を根に置き、入れ子の型を足します。
段1が2つの欄を足し、段2が`PruningSchedule`の3つの欄を足します。
どちらの段も、型の欄だけを置き、RPCは置きません。

```dragon
mind Participantの日程の型

step 2つの欄
  say 段1です。Participantの日程の型は、日程と、内部の状態だけの指定の、2つの欄を持ちます。
  idea root as "ParticipantPruningSchedule" [color: slate]
  idea sch as "schedule" of root [color: blue]
  idea flag as "prune_internally_only" of root [color: blue]
  source CantonのGetParticipantSchedule [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/getparticipantschedule]

step 日程の3つの欄
  say 段2です。日程の型は、cron式と、最大の長さと、保持の期間の3つの欄を持ちます。
  idea cron as "cron" of sch [color: blue]
  idea maxd as "max_duration" of sch [color: blue]
  idea ret as "retention" of sch [color: blue]
  source CantonのGetSchedule [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/getschedule]
```

## 8つのRPCの欄

8つのRPCは、どれもクライアントからもサーバーからも、続けて何度もデータを送るストリーミングを使いません。
要求と応答のメッセージの名前は、RPCの名前に`Request`と`Response`を付けた形です。
次の表は、8つのRPCのパスと、要求と応答の欄です。

| RPC | パス | 要求の欄 | 応答の欄 |
|---|---|---|---|
| `GetSchedule` | `/com.digitalasset.canton.admin.participant.v30.PruningService/GetSchedule` | 欄を持たない | `PruningSchedule`の`schedule`。日程が無い時は入らない |
| `SetSchedule` | `/com.digitalasset.canton.admin.participant.v30.PruningService/SetSchedule` | `PruningSchedule`の`schedule` | 欄を持たない |
| `GetParticipantSchedule` | `/com.digitalasset.canton.admin.participant.v30.PruningService/GetParticipantSchedule` | 欄を持たない | `ParticipantPruningSchedule`の`schedule`。日程が無い時は入らない |
| `SetParticipantSchedule` | `/com.digitalasset.canton.admin.participant.v30.PruningService/SetParticipantSchedule` | `ParticipantPruningSchedule`の`schedule` | 欄を持たない |
| `SetCron` | `/com.digitalasset.canton.admin.participant.v30.PruningService/SetCron` | 文字列の`cron` | 欄を持たない |
| `SetMaxDuration` | `/com.digitalasset.canton.admin.participant.v30.PruningService/SetMaxDuration` | Durationの`max_duration` | 欄を持たない |
| `SetRetention` | `/com.digitalasset.canton.admin.participant.v30.PruningService/SetRetention` | Durationの`retention` | 欄を持たない |

「欄を持たない」応答は、成功の応答です。
| `ClearSchedule` | `/com.digitalasset.canton.admin.participant.v30.PruningService/ClearSchedule` | 欄を持たない | 欄を持たない |

`PruningSchedule`を使う`GetSchedule`と`SetSchedule`と、`ParticipantPruningSchedule`を使う`GetParticipantSchedule`と`SetParticipantSchedule`は、名前が似ていますが、使う型が違います。
Consoleで、`pruning.get_participant_schedule`が、通常の日程に加えて、内部の状態のpruningを求めるかを示す事は、頁「pruningを自動で回す」が追っています。

読む2つのRPCの応答の`schedule`は、日程が設定されていない時と、消した後は、入りません。
Consoleの`pruning.get_schedule`も、設定が無い時と`clear_schedule`の後は、`None`を返します。
個別に変える`SetCron`と`SetMaxDuration`と`SetRetention`は、設定済みの日程に対して働き、日程が無い時と、消した後は、エラーを返します。

`pruning.v30`のパッケージの28のメッセージには、pruningの時刻を探す`FindPruningTimestampRequest`と`FindPruningTimestampResponse`の組も入ります。
`FindPruningTimestampRequest`はint32の`index`を、`FindPruningTimestampResponse`はTimestampの`timestamp`を持ちます。
int32は、32ビットの符号付きの整数の型で、Timestampは、時刻の型です。
`PruningService`の13の操作の要求と応答には、この組は現れません。

commitmentを待たない相手の取得と設定と解除の型と、`WaitCommitmentsSetup`と`Synchronizers`は、前の頁「安全なoffsetまでpruningする」の節「commitmentを待たない相手を決める」が追っています。

## 日程を設定する

自動pruningの日程は、Participant Nodeが古いデータを消す時刻と、消す範囲を決めます。
設定する前に、Participant Nodeのバックアップの仕組みを整え、pruningのたびにバックアップを取ります。
どこまで消すかは、保持の期間が、今の時刻からの長さで決めます。
offsetを明示して消す手動のpruningと、安全なoffsetの求め方は、前の頁「安全なoffsetまでpruningする」が追っています。

`grpcurl`は、gRPCのサーバーのRPCを、JSONで呼び出すための道具です。
`grpcurl`の例は、`SetSchedule`に、`cron`と`maxDuration`と`retention`を持つ`schedule`を送ります。
JSONの欄の名前は、protoの欄の名前をcamelCaseにした形です。
camelCaseは、単語をつなぎ、2つ目からの単語の頭を大文字にする書き方です。

:::details JSON
JSONは、データを文字で表すための形式で、Webのプログラムどうしのデータのやり取りに広く使われています。
:::

接続先のホスト名とポートをコロンでつないだ値を、シェルの変数`HOST_PORT`に設定します。
例では、変数を引用符で囲んで渡し、TLSを使わないサーバーを呼ぶ時は、`-plaintext`を足します。

:::details TLS
TLSは、ネットワークの通信を暗号化し、通信の相手が本物かを証明書で確かめるための規格です。
WebサイトのHTTPSの通信も、TLSを使っています。
:::

次の例は、毎週土曜の8時から8時間を最大の長さとし、90日を保持の期間とする日程を設定します。
cron式は、頁「pruningを自動で回す」の例と同じです。
Durationは、JSONでは、秒数に`s`を付けた文字列で表されるので、8時間は`"28800s"`、90日は`"7776000s"`です。
この値は、手元の運用に合わせて差し替える例です。

```bash
# Add -plaintext if the server is not using TLS.
grpcurl \
  -d @ \
  "$HOST_PORT" \
  com.digitalasset.canton.admin.participant.v30.PruningService/SetSchedule <<'EOF'
{
  "schedule": {
    "cron": "0 0 8 ? * SAT",
    "maxDuration": "28800s",
    "retention": "7776000s"
  }
}
EOF
```

OKの応答の例は、空のJSON`{}`です。

次の表は、ほかのRPCの例の要求と応答です。
読むRPCの応答は、設定済みの例と、日程が無い時の例を、別の行に置きます。
`true`は、内部の状態だけをpruningする指定を求める値の例です。

| RPC | 例の要求 | 例の応答 |
|---|---|---|
| `GetSchedule`。設定済み | `{}` | `{"schedule": {"cron": "0 0 8 ? * SAT", "maxDuration": "28800s", "retention": "7776000s"}}` |
| `GetSchedule`。未設定か消した後 | `{}` | `{}` |
| `GetParticipantSchedule`。設定済み | `{}` | `{"schedule": {"schedule": {"cron": "0 0 8 ? * SAT", "maxDuration": "28800s", "retention": "7776000s"}, "pruneInternallyOnly": true}}` |
| `GetParticipantSchedule`。未設定か消した後 | `{}` | `{}` |
| `SetParticipantSchedule` | `{"schedule": {"schedule": {"cron": "0 0 8 ? * SAT", "maxDuration": "28800s", "retention": "7776000s"}, "pruneInternallyOnly": true}}` | `{}` |
| `SetCron` | `{"cron": "0 0 8 ? * SAT"}` | `{}` |
| `SetMaxDuration` | `{"maxDuration": "28800s"}` | `{}` |
| `SetRetention` | `{"retention": "7776000s"}` | `{}` |

個別に変える3つの例は、日程を設定した後に呼んだ時の成功の応答で、日程が無い時と、消した後は、エラーになります。

## 予定を消す

`ClearSchedule`は、欄を持たない要求を受け取り、欄を持たない応答を返します。
日程を消して、自動pruningを止め、その後は、`SetCron`と`SetRetention`と`SetMaxDuration`がエラーを返します。
Consoleの`pruning.clear_schedule`の働きは、頁「pruningを自動で回す」が追っています。

## 8つのRPCの要求と応答

図Bは、呼び出す側とParticipant NodeのAdmin APIの2つの箱で、8つのRPCの要求と応答を、1つのRPCにつき1つの段で追います。
呼び出す側は、例の`grpcurl`です。
段1と段2が日程を全て読み書きする段で、段3と段4がParticipantの日程を読み書きする段です。
段5から段7は、日程の1つの欄だけを変える段で、段8が日程を消す段です。

この図では、8つのRPCを呼ぶ順を示しません。

```dragon
sequence pruningの予定を読み書きして消す

box G as 呼び出す側 [note: gRPCの呼び出しを送る, color: slate, icon: exe]
box S as Participant NodeのAdmin API [note: ホスト名とポートで指定する, color: rose, icon: server]

step 日程を読む
  say 段1です。日程を読むRPCは、欄の無い要求を送り、設定済みなら、cron式と最大の長さと保持の期間を持つ日程を受け取ります。未設定か消した後は、日程の欄が入りません。
  G -> S: 空の要求
  S -> G: 日程か欄なし
  source CantonのGetSchedule [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/getschedule]

step 日程を設定する
  say 段2です。日程を設定するRPCは、日程を送り、欄の無い応答を受け取ります。
  G -> S: 日程
  S -> G: 空の応答
  source CantonのSetSchedule [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setschedule]

step Participantの日程を読む
  say 段3です。Participantの日程を読むRPCは、欄の無い要求を送り、設定済みなら、日程と、内部の状態だけの指定を受け取ります。未設定か消した後は、日程の欄が入りません。
  G -> S: 空の要求
  S -> G: 日程と内部の状態だけの指定
  source CantonのGetParticipantSchedule [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/getparticipantschedule]

step Participantの日程を設定する
  say 段4です。Participantの日程を設定するRPCは、日程と、内部の状態だけの指定を送り、欄の無い応答を受け取ります。
  G -> S: 日程と内部の状態だけの指定
  S -> G: 空の応答
  source CantonのSetParticipantSchedule [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setparticipantschedule]

step cron式だけを設定する
  say 段5です。cron式だけを設定するRPCは、文字列を1つ送ります。設定済みの日程に対して働き、成功すると、欄の無い応答を受け取ります。
  G -> S: cron式
  S -> G: 空の応答
  source CantonのSetCron [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setcron]

step 最大の長さだけを設定する
  say 段6です。最大の長さだけを設定するRPCは、時間の長さを1つ送ります。設定済みの日程に対して働き、成功すると、欄の無い応答を受け取ります。
  G -> S: 最大の長さ
  S -> G: 空の応答
  source CantonのSetMaxDuration [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setmaxduration]

step 保持の期間だけを設定する
  say 段7です。保持の期間だけを設定するRPCも、時間の長さを1つ送ります。設定済みの日程に対して働き、成功すると、欄の無い応答を受け取ります。
  G -> S: 保持の期間
  S -> G: 空の応答
  source CantonのSetRetention [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setretention]

step 予定を消す
  say 段8です。予定を消すRPCは、欄の無い要求を送り、欄の無い応答を受け取り、自動pruningが止まります。
  G -> S: 空の要求
  S -> G: 空の応答
  source CantonのClearSchedule [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/clearschedule]
```

## 出典

https://docs.canton.network/reference/admin-api/protobuf/packages/com-digitalasset-canton-admin-participant-v30

https://docs.canton.network/reference/admin-api/protobuf/packages/com-digitalasset-canton-admin-pruning-v30

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/getschedule

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setschedule

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/getparticipantschedule

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setparticipantschedule

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setcron

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setmaxduration

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/setretention

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/pruningservice/clearschedule
