Skip to content

Commit b3d5161

Browse files
committed
duplicate worker fix
Signed-off-by: elestrias <rus8-2002@mail.ru>
1 parent 1e08815 commit b3d5161

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

core/primitives/sector_file/sector_file.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ namespace fc::primitives::sector_file {
8383
struct SectorPaths {
8484
public:
8585
SectorId id;
86-
std::string unsealed;
87-
std::string sealed;
88-
std::string cache;
89-
std::string update;
90-
std::string update_cache;
86+
std::string unsealed{};
87+
std::string sealed{};
88+
std::string cache{};
89+
std::string update{};
90+
std::string update_cache{};
9191

9292
void setPathByType(const SectorFileType &file_type,
9393
const std::string &path);

core/primitives/types.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace fc::primitives {
3939
struct FsStat {
4040
uint64_t capacity = 0;
4141
uint64_t available = 0;
42-
uint64_t fs_available = 0; // Available to use for sector storage
42+
uint64_t fs_available = 0; // Available to use for sector storage
4343
uint64_t reserved = 0;
4444
uint64_t max = 0;
4545
uint64_t used = 0;
@@ -91,6 +91,14 @@ namespace fc::primitives {
9191
std::vector<std::string> gpus;
9292
};
9393

94+
inline bool operator==(const WorkerResources &lhs,
95+
const WorkerResources &rhs) {
96+
return (lhs.physical_memory == rhs.physical_memory
97+
&& lhs.swap_memory == rhs.swap_memory
98+
&& lhs.reserved_memory == rhs.reserved_memory
99+
&& lhs.cpus == rhs.cpus && lhs.gpus == rhs.gpus);
100+
}
101+
94102
struct WorkerInfo {
95103
std::string hostname;
96104
WorkerResources resources;

core/sector_storage/impl/manager_impl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ namespace fc::sector_storage {
260260

261261
worker_handler->worker = std::move(worker);
262262
worker_handler->info = std::move(info);
263-
264263
scheduler_->newWorker(std::move(worker_handler));
265264

266265
return outcome::success();

core/sector_storage/impl/scheduler_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ namespace fc::sector_storage {
137137

138138
void SchedulerImpl::newWorker(std::unique_ptr<WorkerHandle> worker) {
139139
std::unique_lock<std::mutex> lock(workers_lock_);
140+
for(const auto &[key, value] : workers_){
141+
if(*value == *worker){
142+
return;
143+
}
144+
}
140145
if (current_worker_id_ == std::numeric_limits<uint64_t>::max()) {
141146
current_worker_id_ = 0; // TODO(ortyomka): maybe better mechanism
142147
}

core/sector_storage/selector.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ namespace fc::sector_storage {
2424
ActiveResources active;
2525
};
2626

27+
inline bool operator==(const WorkerHandle &lhs, const WorkerHandle &rhs) {
28+
return lhs.info.hostname == rhs.info.hostname
29+
&& lhs.info.resources == rhs.info.resources;
30+
}
31+
2732
class WorkerSelector {
2833
public:
2934
virtual ~WorkerSelector() = default;

0 commit comments

Comments
 (0)