-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstorage.rs
More file actions
161 lines (135 loc) · 4.28 KB
/
storage.rs
File metadata and controls
161 lines (135 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! Storage management for Curio.
//!
//! Handles attaching fast-storage and long-term-storage locations.
use super::super::step::SetupContext;
use super::constants::{
CURIO_FAST_STORAGE_PATH, CURIO_LONG_TERM_STORAGE_PATH, STORAGE_ATTACH_WAIT_SECS,
};
use crate::docker::command_logger::run_and_log_command;
use std::error::Error;
use std::thread;
use std::time::Duration;
use tracing::info;
/// Wait for Curio RPC to be ready using the built-in wait-api command.
fn wait_for_curio_rpc(context: &SetupContext, container_name: &str) -> Result<(), Box<dyn Error>> {
info!("Waiting for Curio RPC to be ready...");
let machine_addr = format!("{}:12300", container_name);
let key = format!("curio_wait_api_{}", container_name);
let output = run_and_log_command(
"docker",
&[
"exec",
container_name,
"/usr/local/bin/lotus-bins/curio",
"cli",
"--machine",
&machine_addr,
"wait-api",
],
context,
&key,
)?;
if !output.status.success() {
return Err(format!(
"Curio RPC failed to become ready: {}",
String::from_utf8_lossy(&output.stderr)
)
.into());
}
info!("Curio RPC is ready");
Ok(())
}
/// Attach storage locations for a specific PDP SP.
///
/// Attaches:
/// 1. Fast storage (seal)
/// 2. Long-term storage (store)
pub fn attach_storage_locations(
context: &SetupContext,
sp_index: usize,
) -> Result<(), Box<dyn Error>> {
info!("Attaching storage locations for PDP SP {}...", sp_index);
let run_id = context.run_id();
let container_name = format!("foc-{}-curio-{}", run_id, sp_index);
// Wait for RPC to be ready before attaching storage
wait_for_curio_rpc(context, &container_name)?;
// Attach fast storage
attach_fast_storage(context, &container_name)?;
// Attach long-term storage
attach_long_term_storage(context, &container_name)?;
info!("Storage locations attached for PDP SP {}", sp_index);
Ok(())
}
/// Attach fast storage for sealing operations.
fn attach_fast_storage(context: &SetupContext, container_name: &str) -> Result<(), Box<dyn Error>> {
info!("Attaching fast storage...");
// Use container DNS name for --machine flag so it works in Docker networks
let machine_addr = format!("{}:12300", container_name);
let key = format!("curio_storage_attach_fast_{}", container_name);
let output = run_and_log_command(
"docker",
&[
"exec",
container_name,
"/usr/local/bin/lotus-bins/curio",
"cli",
"--machine",
&machine_addr,
"storage",
"attach",
"--init",
"--seal",
CURIO_FAST_STORAGE_PATH,
],
context,
&key,
)?;
if !output.status.success() {
return Err(format!(
"Failed to attach fast storage: {}",
String::from_utf8_lossy(&output.stderr)
)
.into());
}
thread::sleep(Duration::from_secs(STORAGE_ATTACH_WAIT_SECS));
info!("Fast storage attached");
Ok(())
}
/// Attach long-term storage for storing sealed sectors.
fn attach_long_term_storage(
context: &SetupContext,
container_name: &str,
) -> Result<(), Box<dyn Error>> {
info!("Attaching long-term storage...");
// Use container DNS name for --machine flag so it works in Docker networks
let machine_addr = format!("{}:12300", container_name);
let key = format!("curio_storage_attach_long_term_{}", container_name);
let output = run_and_log_command(
"docker",
&[
"exec",
container_name,
"/usr/local/bin/lotus-bins/curio",
"cli",
"--machine",
&machine_addr,
"storage",
"attach",
"--init",
"--store",
CURIO_LONG_TERM_STORAGE_PATH,
],
context,
&key,
)?;
if !output.status.success() {
return Err(format!(
"Failed to attach long-term storage: {}",
String::from_utf8_lossy(&output.stderr)
)
.into());
}
thread::sleep(Duration::from_secs(STORAGE_ATTACH_WAIT_SECS));
info!("Long-term storage attached");
Ok(())
}