Commit b564edc3 authored by Georgios Bitzes's avatar Georgios Bitzes

NS: Move UsageInfo struct to QuotaNodeCore

parent 94cfdc7c
......@@ -21,6 +21,9 @@
//! @brief Quota node core logic, shared between the two namespaces
//------------------------------------------------------------------------------
#ifndef EOS_NS_COMMON_QUOTA_NODE_CORE_HH
#define EOS_NS_COMMON_QUOTA_NODE_CORE_HH
#include "namespace/Namespace.hh"
#include "namespace/interface/Identifiers.hh"
#include <map>
......@@ -36,6 +39,13 @@ public:
struct UsageInfo {
UsageInfo(): space(0), physicalSpace(0), files(0) {}
UsageInfo& operator += (const UsageInfo& other)
{
space += other.space;
physicalSpace += other.physicalSpace;
files += other.files;
return *this;
}
uint64_t space;
uint64_t physicalSpace;
uint64_t files;
......@@ -93,3 +103,5 @@ private:
};
EOSNSNAMESPACE_END
#endif
......@@ -25,6 +25,7 @@
#include "namespace/Namespace.hh"
#include "namespace/interface/IContainerMD.hh"
#include "namespace/interface/IFileMD.hh"
#include "namespace/common/QuotaNodeCore.hh"
#include <iostream>
#include <memory>
#include <map>
......@@ -43,22 +44,8 @@ class IQuotaNode
{
public:
struct UsageInfo {
UsageInfo(): space(0), physicalSpace(0), files(0) {}
UsageInfo& operator += (const UsageInfo& other)
{
space += other.space;
physicalSpace += other.physicalSpace;
files += other.files;
return *this;
}
uint64_t space;
uint64_t physicalSpace;
uint64_t files;
};
typedef std::map<uid_t, UsageInfo> UserMap;
typedef std::map<gid_t, UsageInfo> GroupMap;
typedef std::map<uid_t, QuotaNodeCore::UsageInfo> UserMap;
typedef std::map<gid_t, QuotaNodeCore::UsageInfo> GroupMap;
//----------------------------------------------------------------------------
//! Constructor
......
......@@ -33,8 +33,8 @@ namespace eos
void QuotaNode::addFile(const IFileMD* file)
{
uint64_t size = pQuotaStats->getPhysicalSize(file);
UsageInfo& user = pUserUsage[file->getCUid()];
UsageInfo& group = pGroupUsage[file->getCGid()];
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace += size;
group.physicalSpace += size;
user.space += file->getSize();
......@@ -49,8 +49,8 @@ void QuotaNode::addFile(const IFileMD* file)
void QuotaNode::removeFile(const IFileMD* file)
{
uint64_t size = pQuotaStats->getPhysicalSize(file);
UsageInfo& user = pUserUsage[file->getCUid()];
UsageInfo& group = pGroupUsage[file->getCGid()];
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace -= size;
group.physicalSpace -= size;
user.space -= file->getSize();
......
......@@ -215,8 +215,8 @@ static uint64_t mapSize(const eos::IFileMD* file)
//------------------------------------------------------------------------------
static void createFiles(const std::string& path,
std::shared_ptr<eos::IView> view,
std::map<uid_t, eos::QuotaNode::UsageInfo>& users,
std::map<gid_t, eos::QuotaNode::UsageInfo>& groups)
std::map<uid_t, eos::QuotaNodeCore::UsageInfo>& users,
std::map<gid_t, eos::QuotaNodeCore::UsageInfo>& groups)
{
eos::IQuotaNode* node = view->getQuotaNode(view->getContainer(path).get());
......@@ -231,8 +231,8 @@ static void createFiles(const std::string& path,
view->updateFileStore(file.get());
node->addFile(file.get());
uint64_t size = mapSize(file.get());
eos::IQuotaNode::UsageInfo& user = users[file->getCUid()];
eos::IQuotaNode::UsageInfo& group = groups[file->getCGid()];
eos::QuotaNodeCore::UsageInfo& user = users[file->getCUid()];
eos::QuotaNodeCore::UsageInfo& group = groups[file->getCGid()];
user.space += file->getSize();
user.physicalSpace += size;
user.files++;
......@@ -276,18 +276,18 @@ void HierarchicalViewTest::quotaTest()
//----------------------------------------------------------------------------
// Test quota node melding
//----------------------------------------------------------------------------
std::map<uid_t, eos::IQuotaNode::UsageInfo> users;
std::map<gid_t, eos::IQuotaNode::UsageInfo> groups;
std::map<uid_t, eos::IQuotaNode::UsageInfo>::iterator userIt;
std::map<gid_t, eos::IQuotaNode::UsageInfo>::iterator groupIt;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo> users;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo> groups;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo>::iterator userIt;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo>::iterator groupIt;
eos::IQuotaNode* meldNode1 = new eos::QuotaNode(0, 1);
eos::IQuotaNode* meldNode2 = new eos::QuotaNode(0, 2);
for (int i = 0; i < 10000; ++i) {
uid_t uid = random();
gid_t gid = random();
eos::IQuotaNode::UsageInfo& user = users[uid];
eos::IQuotaNode::UsageInfo& group = groups[gid];
eos::QuotaNodeCore::UsageInfo& user = users[uid];
eos::QuotaNodeCore::UsageInfo& group = groups[gid];
uint64_t userSpace = random() % 100000;
uint64_t userPhysicalSpace = random() % 100000;
uint64_t userFiles = random() % 1000;
......@@ -388,16 +388,16 @@ void HierarchicalViewTest::quotaTest()
//----------------------------------------------------------------------------
// Create some files
//----------------------------------------------------------------------------
std::map<uid_t, eos::IQuotaNode::UsageInfo> users1;
std::map<gid_t, eos::IQuotaNode::UsageInfo> groups1;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo> users1;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo> groups1;
std::string path1 = "/test/embed/embed1/";
createFiles(path1, view, users1, groups1);
std::map<uid_t, eos::IQuotaNode::UsageInfo> users2;
std::map<gid_t, eos::IQuotaNode::UsageInfo> groups2;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo> users2;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo> groups2;
std::string path2 = "/test/embed/embed2/";
createFiles(path2, view, users2, groups2);
std::map<uid_t, eos::IQuotaNode::UsageInfo> users3;
std::map<gid_t, eos::IQuotaNode::UsageInfo> groups3;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo> users3;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo> groups3;
std::string path3 = "/test/embed/embed3/";
createFiles(path3, view, users3, groups3);
//----------------------------------------------------------------------------
......
......@@ -73,8 +73,8 @@ QuotaNode::addFile(const IFileMD* file)
);
// Update the cached information
UsageInfo& user = pUserUsage[file->getCUid()];
UsageInfo& group = pGroupUsage[file->getCGid()];
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace += size;
group.physicalSpace += size;
user.space += file->getSize();
......@@ -107,8 +107,8 @@ QuotaNode::removeFile(const IFileMD* file)
);
// Update the cached information
UsageInfo& user = pUserUsage[file->getCUid()];
UsageInfo& group = pGroupUsage[file->getCGid()];
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace -= size;
group.physicalSpace -= size;
user.space -= file->getSize();
......@@ -187,11 +187,11 @@ void QuotaNode::updateFromBackend()
auto it_uid = pUserUsage.find(uid);
if (it_uid == pUserUsage.end()) {
auto pair = pUserUsage.emplace(uid, UsageInfo());
auto pair = pUserUsage.emplace(uid, QuotaNodeCore::UsageInfo());
it_uid = pair.first;
}
UsageInfo& uinfo = it_uid->second;
QuotaNodeCore::UsageInfo& uinfo = it_uid->second;
if (type == "logical_size") {
uinfo.space = std::stoull(elem.second);
......@@ -216,11 +216,11 @@ void QuotaNode::updateFromBackend()
auto it_gid = pGroupUsage.find(uid);
if (it_gid == pGroupUsage.end()) {
auto pair = pGroupUsage.emplace(uid, UsageInfo());
auto pair = pGroupUsage.emplace(uid, QuotaNodeCore::UsageInfo());
it_gid = pair.first;
}
UsageInfo& ginfo = it_gid->second;
QuotaNodeCore::UsageInfo& ginfo = it_gid->second;
if (type == "logical_size") {
ginfo.space = std::stoull(elem.second);
......
......@@ -184,8 +184,8 @@ mapSize(const eos::IFileMD* file)
//------------------------------------------------------------------------------
static void
createFiles(const std::string& path, eos::IView* view,
std::map<uid_t, eos::QuotaNode::UsageInfo>* users,
std::map<gid_t, eos::QuotaNode::UsageInfo>* groups)
std::map<uid_t, eos::QuotaNodeCore::UsageInfo>* users,
std::map<gid_t, eos::QuotaNodeCore::UsageInfo>* groups)
{
eos::IQuotaNode* node = view->getQuotaNode(view->getContainer(path).get());
......@@ -200,8 +200,8 @@ createFiles(const std::string& path, eos::IView* view,
view->updateFileStore(file.get());
node->addFile(file.get());
uint64_t size = mapSize(file.get());
eos::IQuotaNode::UsageInfo& user = (*users)[file->getCUid()];
eos::IQuotaNode::UsageInfo& group = (*groups)[file->getCGid()];
eos::QuotaNodeCore::UsageInfo& user = (*users)[file->getCUid()];
eos::QuotaNodeCore::UsageInfo& group = (*groups)[file->getCGid()];
user.space += file->getSize();
user.physicalSpace += size;
user.files++;
......@@ -296,16 +296,16 @@ TEST_F(HierarchicalViewF, QuotaTest)
ASSERT_TRUE(qn3 != qn5);
ASSERT_TRUE(qn3 != qn2);
// Create some files
std::map<uid_t, eos::IQuotaNode::UsageInfo> users1;
std::map<gid_t, eos::IQuotaNode::UsageInfo> groups1;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo> users1;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo> groups1;
std::string path1 = "/test/embed/embed1/";
createFiles(path1, view(), &users1, &groups1);
std::map<uid_t, eos::IQuotaNode::UsageInfo> users2;
std::map<gid_t, eos::IQuotaNode::UsageInfo> groups2;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo> users2;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo> groups2;
std::string path2 = "/test/embed/embed2/";
createFiles(path2, view(), &users2, &groups2);
std::map<uid_t, eos::IQuotaNode::UsageInfo> users3;
std::map<gid_t, eos::IQuotaNode::UsageInfo> groups3;
std::map<uid_t, eos::QuotaNodeCore::UsageInfo> users3;
std::map<gid_t, eos::QuotaNodeCore::UsageInfo> groups3;
std::string path3 = "/test/embed/embed3/";
createFiles(path3, view(), &users3, &groups3);
// Verify correctness
......
......@@ -541,9 +541,27 @@ TEST(QuotaNodeCore, BasicSanity) {
ASSERT_EQ(qn.getPhysicalSpaceByGroup(12), 2);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(13), 2048);
ASSERT_EQ(qn.getNumFilesByUser(12), 2u);
ASSERT_EQ(qn.getNumFilesByUser(13), 0u);
ASSERT_EQ(qn.getNumFilesByGroup(12), 1u);
ASSERT_EQ(qn.getNumFilesByGroup(13), 1u);
qn.removeFile(12, 13, 1024, 2048);
ASSERT_EQ(qn.getPhysicalSpaceByUser(12), 2);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(12), 2);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(13), 0);
qn.removeFile(12, 12, 1, 2);
ASSERT_EQ(qn.getPhysicalSpaceByUser(12), 0);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(12), 0);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(13), 0);
ASSERT_EQ(qn.getNumFilesByUser(12), 0u);
ASSERT_EQ(qn.getNumFilesByUser(13), 0u);
ASSERT_EQ(qn.getNumFilesByGroup(12), 0u);
ASSERT_EQ(qn.getNumFilesByGroup(13), 0u);
}
......@@ -810,8 +810,8 @@ ConvertQuotaView::addQuotaInfo(IFileMD* file)
QuotaNodeMapT& map_uid = it_map->second.first;
QuotaNodeMapT& map_gid = it_map->second.second;
eos::IQuotaNode::UsageInfo& user = map_uid[suid];
eos::IQuotaNode::UsageInfo& group = map_gid[sgid];
eos::QuotaNodeCore::UsageInfo& user = map_uid[suid];
eos::QuotaNodeCore::UsageInfo& group = map_gid[sgid];
user.physicalSpace += size;
group.physicalSpace += size;
user.space += file->getSize();
......@@ -844,7 +844,7 @@ ConvertQuotaView::commitToBackend()
qclient::QHash quota_map(*sQcl, uid_key);
for (auto& elem : uid_map) {
eos::IQuotaNode::UsageInfo& info = elem.second;
eos::QuotaNodeCore::UsageInfo& info = elem.second;
std::string field = elem.first + quota::sPhysicalSize;
quota_map.hset_async(field, info.physicalSpace, &ah);
field = elem.first + quota::sLogicalSize;
......@@ -856,7 +856,7 @@ ConvertQuotaView::commitToBackend()
quota_map.setKey(gid_key);
for (auto& elem : gid_map) {
eos::IQuotaNode::UsageInfo& info = elem.second;
eos::QuotaNodeCore::UsageInfo& info = elem.second;
std::string field = elem.first + quota::sPhysicalSize;
quota_map.hset_async(field, info.physicalSpace, &ah);
field = elem.first + quota::sLogicalSize;
......
......@@ -39,7 +39,7 @@
EOSNSNAMESPACE_BEGIN
using QuotaNodeMapT = std::map<std::string, eos::IQuotaNode::UsageInfo>;
using QuotaNodeMapT = std::map<std::string, eos::QuotaNodeCore::UsageInfo>;
//------------------------------------------------------------------------------
//! Class ConvertQuotaView
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment