Commit dede68b4 authored by Georgios Bitzes's avatar Georgios Bitzes

NS: Allow replacing the core of a quotanode

parent 81ffb926
......@@ -158,6 +158,11 @@ public:
return pCore;
}
//----------------------------------------------------------------------------
//! Replace underlying QuotaNodeCore obejct.
//----------------------------------------------------------------------------
virtual void replaceCore(const QuotaNodeCore &updated) = 0;
protected:
IQuotaStats* pQuotaStats;
IContainerMD::id_t pContainerId; ///< Id of the corresponding container
......
......@@ -27,9 +27,9 @@
namespace eos
{
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Account a new file, adjust the size using the size mapping function
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
void QuotaNode::addFile(const IFileMD* file)
{
pCore.addFile(
......@@ -40,9 +40,9 @@ void QuotaNode::addFile(const IFileMD* file)
);
}
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Remove a file, adjust the size using the size mapping function
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
void QuotaNode::removeFile(const IFileMD* file)
{
pCore.removeFile(
......@@ -61,9 +61,17 @@ void QuotaNode::meld(const IQuotaNode* node)
pCore.meld(node->getCore());
}
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Replace underlying QuotaNodeCore object.
//------------------------------------------------------------------------------
void QuotaNode::replaceCore(const QuotaNodeCore &updated)
{
pCore = updated;
}
//------------------------------------------------------------------------------
// Get a quota node associated to the container id
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
IQuotaNode* QuotaStats::getQuotaNode(IContainerMD::id_t nodeId)
{
NodeMap::iterator it = pNodeMap.find(nodeId);
......@@ -75,9 +83,9 @@ IQuotaNode* QuotaStats::getQuotaNode(IContainerMD::id_t nodeId)
return it->second;
}
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
QuotaStats::~QuotaStats()
{
for (auto it = pNodeMap.begin(); it != pNodeMap.end(); ++it) {
......@@ -101,9 +109,9 @@ QuotaStats::getAllIds()
return set_ids;
}
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Register a new quota node
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
IQuotaNode* QuotaStats::registerNewNode(IContainerMD::id_t nodeId)
{
NodeMap::iterator it = pNodeMap.find(nodeId);
......@@ -119,9 +127,9 @@ IQuotaNode* QuotaStats::registerNewNode(IContainerMD::id_t nodeId)
return node;
}
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Remove quota node
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
void QuotaStats::removeNode(IContainerMD::id_t nodeId)
{
NodeMap::iterator it = pNodeMap.find(nodeId);
......
......@@ -107,11 +107,16 @@ public:
//! Meld in another quota node
//----------------------------------------------------------------------------
void meld(const IQuotaNode* node) override;
//----------------------------------------------------------------------------
//! Replace underlying QuotaNodeCore object.
//----------------------------------------------------------------------------
void replaceCore(const QuotaNodeCore &updated) override;
};
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
//! Manager of the quota nodes
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
class QuotaStats: public IQuotaStats
{
public:
......
......@@ -222,6 +222,54 @@ void QuotaNode::updateFromBackend()
}
//------------------------------------------------------------------------------
// Replace underlying QuotaNodeCore object.
//------------------------------------------------------------------------------
void QuotaNode::replaceCore(const QuotaNodeCore &updated) {
pCore = updated;
pFlusher->exec("DEL", pQuotaUidKey);
pFlusher->exec("DEL", pQuotaGidKey);
for(auto it = pCore.mUserInfo.begin(); it != pCore.mUserInfo.end(); it++) {
std::string suid = std::to_string(it->first);
pFlusher->exec("HSET", pQuotaUidKey,
suid + quota::sPhysicalSize,
std::to_string(it->second.physicalSpace)
);
pFlusher->exec("HSET", pQuotaUidKey,
suid + quota::sLogicalSize,
std::to_string(it->second.space)
);
pFlusher->exec("HSET", pQuotaUidKey,
suid + quota::sNumFiles,
std::to_string(it->second.files)
);
}
for(auto it = pCore.mGroupInfo.begin(); it != pCore.mGroupInfo.end(); it++) {
std::string sgid = std::to_string(it->first);
pFlusher->exec("HSET", pQuotaGidKey,
sgid + quota::sPhysicalSize,
std::to_string(it->second.physicalSpace)
);
pFlusher->exec("HSET", pQuotaGidKey,
sgid + quota::sLogicalSize,
std::to_string(it->second.space)
);
pFlusher->exec("HSET", pQuotaGidKey,
sgid + quota::sNumFiles,
std::to_string(it->second.files)
);
}
}
//------------------------------------------------------------------------------
// *** Class QuotaStats implementaion ***
//------------------------------------------------------------------------------
......
......@@ -94,6 +94,11 @@ public:
//----------------------------------------------------------------------------
void updateFromBackend();
//----------------------------------------------------------------------------
//! Replace underlying QuotaNodeCore object.
//----------------------------------------------------------------------------
void replaceCore(const QuotaNodeCore &updated) override;
private:
//! Quota quota node uid hash key e.g. quota_node:id:uid
std::string pQuotaUidKey;
......
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