Skip to content

Commit a8291ea

Browse files
committed
MGM: GroupBalancer/Drainer: make file filter configurable
Make the function that selects files allow a filter argument which defaults to Null so that GroupBalancer can filter out proc files whereas the GroupDrainer needs to not skip these. Fixes: EOS-6382 Signed-off-by: Abhishek Lekshmanan <abhishek.lekshmanan@cern.ch>
1 parent a24ae7d commit a8291ea

File tree

6 files changed

+65
-24
lines changed

6 files changed

+65
-24
lines changed

mgm/GroupBalancer.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ EOSMGMNAMESPACE_BEGIN
4141
using group_balancer::BalancerEngineT;
4242
using group_balancer::group_size_map;
4343
using group_balancer::eosGroupsInfoFetcher;
44-
44+
using group_balancer::PrefixFilter;
4545

4646
//-------------------------------------------------------------------------------
4747
// GroupBalancer constructor
4848
//-------------------------------------------------------------------------------
4949
GroupBalancer::GroupBalancer(const char* spacename)
50-
: mSpaceName(spacename), mLastCheck(0)
50+
: mSpaceName(spacename), mLastCheck(0),
51+
mProcFilter(PrefixFilter(gOFS->MgmProcPath.c_str()))
5152
{
5253
mEngine.reset(group_balancer::make_balancer_engine(BalancerEngineT::stddev));
5354
mThread.reset(&GroupBalancer::GroupBalance, this);
@@ -216,7 +217,8 @@ GroupBalancer::chooseFileFromGroup(FsGroup* from_group, FsGroup* to_group,
216217

217218
auto filename = group_balancer::getFileProcTransferNameAndSize(fid,
218219
to_group->mName,
219-
&filesize);
220+
&filesize,
221+
mProcFilter);
220222

221223
if (filename.empty() ||
222224
(mCfg.mMinFileSize > filesize) ||

mgm/GroupBalancer.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <map>
3434
#include <unordered_set>
3535
#include "mgm/groupbalancer/BalancerEngineTypes.hh"
36+
#include "mgm/groupbalancer/ConverterUtils.hh"
3637

3738
EOSMGMNAMESPACE_BEGIN
3839

@@ -158,7 +159,7 @@ private:
158159
//! Scheduled transfers (maps fid to path in proc)
159160
std::map<eos::common::FileId::fileid_t, std::string> mTransfers;
160161
group_balancer::engine_conf_t mEngineConf;
161-
162+
group_balancer::SkipFileFn mProcFilter;
162163

163164
//----------------------------------------------------------------------------
164165
//! Chooses a random file ID from a random filesystem in the given group

mgm/GroupDrainer.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ GroupDrainer::scheduleTransfer(eos::common::FileId::fileid_t fid,
313313
}
314314

315315
uint64_t filesz;
316-
auto conv_tag = getFileProcTransferNameAndSize(fid, tgt_grp, &filesz);
316+
auto conv_tag = getFileProcTransferNameAndSize(fid, tgt_grp, &filesz,
317+
group_balancer::NullFilter);
317318

318319
if (conv_tag.empty()) {
319320
eos_err("msg=\"Possibly failed proc file found\" fid=%08llx", fid);

mgm/groupbalancer/ConverterUtils.cc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
//
2-
// Created by abhi on 4/26/22.
3-
//
4-
51
#include "ConverterUtils.hh"
2+
3+
#include "common/StringUtils.hh"
64
#include "common/Logging.hh"
75
#include "common/LayoutId.hh"
86
#include "namespace/Prefetcher.hh"
@@ -12,10 +10,14 @@
1210

1311
namespace eos::mgm::group_balancer
1412
{
13+
bool PrefixFilter::operator()(std::string_view path) {
14+
return eos::common::startsWith(path, prefix);
15+
}
1516

1617
std::string
1718
getFileProcTransferNameAndSize(eos::common::FileId::fileid_t fid,
18-
const std::string& target_group, uint64_t* size)
19+
const std::string& target_group, uint64_t* size,
20+
const SkipFileFn& skip_file_fn)
1921
{
2022
char fileName[1024];
2123
std::shared_ptr<eos::IFileMD> fmd;
@@ -34,19 +36,16 @@ getFileProcTransferNameAndSize(eos::common::FileId::fileid_t fid,
3436
return std::string("");
3537
}
3638

37-
if (size) {
38-
*size = fmd->getSize();
39+
if (skip_file_fn && skip_file_fn(gOFS->eosView->getUri(fmd.get()))) {
40+
return std::string("");
3941
}
4042

41-
XrdOucString fileURI = gOFS->eosView->getUri(fmd.get()).c_str();
42-
43-
if (fileURI.beginswith(gOFS->MgmProcPath.c_str())) {
44-
// don't touch files in any ../proc/ directory
45-
return std::string("");
43+
if (size) {
44+
*size = fmd->getSize();
4645
}
4746

48-
eos_static_debug("msg=\"found file for transfering\" file=\"%s\"",
49-
fileURI.c_str());
47+
eos_static_debug("msg=\"found file for transfering\" fid=\"%08llx\"",
48+
fileid);
5049
} catch (eos::MDException& e) {
5150
eos_static_debug("msg=\"exception\" ec=%d emsg=\"%s\"\n", e.getErrno(),
5251
e.getMessage().str().c_str());

mgm/groupbalancer/ConverterUtils.hh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,39 @@
2424
#ifndef EOS_CONVERTERUTILS_HH
2525
#define EOS_CONVERTERUTILS_HH
2626

27+
#include <functional>
28+
#include <string_view>
29+
2730
#include "common/FileId.hh"
2831
#include <string>
2932

3033
namespace eos::mgm::group_balancer
3134
{
35+
36+
using SkipFileFn = std::function<bool(std::string_view)>;
37+
inline const SkipFileFn NullFilter = {};
38+
39+
struct PrefixFilter {
40+
bool operator()(std::string_view path);
41+
std::string prefix;
42+
PrefixFilter(std::string_view _prefix): prefix(_prefix) {}
43+
};
44+
3245
//----------------------------------------------------------------------------
3346
//! Produces a file conversion path to be placed in the proc directory taking
3447
//! into account the given group and also returns its size
3548
//!
3649
//! @param fid the file ID
3750
//! @param target_group the group to which the file will be transferred
3851
//! @param size return address for the size of the file
52+
//! @param skip_file_fn function to skip files matching filter
53+
//! defaults to NullFilter, which means no files will be skipped
3954
//!
4055
//! @return name of the proc transfer file
4156
//----------------------------------------------------------------------------
4257
std::string
4358
getFileProcTransferNameAndSize(eos::common::FileId::fileid_t fid,
44-
const std::string& target_group, uint64_t* size);
45-
59+
const std::string& target_group, uint64_t* size,
60+
const SkipFileFn& skip_file_fn = NullFilter);
4661
} // eos::mgm::group_balancer
4762
#endif // EOS_CONVERTERUTILS_HH

unit_tests/mgm/groupbalancer/GroupBalancerUtilsTests.cc

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#include "gtest/gtest.h"
22
#include "mgm/groupbalancer/BalancerEngineUtils.hh"
3+
#include "mgm/groupbalancer/ConverterUtils.hh"
34

45
using namespace eos::mgm::group_balancer;
56

6-
7-
8-
97
TEST(GroupBalancerUtils, Avg)
108
{
119
EXPECT_DOUBLE_EQ(0, calculateAvg({}));
@@ -84,3 +82,28 @@ TEST(GroupBalancerUtils, extract_commalist_value)
8482
EXPECT_EQ(empty,
8583
extract_commalist_value(conf, "some key"));
8684
}
85+
86+
// a function that behaves like the skipFiles call in
87+
// getProcTransferNameAndSize
88+
std::string fakeSkipFile(const SkipFileFn& skip_file_fn,
89+
std::string_view path)
90+
{
91+
if (skip_file_fn && skip_file_fn(path)) {
92+
return std::string("");
93+
}
94+
return std::string(path);
95+
}
96+
97+
TEST(GroupBalancerUtils, SkipFilesNullFilter)
98+
{
99+
EXPECT_FALSE(NullFilter);
100+
EXPECT_EQ("/proc/foo",fakeSkipFile(NullFilter, "/proc/foo"));
101+
EXPECT_EQ("/00001/bar",fakeSkipFile(NullFilter, "/00001/bar"));
102+
}
103+
104+
TEST(GroupBalancerUtils, SkipFiles)
105+
{
106+
PrefixFilter procFilter{"/proc/"};
107+
EXPECT_EQ("", fakeSkipFile(procFilter, "/proc/foo"));
108+
EXPECT_EQ("/000001/bar",fakeSkipFile(procFilter, "/000001/bar"));
109+
}

0 commit comments

Comments
 (0)