Commit 12caba28 authored by Georgios Bitzes's avatar Georgios Bitzes

NS: Implement QuotaNode in terms of QuotaNodeCore

parent 2470a89d
Pipeline #471081 passed with stages
in 66 minutes 13 seconds
......@@ -21,19 +21,6 @@
EOSNSNAMESPACE_BEGIN
//------------------------------------------------------------------------------
// Get the amount of space occupied by the given user
//------------------------------------------------------------------------------
uint64_t QuotaNodeCore::getUsedSpaceByUser(uid_t uid) {
auto it = mUserInfo.find(uid);
if(it == mUserInfo.end()) {
return 0;
}
return it->second.space;
}
//------------------------------------------------------------------------------
//! Get the amount of space occupied by the given group
//------------------------------------------------------------------------------
uint64_t QuotaNodeCore::getUsedSpaceByGroup(gid_t gid) {
......@@ -145,38 +132,6 @@ void QuotaNodeCore::removeFile(uid_t uid, gid_t gid, uint64_t size,
}
//------------------------------------------------------------------------------
// Get the set of uids for which information is stored in the current quota
// node.
//
// @return set of uids
//------------------------------------------------------------------------------
std::unordered_set<uint64_t> QuotaNodeCore::getUids() {
std::unordered_set<uint64_t> uids;
for (auto it = mUserInfo.begin(); it != mUserInfo.end(); ++it) {
uids.insert(it->first);
}
return uids;
}
//------------------------------------------------------------------------------
// Get the set of gids for which information is stored in the current quota
// node.
//
// @return set of gids
//------------------------------------------------------------------------------
std::unordered_set<uint64_t> QuotaNodeCore::getGids() {
std::unordered_set<uint64_t> gids;
for (auto it = mGroupInfo.begin(); it != mGroupInfo.end(); ++it) {
gids.insert(it->first);
}
return gids;
}
//------------------------------------------------------------------------------
// Meld in another quota node core
//------------------------------------------------------------------------------
void QuotaNodeCore::meld(const QuotaNodeCore& other) {
......
......@@ -31,6 +31,9 @@
EOSNSNAMESPACE_BEGIN
class IQuotaNode;
class QuotaNode;
//------------------------------------------------------------------------------
//! QuotaNode core logic, which keeps track of user/group volume/inode use for
//! a single quotanode.
......@@ -68,7 +71,15 @@ public:
//----------------------------------------------------------------------------
//! Get the amount of space occupied by the given user
//----------------------------------------------------------------------------
uint64_t getUsedSpaceByUser(uid_t uid);
uint64_t getUsedSpaceByUser(uid_t uid) {
auto it = mUserInfo.find(uid);
if(it == mUserInfo.end()) {
return 0;
}
return it->second.space;
}
//----------------------------------------------------------------------------
//! Get the amount of space occupied by the given group
......@@ -116,7 +127,15 @@ public:
//!
//! @return set of uids
//----------------------------------------------------------------------------
std::unordered_set<uint64_t> getUids();
std::unordered_set<uint64_t> getUids() {
std::unordered_set<uint64_t> uids;
for (auto it = mUserInfo.begin(); it != mUserInfo.end(); ++it) {
uids.insert(it->first);
}
return uids;
}
//----------------------------------------------------------------------------
//! Get the set of gids for which information is stored in the current quota
......@@ -124,9 +143,20 @@ public:
//!
//! @return set of gids
//----------------------------------------------------------------------------
std::unordered_set<uint64_t> getGids();
std::unordered_set<uint64_t> getGids() {
std::unordered_set<uint64_t> gids;
for (auto it = mGroupInfo.begin(); it != mGroupInfo.end(); ++it) {
gids.insert(it->first);
}
return gids;
}
private:
friend class IQuotaNode;
friend class QuotaNode;
std::map<uid_t, UsageInfo> mUserInfo;
std::map<gid_t, UsageInfo> mGroupInfo;
};
......
......@@ -71,7 +71,7 @@ public:
//----------------------------------------------------------------------------
virtual uint64_t getUsedSpaceByUser(uid_t uid)
{
return pUserUsage[uid].space;
return pCore.getUsedSpaceByUser(uid);
}
//----------------------------------------------------------------------------
......@@ -79,7 +79,7 @@ public:
//----------------------------------------------------------------------------
virtual uint64_t getUsedSpaceByGroup(gid_t gid)
{
return pGroupUsage[gid].space;
return pCore.getUsedSpaceByGroup(gid);
}
//----------------------------------------------------------------------------
......@@ -87,7 +87,7 @@ public:
//----------------------------------------------------------------------------
virtual uint64_t getPhysicalSpaceByUser(uid_t uid)
{
return pUserUsage[uid].physicalSpace;
return pCore.getPhysicalSpaceByUser(uid);
}
//----------------------------------------------------------------------------
......@@ -95,7 +95,7 @@ public:
//----------------------------------------------------------------------------
virtual uint64_t getPhysicalSpaceByGroup(gid_t gid)
{
return pGroupUsage[gid].physicalSpace;
return pCore.getPhysicalSpaceByGroup(gid);
}
//----------------------------------------------------------------------------
......@@ -103,7 +103,7 @@ public:
//----------------------------------------------------------------------------
virtual uint64_t getNumFilesByUser(uid_t uid)
{
return pUserUsage[uid].files;
return pCore.getNumFilesByUser(uid);
}
//----------------------------------------------------------------------------
......@@ -111,7 +111,7 @@ public:
//----------------------------------------------------------------------------
virtual uint64_t getNumFilesByGroup(gid_t gid)
{
return pGroupUsage[gid].files;
return pCore.getNumFilesByGroup(gid);
}
//----------------------------------------------------------------------------
......@@ -137,13 +137,7 @@ public:
//----------------------------------------------------------------------------
virtual std::unordered_set<uint64_t> getUids()
{
std::unordered_set<uint64_t> uids;
for (auto it = pUserUsage.begin(); it != pUserUsage.end(); ++it) {
uids.insert(it->first);
}
return uids;
return pCore.getUids();
}
//----------------------------------------------------------------------------
......@@ -154,20 +148,20 @@ public:
//----------------------------------------------------------------------------
virtual std::unordered_set<uint64_t> getGids()
{
std::unordered_set<uint64_t> gids;
for (auto it = pGroupUsage.begin(); it != pGroupUsage.end(); ++it) {
gids.insert(it->first);
}
return pCore.getGids();
}
return gids;
//----------------------------------------------------------------------------
//! Get underlying QuotaNodeCore object.
//----------------------------------------------------------------------------
const QuotaNodeCore& getCore() const {
return pCore;
}
protected:
IQuotaStats* pQuotaStats;
IContainerMD::id_t pContainerId; ///< Id of the corresponding container
UserMap pUserUsage;
GroupMap pGroupUsage;
QuotaNodeCore pCore;
};
//----------------------------------------------------------------------------
......
......@@ -32,15 +32,12 @@ namespace eos
//----------------------------------------------------------------------------
void QuotaNode::addFile(const IFileMD* file)
{
uint64_t size = pQuotaStats->getPhysicalSize(file);
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace += size;
group.physicalSpace += size;
user.space += file->getSize();
group.space += file->getSize();
user.files++;
group.files++;
pCore.addFile(
file->getCUid(),
file->getCGid(),
file->getSize(),
pQuotaStats->getPhysicalSize(file)
);
}
//----------------------------------------------------------------------------
......@@ -48,15 +45,12 @@ void QuotaNode::addFile(const IFileMD* file)
//----------------------------------------------------------------------------
void QuotaNode::removeFile(const IFileMD* file)
{
uint64_t size = pQuotaStats->getPhysicalSize(file);
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace -= size;
group.physicalSpace -= size;
user.space -= file->getSize();
group.space -= file->getSize();
user.files--;
group.files--;
pCore.removeFile(
file->getCUid(),
file->getCGid(),
file->getSize(),
pQuotaStats->getPhysicalSize(file)
);
}
//----------------------------------------------------------------------------
......@@ -64,17 +58,7 @@ void QuotaNode::removeFile(const IFileMD* file)
//----------------------------------------------------------------------------
void QuotaNode::meld(const IQuotaNode* node)
{
const QuotaNode* qnode = static_cast<const QuotaNode*>(node);
for (auto it1 = qnode->pUserUsage.begin(); it1 != qnode->pUserUsage.end();
++it1) {
pUserUsage[it1->first] += it1->second;
}
for (auto it2 = qnode->pGroupUsage.begin(); it2 != qnode->pGroupUsage.end();
++it2) {
pGroupUsage[it2->first] += it2->second;
}
pCore.meld(node->getCore());
}
//----------------------------------------------------------------------------
......
......@@ -50,7 +50,7 @@ public:
//----------------------------------------------------------------------------
void changeSpaceUser(uid_t uid, int64_t delta)
{
pUserUsage[uid].space += delta;
pCore.mUserInfo[uid].space += delta;
}
//----------------------------------------------------------------------------
......@@ -58,7 +58,7 @@ public:
//----------------------------------------------------------------------------
void changeSpaceGroup(gid_t gid, int64_t delta)
{
pGroupUsage[gid].space += delta;
pCore.mGroupInfo[gid].space += delta;
}
//----------------------------------------------------------------------------
......@@ -66,7 +66,7 @@ public:
//----------------------------------------------------------------------------
void changePhysicalSpaceUser(uid_t uid, int64_t delta)
{
pUserUsage[uid].physicalSpace += delta;
pCore.mUserInfo[uid].physicalSpace += delta;
}
//----------------------------------------------------------------------------
......@@ -74,7 +74,7 @@ public:
//----------------------------------------------------------------------------
void changePhysicalSpaceGroup(gid_t gid, int64_t delta)
{
pGroupUsage[gid].physicalSpace += delta;
pCore.mGroupInfo[gid].physicalSpace += delta;
}
//----------------------------------------------------------------------------
......@@ -82,7 +82,7 @@ public:
//----------------------------------------------------------------------------
uint64_t changeNumFilesUser(uid_t uid, uint64_t delta)
{
return pUserUsage[uid].files += delta;
return pCore.mUserInfo[uid].files += delta;
}
//----------------------------------------------------------------------------
......@@ -90,7 +90,7 @@ public:
//----------------------------------------------------------------------------
uint64_t changeNumFilesGroup(gid_t gid, uint64_t delta)
{
return pGroupUsage[gid].files += delta;
return pCore.mGroupInfo[gid].files += delta;
}
//----------------------------------------------------------------------------
......
......@@ -73,14 +73,12 @@ QuotaNode::addFile(const IFileMD* file)
);
// Update the cached information
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace += size;
group.physicalSpace += size;
user.space += file->getSize();
group.space += file->getSize();
++user.files;
++group.files;
pCore.addFile(
file->getCUid(),
file->getCGid(),
file->getSize(),
size
);
}
//------------------------------------------------------------------------------
......@@ -107,14 +105,12 @@ QuotaNode::removeFile(const IFileMD* file)
);
// Update the cached information
QuotaNodeCore::UsageInfo& user = pUserUsage[file->getCUid()];
QuotaNodeCore::UsageInfo& group = pGroupUsage[file->getCGid()];
user.physicalSpace -= size;
group.physicalSpace -= size;
user.space -= file->getSize();
group.space -= file->getSize();
--user.files;
--group.files;
pCore.removeFile(
file->getCUid(),
file->getCGid(),
file->getSize(),
size
);
}
//------------------------------------------------------------------------------
......@@ -154,15 +150,7 @@ QuotaNode::meld(const IQuotaNode* node)
} while (cursor != "0");
// Update the cached information
for (auto it1 = impl_node->pUserUsage.begin();
it1 != impl_node->pUserUsage.end(); ++it1) {
pUserUsage[it1->first] += it1->second;
}
for (auto it2 = impl_node->pGroupUsage.begin();
it2 != impl_node->pGroupUsage.end(); ++it2) {
pGroupUsage[it2->first] += it2->second;
}
pCore.meld(node->getCore());
}
//------------------------------------------------------------------------------
......@@ -184,10 +172,10 @@ void QuotaNode::updateFromBackend()
size_t pos = elem.first.find(':');
uint64_t uid = std::stoull(elem.first.substr(0, pos));
std::string type = elem.first.substr(pos + 1);
auto it_uid = pUserUsage.find(uid);
auto it_uid = pCore.mUserInfo.find(uid);
if (it_uid == pUserUsage.end()) {
auto pair = pUserUsage.emplace(uid, QuotaNodeCore::UsageInfo());
if (it_uid == pCore.mUserInfo.end()) {
auto pair = pCore.mUserInfo.emplace(uid, QuotaNodeCore::UsageInfo());
it_uid = pair.first;
}
......@@ -213,10 +201,10 @@ void QuotaNode::updateFromBackend()
size_t pos = elem.first.find(':');
uint64_t uid = std::stoull(elem.first.substr(0, pos));
std::string type = elem.first.substr(pos + 1);
auto it_gid = pGroupUsage.find(uid);
auto it_gid = pCore.mGroupInfo.find(uid);
if (it_gid == pGroupUsage.end()) {
auto pair = pGroupUsage.emplace(uid, QuotaNodeCore::UsageInfo());
if (it_gid == pCore.mGroupInfo.end()) {
auto pair = pCore.mGroupInfo.emplace(uid, QuotaNodeCore::UsageInfo());
it_gid = pair.first;
}
......
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