Skip to content

Commit 9a122ff

Browse files
Rafael SteilRafSteilShopify
authored andcommitted
[Custom Patch] Check dstdir available space before starting new plot
Reference: ericaltendorf#122
1 parent ac606ff commit 9a122ff

File tree

7 files changed

+38
-12
lines changed

7 files changed

+38
-12
lines changed

src/plotman/_tests/manager_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def sched_cfg():
1414
polling_time_s=2,
1515
tmpdir_stagger_phase_major=3,
1616
tmpdir_stagger_phase_minor=0,
17-
tmpdir_max_jobs=3
17+
tmpdir_max_jobs=3,
18+
stop_when_dst_full=False
1819
)
1920

2021
@pytest.fixture

src/plotman/archive.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ def archive(dir_cfg, all_jobs):
159159
return(False, 'No free archive dirs found.')
160160

161161
archdir = ''
162-
available = [(d, space) for (d, space) in archdir_freebytes.items() if
163-
space > 1.2 * plot_util.get_k32_plotsize()]
162+
available = [(d, space) for (d, space) in archdir_freebytes.items() if plot_util.enough_space_for_k32(space)]
164163
if len(available) > 0:
165164
index = min(dir_cfg.archive.index, len(available) - 1)
166165
(archdir, freespace) = sorted(available)[index]

src/plotman/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Scheduling:
9292
tmpdir_stagger_phase_major: int
9393
tmpdir_stagger_phase_minor: int
9494
tmpdir_stagger_phase_limit: int = 1 # If not explicit, "tmpdir_stagger_phase_limit" will default to 1
95+
stop_when_dst_full: bool = False
9596

9697
@attr.frozen
9798
class Plotting:

src/plotman/manager.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,24 @@ def maybe_start_new_plot(dir_cfg, sched_cfg, plotting_cfg):
9090
rankable = [ (d, phases[0]) if phases else (d, job.Phase(known=False))
9191
for (d, phases) in eligible ]
9292

93-
if not eligible:
93+
# Select the dst dir least recently selected
94+
dst_dir = dir_cfg.get_dst_directories()
95+
96+
dir2ph = { d:ph for (d, ph) in dstdirs_to_youngest_phase(jobs).items()
97+
if d in dst_dir and ph is not None and plot_util.is_valid_plot_dst(d, sched_cfg, jobs)}
98+
unused_dirs = [d for d in dst_dir if d not in dir2ph.keys() and plot_util.is_valid_plot_dst(d, sched_cfg, jobs)]
99+
100+
if not unused_dirs and not dir2ph:
101+
wait_reason = 'no eligible dstdirs'
102+
elif not eligible:
94103
wait_reason = 'no eligible tempdirs (%ds/%ds)' % (youngest_job_age, global_stagger)
95104
else:
96105
# Plot to oldest tmpdir.
97106
tmpdir = max(rankable, key=operator.itemgetter(1))[0]
98-
99-
# Select the dst dir least recently selected
100-
dst_dir = dir_cfg.get_dst_directories()
107+
101108
if dir_cfg.dst_is_tmp():
102109
dstdir = tmpdir
103110
else:
104-
dir2ph = { d:ph for (d, ph) in dstdirs_to_youngest_phase(jobs).items()
105-
if d in dst_dir and ph is not None}
106-
unused_dirs = [d for d in dst_dir if d not in dir2ph.keys()]
107-
dstdir = ''
108111
if unused_dirs:
109112
dstdir = random.choice(unused_dirs)
110113
else:

src/plotman/plot_util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import re
44
import shutil
55

6+
from plotman import job
7+
68
GB = 1_000_000_000
79

810
def df_b(d):
@@ -13,6 +15,22 @@ def df_b(d):
1315
def get_k32_plotsize():
1416
return 108 * GB
1517

18+
def is_valid_plot_dst(d, sched_cfg, all_jobs):
19+
if sched_cfg.stop_when_dst_full:
20+
space = df_b(d)
21+
# Subtract space for current jobs which will be moved to the dir
22+
# Note: This is underestimates the free space available when a
23+
# job is in phase 4 since the plot is partially moved to dst,
24+
# once phase 4 is complete a new plot will eventually kick off
25+
jobs_to_dstdir = job.job_phases_for_dstdir(d, all_jobs)
26+
space -= len(jobs_to_dstdir) * get_k32_plotsize()
27+
return enough_space_for_k32(space)
28+
return True
29+
30+
def enough_space_for_k32(b):
31+
'Determine if there is enough space for a k32 given a number of free bytes'
32+
return b > 1.2 * get_k32_plotsize()
33+
1634
def human_format(num, precision):
1735
magnitude = 0
1836
while abs(num) >= 1000:

src/plotman/plotman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def main():
171171
csv_exporter.export(logfilenames, args.save_to)
172172

173173
else:
174-
jobs = Job.get_running_jobs(cfg.directories.log())
174+
jobs = Job.get_running_jobs(cfg.directories.log)
175175

176176
# Status report
177177
if args.cmd == 'status':

src/plotman/resources/plotman.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ scheduling:
113113
# How often the daemon wakes to consider starting a new plot job, in seconds.
114114
polling_time_s: 20
115115

116+
# Stop initiating new plots when a dst is full, default to False since
117+
# archiving job should move other plots before plotting is completed
118+
stop_when_dst_full: False
119+
116120

117121
# Plotting parameters. These are pass-through parameters to chia plots create.
118122
# See documentation at

0 commit comments

Comments
 (0)