Skip to content

Commit

Permalink
Match file prefix to storage plane definition
Browse files Browse the repository at this point in the history
- Find match first and throw an error if one is not found
- Check next segment for striping if numDevices>1
- Only check last segment before filename for dir-per-part number
- avoid copying single chars and copy chunks after we look for dir-per-part
  • Loading branch information
jackdelv committed Nov 8, 2024
1 parent ded8478 commit 5aa25a9
Showing 1 changed file with 48 additions and 45 deletions.
93 changes: 48 additions & 45 deletions dali/dfuXRefLib/dfuxreflib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,61 +943,65 @@ static bool parseFileName(const char *name,StringBuffer &mname,unsigned &num,uns
replicate = setReplicateDir(name,nonrepdir,false);
if (replicate)
name = nonrepdir.str();
num = 0;
max = 0;
unsigned dirPerPart = 0;
for (;;) {
char c=*name;
if (!c)
break;
if ((c=='d')&&(isdigit(name[1])))
{
// Checks that the prefix matches and numDevices > 1 to see if d[0-9]+ is a stripe number
mname.append(c);
name++;

Owned<IPropertyTreeIterator> planesIter = getPlanesIterator("data", nullptr);
ForEach(*planesIter)
{
const IPropertyTree &plane = planesIter->query();
if (startsWith(mname.str(), plane.queryProp("@prefix")))
{
if (plane.getPropInt("@numDevices") > 1)
{
while (*name&&isdigit(*name))
name++;
mname.append("$P$");
}
break;
}
}
c = *name;
}
if ((c=='/')&&(isdigit(name[1])))
Owned<IPropertyTreeIterator> planesIter = getPlanesIterator("data", nullptr);
ForEach(*planesIter)
{
const IPropertyTree &plane = planesIter->query();
const char *prefix = plane.queryProp("@prefix");
if (startsWith(name, prefix))
{
mname.append(c);
name++;

// Get dir-per-part #
while (*name&&isdigit(*name))
mname.ensureCapacity(strlen(name));
mname.append(prefix).append(PATHSEPCHAR);
name += strlen(prefix) + 1;
if (plane.getPropInt("@numDevices") > 1)
{
dirPerPart = dirPerPart*10+(*name-'0');
if (*name&&*name!='d')
throw makeStringExceptionV(-1, "numDevices>1 but no stripe sub-directory in file %s", mname.append(name).str());
name++;
while (*name&&isdigit(*name))
name++;
mname.append("d$P$");
}

c=*name;
mname.append("$P$");
break;
}
if ((c=='.')&&(name[1]=='_')) {
}

if (mname.isEmpty())
throw makeStringExceptionV(-1, "Could not find matching prefix in plane definition for file %s", name);

num = 0;
max = 0;
unsigned dirPerPart = 0;
const char * cur = name;
for (;;) {
char c=*cur;
if (!c)
break;
if ((c=='.')&&(cur[1]=='_')) {
unsigned pn = 0;
const char *s = name+2;
const char *s = cur+2;
while (*s&&isdigit(*s)) {
pn = pn*10+(*s-'0');
s++;
}

if (dirPerPart&&dirPerPart!=pn)
throw makeStringException(-1, "dir-per-part # does not match part # of file");
// Check for dir-per-part number
const char *tailSlash = cur;
while (*tailSlash&&*tailSlash!='/')
tailSlash--;
const char *d = tailSlash;
for (int i=1;*(--d)&&isdigit(*d);i++)
dirPerPart = dirPerPart+(*d-'0')*i;
if (*d&&*d=='/')
{
if (dirPerPart!=pn)
throw makeStringException(-1, "dir-per-part # does not match part # of file");

mname.append((d+1)-name, name).append("$P$").append(cur-tailSlash, tailSlash);
}
else
mname.append(cur-name,name);

if (pn&&(memicmp(s,"_of_",4)==0)) {
unsigned mn = 0;
Expand All @@ -1016,8 +1020,7 @@ static bool parseFileName(const char *name,StringBuffer &mname,unsigned &num,uns
}
}
}
mname.append(c);
name++;
cur++;
}
return false;
}
Expand Down

0 comments on commit 5aa25a9

Please sign in to comment.