Skip to content

Commit

Permalink
Merge pull request #13202 from jakesmith/hpcc-23191-remove-protect-count
Browse files Browse the repository at this point in the history
HPCC-23191 Remove @count from logical file Protect status

Reviewed-By: Kevin Wang <kevin.wang@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
  • Loading branch information
richardkchapman committed Dec 9, 2019
2 parents b92cd77 + 95864de commit 9685f9c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 117 deletions.
131 changes: 33 additions & 98 deletions dali/base/dadfs.cpp
Expand Up @@ -1129,8 +1129,6 @@ protected: friend class CDistributedFile;
IFileDescriptor *createDescriptorFromMetaFile(const CDfsLogicalFileName &logicalname,IUserDescriptor *user);

bool isProtectedFile(const CDfsLogicalFileName &logicalname, unsigned timeout) ;
unsigned queryProtectedCount(const CDfsLogicalFileName &logicalname, const char *owner);
bool getProtectedInfo(const CDfsLogicalFileName &logicalname, StringArray &names, UnsignedArray &counts);
IDFProtectedIterator *lookupProtectedFiles(const char *owner=NULL,bool notsuper=false,bool superonly=false);
IDFAttributesIterator* getLogicalFilesSorted(IUserDescriptor* udesc, DFUQResultField *sortOrder, const void *filterBuf, DFUQResultField *specialFilters,
const void *specialFilterBuf, unsigned startOffset, unsigned maxNum, __int64 *cacheHint, unsigned *total, bool *allMatchingFilesReceived);
Expand Down Expand Up @@ -2035,14 +2033,9 @@ class CDFAttributeIterator: implements IDFAttributesIterator, public CInterface
ForEach(*piter) {
const char *name = piter->get().queryProp("@name");
if (name&&*name) {
unsigned count = piter->get().getPropInt("@count");
if (count) {
if (plist.length())
plist.append(',');
plist.append(name);
if (count>1)
plist.append(':').append(count);
}
if (plist.length())
plist.append(',');
plist.append(name);
}
}
if (plist.length()) {
Expand Down Expand Up @@ -2152,7 +2145,6 @@ class CDFProtectedIterator: implements IDFProtectedIterator, public CInterface
{
StringAttr owner;
StringAttr fn;
unsigned count;
bool issuper;
Owned<IRemoteConnection> conn;
Owned<IPropertyTreeIterator> fiter;
Expand All @@ -2168,7 +2160,6 @@ class CDFProtectedIterator: implements IDFProtectedIterator, public CInterface
fn.set(t.queryProp("OrigName"));
IPropertyTree &pt = piter->query();
owner.set(pt.queryProp("@name"));
count = pt.getPropInt("@count");
}

void clear()
Expand All @@ -2185,7 +2176,6 @@ class CDFProtectedIterator: implements IDFProtectedIterator, public CInterface
CDFProtectedIterator(const char *_owner,bool _notsuper,bool _superonly,unsigned _defaultTimeout)
: owner(_owner)
{
count = 0;
issuper = false;
notsuper=_notsuper;
superonly=_superonly;
Expand Down Expand Up @@ -2282,11 +2272,6 @@ class CDFProtectedIterator: implements IDFProtectedIterator, public CInterface
return owner;
}

unsigned getCount()
{
return count;
}

bool isSuper()
{
return issuper;
Expand Down Expand Up @@ -2619,38 +2604,33 @@ static bool setFileProtectTree(IPropertyTree &p,const char *owner, bool protect)
bool ret = false;
CDateTime dt;
dt.setNow();
if (owner&&*owner) {
Owned<IPropertyTree> t = getNamedPropTree(&p,"Protect","@name",owner,false);
if (t) {
unsigned c = t->getPropInt("@count");
if (owner&&*owner)
{
Owned<IPropertyTree> t = getNamedPropTree(&p, "Protect", "@name", owner, false);
if (t)
{
if (protect)
c++;
else {
if (c>=1) {
p.removeTree(t);
c = 0;
}
else
c--;
}
if (c) {
t->setPropInt("@count",c);
{
StringBuffer str;
t->setProp("@modified",dt.getString(str).str());
t->setProp("@modified", dt.getString(str).str());
}
else
p.removeTree(t);
}
else if (protect) {
t.setown(addNamedPropTree(&p,"Protect","@name",owner));
t->setPropInt("@count",1);
else if (protect)
{
t.setown(addNamedPropTree(&p, "Protect", "@name", owner));
StringBuffer str;
t->setProp("@modified",dt.getString(str).str());
}
ret = true;
}
else if (!protect) {
else if (!protect)
{
unsigned n=0;
IPropertyTree *pt;
while ((pt=p.queryPropTree("Protect[1]"))!=NULL) {
while ((pt=p.queryPropTree("Protect[1]"))!=NULL)
{
p.removeTree(pt);
n++;
}
Expand All @@ -2664,18 +2644,18 @@ static bool checkProtectAttr(const char *logicalname,IPropertyTree *froot,String
{
Owned<IPropertyTreeIterator> wpiter = froot->getElements("Attr/Protect");
bool prot = false;
ForEach(*wpiter) {
ForEach(*wpiter)
{
IPropertyTree &t = wpiter->query();
if (t.getPropInt("@count")) {
const char *wpname = t.queryProp("@name");
if (!wpname||!*wpname)
wpname = "<Unknown>";
if (prot)
reason.appendf(", %s",wpname);
else {
reason.appendf("file %s protected by %s",logicalname,wpname);
prot = true;
}
const char *wpname = t.queryProp("@name");
if (!wpname||!*wpname)
wpname = "<Unknown>";
if (prot)
reason.appendf(", %s", wpname);
else
{
reason.appendf("file %s protected by %s", logicalname, wpname);
prot = true;
}
}
return prot;
Expand Down Expand Up @@ -5199,7 +5179,7 @@ class CDistributedSuperFile: public CDistributedFileBase<IDistributedSuperFile>
if (pos==0)
{
Owned<IPropertyTree> superAttrs = createPTreeFromIPT(&file->queryAttributes());
superAttrs->removeProp("Protect"); // do not automatically inherit protected status
while (superAttrs->removeProp("Protect")); // do not automatically inherit protected status
resetFileAttr(superAttrs.getClear());
}
root->addPropTree("SubFile",sub);
Expand Down Expand Up @@ -5229,7 +5209,7 @@ class CDistributedSuperFile: public CDistributedFileBase<IDistributedSuperFile>
if (subfiles.ordinality())
{
Owned<IPropertyTree> superAttrs = createPTreeFromIPT(&subfiles.item(0).queryAttributes());
superAttrs->removeProp("Protect"); // do not automatically inherit protected status
while (superAttrs->removeProp("Protect")); // do not automatically inherit protected status
resetFileAttr(superAttrs.getClear());
}
else
Expand Down Expand Up @@ -12457,52 +12437,7 @@ bool CDistributedFileDirectory::isProtectedFile(const CDfsLogicalFileName &logic
CFileAttrLock attrLock;
if (!attrLock.init(logicalName, RTM_LOCK_READ, NULL, timeout?timeout:INFINITE, "CDistributedFileDirectory::isProtectedFile"))
return false; // timeout will raise exception
Owned<IPropertyTreeIterator> wpiter = attrLock.queryRoot()->getElements("Protect");
bool prot = false;
ForEach(*wpiter) {
IPropertyTree &t = wpiter->query();
if (t.getPropInt("@count")) {
prot = true;
break;
}
}
// timeout retry TBD
return prot;
}

unsigned CDistributedFileDirectory::queryProtectedCount(const CDfsLogicalFileName &logicalName, const char *owner)
{
CFileAttrLock attrLock;
if (!attrLock.init(logicalName, RTM_LOCK_READ, NULL, defaultTimeout, "CDistributedFileDirectory::queryProtectedCount"))
return 0; // timeout will raise exception
Owned<IPropertyTreeIterator> wpiter = attrLock.queryRoot()->getElements("Protect");
unsigned count = 0;
ForEach(*wpiter) {
IPropertyTree &t = wpiter->query();
const char *name = t.queryProp("@name");
if (!owner||!*owner||(name&&(strcmp(owner,name)==0)))
count += t.getPropInt("@count");
}
return count;
}

bool CDistributedFileDirectory::getProtectedInfo(const CDfsLogicalFileName &logicalName, StringArray &names, UnsignedArray &counts)
{
CFileAttrLock attrLock;
if (!attrLock.init(logicalName, RTM_LOCK_READ, NULL, defaultTimeout, "CDistributedFileDirectory::getProtectedInfo"))
return false; // timeout will raise exception
Owned<IPropertyTreeIterator> wpiter = attrLock.queryRoot()->getElements("Protect");
bool prot = false;
ForEach(*wpiter) {
IPropertyTree &t = wpiter->query();
const char *name = t.queryProp("@name");
names.append(name?name:"<Unknown>");
unsigned c = t.getPropInt("@count");
if (c)
prot = true;
counts.append(c);
}
return prot;
return attrLock.queryRoot()->hasProp("Protect");
}

IDFProtectedIterator *CDistributedFileDirectory::lookupProtectedFiles(const char *owner,bool notsuper,bool superonly)
Expand Down
7 changes: 0 additions & 7 deletions dali/base/dadfs.hpp
Expand Up @@ -81,7 +81,6 @@ interface IDFProtectedIterator: public IInterface
virtual bool isValid() = 0;
virtual const char *queryFilename() = 0;
virtual const char *queryOwner() = 0;
virtual unsigned getCount() = 0;
virtual bool isSuper() = 0;
};

Expand Down Expand Up @@ -680,12 +679,6 @@ interface IDistributedFileDirectory: extends IInterface
unsigned timeout=0 // 0 = return state immediately, >0 waits until false or timed-out
) = 0;

virtual unsigned queryProtectedCount(const CDfsLogicalFileName &logicalname,
const char *callerid=NULL) = 0; // if NULL then sums all

virtual bool getProtectedInfo (const CDfsLogicalFileName &logicalname,
StringArray &names, UnsignedArray &counts) = 0;

virtual IDFProtectedIterator *lookupProtectedFiles(const char *owner=NULL,bool notsuper=false,bool superonly=false)=0; // if owner = NULL then all
virtual IDFAttributesIterator* getLogicalFilesSorted(IUserDescriptor* udesc, DFUQResultField *sortOrder, const void* filters, DFUQResultField *localFilters,
const void *specialFilterBuf, unsigned startOffset, unsigned maxNum, __int64 *cacheHint, unsigned *total, bool *allMatchingFilesReceived) = 0;
Expand Down
2 changes: 1 addition & 1 deletion dali/daliadmin/daliadmin.cpp
Expand Up @@ -1180,7 +1180,7 @@ static void listprotect(const char *filename, const char *callerid)
Owned<IDFProtectedIterator> piter = queryDistributedFileDirectory().lookupProtectedFiles((strcmp(callerid,"*")==0)?NULL:callerid);
ForEach(*piter) {
if (WildMatch(piter->queryFilename(),filename))
OUTLOG("%s,%s,%s,%u",piter->isSuper()?"SuperFile":"File",piter->queryFilename(),piter->queryOwner(),piter->getCount());
OUTLOG("%s,%s,%s", piter->isSuper()?"SuperFile":"File", piter->queryFilename(), piter->queryOwner());
}
}

Expand Down
6 changes: 3 additions & 3 deletions esp/scm/ws_dfu.ecm
Expand Up @@ -158,7 +158,7 @@ ESPStruct [nil_remove] DFUFilePartsOnCluster
ESPStruct [nil_remove] DFUFileProtect
{
string Owner;
int Count;
[depr_ver("1.54")] int Count;
string Modified;
};

Expand Down Expand Up @@ -986,8 +986,8 @@ ESPresponse [exceptions_inline, nil_remove] DFUFilePublishResponse
// ===========================================================================
ESPservice [
auth_feature("DEFERRED"),
version("1.53"),
default_client_version("1.53"),
version("1.54"),
default_client_version("1.54"),
noforms,
exceptions_inline("./smc_xslt/exceptions.xslt")] WsDfu
{
Expand Down
4 changes: 2 additions & 2 deletions esp/services/ws_dfu/ws_dfuService.cpp
Expand Up @@ -2096,13 +2096,13 @@ void CWsDfuEx::doGetFileDetails(IEspContext &context, IUserDescriptor *udesc, co
IPropertyTree &tree = itr->query();
const char *owner = tree.queryProp("@name");
const char *modified = tree.queryProp("@modified");
int count = tree.getPropInt("@count", 0);
Owned<IEspDFUFileProtect> protect= createDFUFileProtect();
if(owner && *owner)
protect->setOwner(owner);
if(modified && *modified)
protect->setModified(modified);
protect->setCount(count);
if (version < 1.54)
protect->setCount(1);
protectList.append(*protect.getLink());
}
FileDetails.setProtectList(protectList);
Expand Down
9 changes: 3 additions & 6 deletions plugins/fileservices/fileservices.cpp
Expand Up @@ -2582,12 +2582,9 @@ FILESERVICES_API char * FILESERVICES_CALL fsfGetLogicalFileAttribute(ICodeContex
ForEach(*piter) {
const char *name = piter->get().queryProp("@name");
if (name&&*name) {
unsigned count = piter->get().getPropInt("@count");
if (count) {
if (ret.length())
ret.append(',');
ret.append(name);
}
if (ret.length())
ret.append(',');
ret.append(name);
}
}
}
Expand Down

0 comments on commit 9685f9c

Please sign in to comment.