|
@@ -45,25 +45,24 @@ bool CXRefFilesNode::IsChanged()
|
|
|
void CXRefFilesNode::Commit()
|
|
|
{
|
|
|
if (m_bChanged)
|
|
|
- Deserialize(getDataTree());
|
|
|
+ Deserialize(queryDataTree());
|
|
|
m_bChanged = false;
|
|
|
}
|
|
|
|
|
|
-StringBuffer& CXRefFilesNode::Serialize(StringBuffer& outStr)
|
|
|
+MemoryBuffer &CXRefFilesNode::queryData()
|
|
|
{
|
|
|
- if (!m_bChanged && _data.length() > 0)
|
|
|
- {
|
|
|
- outStr.append(_data);
|
|
|
- return outStr;
|
|
|
- }
|
|
|
- _data.clear();
|
|
|
- MemoryBuffer buff;
|
|
|
- m_baseTree.getPropBin("data",buff);
|
|
|
- if (buff.length())
|
|
|
+ if (m_bChanged || (0 == _data.length()))
|
|
|
{
|
|
|
- outStr.append(buff.length(),buff.toByteArray());
|
|
|
- _data.append(outStr);
|
|
|
+ _data.clear();
|
|
|
+ m_baseTree.getPropBin("data", _data);
|
|
|
}
|
|
|
+ return _data;
|
|
|
+}
|
|
|
+
|
|
|
+StringBuffer& CXRefFilesNode::Serialize(StringBuffer& outStr)
|
|
|
+{
|
|
|
+ MemoryBuffer &_data = queryData();
|
|
|
+ outStr.append(_data.length(), _data.toByteArray());
|
|
|
return outStr;
|
|
|
}
|
|
|
|
|
@@ -79,17 +78,22 @@ IPropertyTree* CXRefFilesNode::FindNode(const char* NodeName)
|
|
|
{
|
|
|
StringBuffer xpath;
|
|
|
xpath.clear().appendf("File/[Partmask=\"%s\"]", NodeName);
|
|
|
- StringBuffer tmpbuf;
|
|
|
- return getDataTree().getBranch(xpath.str());
|
|
|
+ return queryDataTree().getBranch(xpath.str());
|
|
|
}
|
|
|
|
|
|
-IPropertyTree& CXRefFilesNode::getDataTree()
|
|
|
+IPropertyTreeIterator *CXRefFilesNode::getMatchingFiles(const char *match, const char *type)
|
|
|
+{
|
|
|
+ StringBuffer xpath;
|
|
|
+ xpath.clear().appendf("File/[%s=\"%s\"]", type, match);
|
|
|
+ return queryDataTree().getElements(xpath.str());
|
|
|
+}
|
|
|
+
|
|
|
+IPropertyTree& CXRefFilesNode::queryDataTree()
|
|
|
{
|
|
|
if (m_DataTree.get() == 0)
|
|
|
{
|
|
|
- StringBuffer dataStr;
|
|
|
- Serialize(dataStr);
|
|
|
- m_DataTree.setown(createPTreeFromXMLString(dataStr.str()));
|
|
|
+ MemoryBuffer &data = queryData();
|
|
|
+ m_DataTree.setown(createPTreeFromXMLString(data.length(), data.toByteArray()));
|
|
|
}
|
|
|
return *m_DataTree.get();
|
|
|
}
|
|
@@ -97,7 +101,8 @@ IPropertyTree& CXRefFilesNode::getDataTree()
|
|
|
static bool checkPartsInCluster(const char *title,const char *clustername, IPropertyTree *subBranch, StringBuffer &errstr,bool exists)
|
|
|
{
|
|
|
Owned<IGroup> group = queryNamedGroupStore().lookup(clustername);
|
|
|
- if (!group) {
|
|
|
+ if (!group)
|
|
|
+ {
|
|
|
ERRLOG("%s cluster not found",clustername);
|
|
|
errstr.appendf("ERROR: %s cluster not found",clustername);
|
|
|
return false;
|
|
@@ -106,12 +111,15 @@ static bool checkPartsInCluster(const char *title,const char *clustername, IProp
|
|
|
unsigned i;
|
|
|
StringBuffer xpath;
|
|
|
unsigned n = group->ordinality();
|
|
|
- ForEach(*partItr) {
|
|
|
+ ForEach(*partItr)
|
|
|
+ {
|
|
|
IPropertyTree& part = partItr->query();
|
|
|
unsigned pn = part.getPropInt("Num");
|
|
|
- for (int rep=0;rep<2;rep++) {
|
|
|
+ for (int rep=0;rep<2;rep++)
|
|
|
+ {
|
|
|
i = 0;
|
|
|
- for (;;) {
|
|
|
+ for (;;)
|
|
|
+ {
|
|
|
i++;
|
|
|
xpath.clear().appendf(rep?"RNode[%d]":"Node[%d]",i);
|
|
|
if (!part.hasProp(xpath.str()))
|
|
@@ -119,14 +127,17 @@ static bool checkPartsInCluster(const char *title,const char *clustername, IProp
|
|
|
SocketEndpoint ep(part.queryProp(xpath.str()));
|
|
|
ep.port = 0;
|
|
|
rank_t gn = group->rank(ep);
|
|
|
- if (group->rank(ep)==RANK_NULL) {
|
|
|
+ if (group->rank(ep)==RANK_NULL)
|
|
|
+ {
|
|
|
StringBuffer eps;
|
|
|
ERRLOG("%s %s Part %d on %s is not in cluster %s",title,rep?"Replicate":"Primary",pn,ep.getUrlStr(eps).str(),clustername);
|
|
|
errstr.appendf("ERROR: %s %s part %d on %s is not in cluster %s",title,rep?"Replicate":"Primary",pn,ep.getUrlStr(eps).str(),clustername);
|
|
|
return false;
|
|
|
}
|
|
|
- if (exists) {
|
|
|
- if ((pn-1+rep)%n==gn) {
|
|
|
+ if (exists)
|
|
|
+ {
|
|
|
+ if ((pn-1+rep)%n==gn)
|
|
|
+ {
|
|
|
ERRLOG("Logical file for %s exists (part not orphaned?)",title);
|
|
|
errstr.appendf("Logical file for %s exists (part not orphaned?)",title);
|
|
|
return false;
|
|
@@ -145,7 +156,8 @@ bool CXRefFilesNode::RemovePhysical(const char *Partmask,IUserDescriptor* udesc,
|
|
|
{
|
|
|
size32_t startlen = errstr.length();
|
|
|
IPropertyTree* subBranch = FindNode(Partmask);
|
|
|
- if (!subBranch) {
|
|
|
+ if (!subBranch)
|
|
|
+ {
|
|
|
ERRLOG("%s branch not found",Partmask);
|
|
|
errstr.appendf("ERROR: %s branch not found",Partmask);
|
|
|
return false;
|
|
@@ -153,7 +165,8 @@ bool CXRefFilesNode::RemovePhysical(const char *Partmask,IUserDescriptor* udesc,
|
|
|
// sanity check file doesn't (now) exist
|
|
|
bool exists = false;
|
|
|
StringBuffer lfn;
|
|
|
- if (LogicalNameFromMask(Partmask,lfn)) {
|
|
|
+ if (LogicalNameFromMask(Partmask,lfn))
|
|
|
+ {
|
|
|
if (queryDistributedFileDirectory().exists(lfn.str(),udesc,true))
|
|
|
exists = true;
|
|
|
}
|
|
@@ -172,7 +185,8 @@ bool CXRefFilesNode::RemovePhysical(const char *Partmask,IUserDescriptor* udesc,
|
|
|
/////////////////////////////////
|
|
|
StringBuffer xpath;
|
|
|
unsigned i = 0;
|
|
|
- for (;;) {
|
|
|
+ for (;;)
|
|
|
+ {
|
|
|
i++;
|
|
|
xpath.clear().appendf("Node[%d]",i);
|
|
|
if (!part.hasProp(xpath.str()))
|
|
@@ -183,7 +197,8 @@ bool CXRefFilesNode::RemovePhysical(const char *Partmask,IUserDescriptor* udesc,
|
|
|
files.append(rmtFile);
|
|
|
}
|
|
|
i = 0;
|
|
|
- for (;;) {
|
|
|
+ for (;;)
|
|
|
+ {
|
|
|
i++;
|
|
|
xpath.clear().appendf("RNode[%d]",i);
|
|
|
if (!part.hasProp(xpath.str()))
|
|
@@ -197,7 +212,6 @@ bool CXRefFilesNode::RemovePhysical(const char *Partmask,IUserDescriptor* udesc,
|
|
|
rmtFile.setPath(ip,remoteFile.str());
|
|
|
files.append(rmtFile);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
CriticalSection crit;
|
|
@@ -217,8 +231,10 @@ bool CXRefFilesNode::RemovePhysical(const char *Partmask,IUserDescriptor* udesc,
|
|
|
try{
|
|
|
Owned<IFile> _remoteFile = createIFile(files.item(idx));
|
|
|
DBGLOG("Removing physical part at %s",_remoteFile->queryFilename());
|
|
|
- if (_remoteFile->exists()) {
|
|
|
- if (!_remoteFile->remove()) {
|
|
|
+ if (_remoteFile->exists())
|
|
|
+ {
|
|
|
+ if (!_remoteFile->remove())
|
|
|
+ {
|
|
|
StringBuffer errname;
|
|
|
files.item(idx).getRemotePath(errname);
|
|
|
ERRLOG("Could not delete file %s",errname.str());
|
|
@@ -272,20 +288,23 @@ bool CXRefFilesNode::RemoveLogical(const char* LogicalName,IUserDescriptor* udes
|
|
|
StringBuffer tmpbuf;
|
|
|
|
|
|
|
|
|
- IPropertyTree* pLogicalFileNode = getDataTree().getBranch(xpath.str());
|
|
|
- if (!pLogicalFileNode) {
|
|
|
+ IPropertyTree* pLogicalFileNode = queryDataTree().getBranch(xpath.str());
|
|
|
+ if (!pLogicalFileNode)
|
|
|
+ {
|
|
|
ERRLOG("Branch %s not found",xpath.str());
|
|
|
errstr.appendf("Branch %s not found",xpath.str());
|
|
|
return false;
|
|
|
}
|
|
|
if (!checkPartsInCluster(LogicalName,clustername,pLogicalFileNode,errstr,false))
|
|
|
return false;
|
|
|
- if (queryDistributedFileDirectory().existsPhysical(LogicalName,udesc)) {
|
|
|
+ if (queryDistributedFileDirectory().existsPhysical(LogicalName,udesc))
|
|
|
+ {
|
|
|
ERRLOG("Logical file %s all parts exist (not lost?))",LogicalName);
|
|
|
errstr.appendf("Logical file %s all parts exist (not lost?))",LogicalName);
|
|
|
return false;
|
|
|
}
|
|
|
- if (!getDataTree().removeTree(pLogicalFileNode)) {
|
|
|
+ if (!queryDataTree().removeTree(pLogicalFileNode))
|
|
|
+ {
|
|
|
ERRLOG("Removing XRef Branch %s", xpath.str());
|
|
|
errstr.appendf("Removing XRef Branch %s", xpath.str());
|
|
|
return false;
|
|
@@ -298,7 +317,8 @@ bool CXRefFilesNode::RemoveLogical(const char* LogicalName,IUserDescriptor* udes
|
|
|
bool CXRefFilesNode::AttachPhysical(const char *Partmask,IUserDescriptor* udesc, const char *clustername, StringBuffer &errstr)
|
|
|
{
|
|
|
IPropertyTree* subBranch = FindNode(Partmask);
|
|
|
- if (!subBranch) {
|
|
|
+ if (!subBranch)
|
|
|
+ {
|
|
|
ERRLOG("%s node not found",Partmask);
|
|
|
errstr.appendf("ERROR: %s node not found",Partmask);
|
|
|
return false;
|
|
@@ -307,7 +327,8 @@ bool CXRefFilesNode::AttachPhysical(const char *Partmask,IUserDescriptor* udesc,
|
|
|
return false;
|
|
|
|
|
|
StringBuffer logicalName;
|
|
|
- if (!LogicalNameFromMask(Partmask,logicalName)) {
|
|
|
+ if (!LogicalNameFromMask(Partmask,logicalName))
|
|
|
+ {
|
|
|
ERRLOG("%s - could not attach",Partmask);
|
|
|
errstr.appendf("ERROR: %s - could not attach",Partmask);
|
|
|
return false;
|
|
@@ -441,7 +462,7 @@ bool CXRefFilesNode::RemoveTreeNode(const char* NodeName)
|
|
|
if (!subBranch)
|
|
|
return false;
|
|
|
StringBuffer tmpbuf;
|
|
|
- return getDataTree().removeTree(subBranch);
|
|
|
+ return queryDataTree().removeTree(subBranch);
|
|
|
}
|
|
|
|
|
|
bool CXRefFilesNode::RemoveRemoteFile(const char* fileName, const char* ipAddress)
|
|
@@ -484,5 +505,5 @@ void CXRefOrphanFilesNode::CleanTree(IPropertyTree& inTree)
|
|
|
Itr->next();
|
|
|
}
|
|
|
if(partcount != 0)
|
|
|
- inTree.setPropInt("Partsfound",partcount);
|
|
|
+ inTree.setPropInt("Partsfound",partcount);
|
|
|
}
|