key = "DISTRIBUTE-" + dcount;
brick = vol.get(key).get(0);
if (hnts == null) {
result = new BlockLocation[1];
result[0] = new BlockLocation(null, new String[] {brick2host(brick)}, start, len);
} else
hnts.put(0, new GlusterFSBrickClass(brick, start, len, false, -1, -1, -1));
break;
case R:
case DR:
/* just the name says it's striped - the volume isn't */
stripedBricks = new ArrayList<String>();
for (i = 1; i <= rcount; i++) {
key = "REPLICATE-" + i;
brickList = vol.get(key);
it = brickList.iterator();
while (it.hasNext()) {
stripedBricks.add(it.next());
}
}
nrAllocs = stripedBricks.size();
if (hnts == null) {
result = new BlockLocation[1];
blks = new String[nrAllocs];
}
for (i = 0; i < nrAllocs; i++) {
if (hnts == null)
blks[i] = brick2host(stripedBricks.get(i));
else
hnts.put(i, new GlusterFSBrickClass(stripedBricks.get(i), start, len, false, -1, -1, -1));
}
if (hnts == null)
result[0] = new BlockLocation(null, blks, start, len);
break;
case SR:
case DSR:
int rsize = 0;
ArrayList<ArrayList<String>> replicas = new ArrayList<ArrayList<String>>();
stripedBricks = new ArrayList<String>();
if (rcount == 0)
throw new IOException("got replicated volume with replication count 0");
for (i = 1; i <= rcount; i++) {
key = "REPLICATE-" + i;
brickList = vol.get(key);
it = brickList.iterator();
replicas.add(i - 1, new ArrayList<String>());
while (it.hasNext()) {
replicas.get(i - 1).add(it.next());
}
}
stripeSize = meta.get("block-size");
nrAllocs = (int) (((len - start) / stripeSize) + 1);
if (hnts == null) {
result = new BlockLocation[nrAllocs];
repl = new GlusterFSBrickRepl[nrAllocs];
}
// starting stripe position
counter = (int) ((start / stripeSize) % rcount);
stripeStart = start;
key = null;
int currAlloc = 0;
boolean hntsDone = false;
while ((stripeStart < len) && !done) {
stripeEnd = (stripeStart - (stripeStart % stripeSize)) + stripeSize - 1;
if (stripeEnd > start + len) {
stripeEnd = start + len - 1;
done = true;
}
rsize = replicas.get(counter).size();
if (hnts == null)
repl[allocCtr] = new GlusterFSBrickRepl(rsize, stripeStart, (stripeEnd - stripeStart));
for (i = 0; i < rsize; i++) {
brick = replicas.get(counter).get(i);
currAlloc = (allocCtr * rsize) + i;
if (hnts == null)
repl[allocCtr].addHost(brick2host(brick));
else
if (currAlloc <= (rsize * rcount) - 1) {
hnts.put(currAlloc, new GlusterFSBrickClass(brick, stripeStart,
(stripeEnd - stripeStart),
true, stripeSize, rcount, rsize));
} else
hntsDone = true;
}
if (hntsDone)
break;
stripeStart = stripeEnd + 1;
allocCtr++;
counter++;
if (counter >= replicas.size())
counter = 0;
}
if (hnts == null)
for (int k = 0; k < nrAllocs; k++)
result[k] = new BlockLocation(null, repl[k].getReplHosts(), repl[k].getStartLen(), repl[k].getOffLen());
break;
case S:
case DS:
if (scount == 0)
throw new IOException("got striped volume with stripe count 0");
stripedBricks = new ArrayList<String>();
stripeSize = meta.get("block-size");
key = "STRIPE-" + scount;
brickList = vol.get(key);
it = brickList.iterator();
while (it.hasNext()) {
stripedBricks.add(it.next());
}
nrAllocs = (int) ((len - start) / stripeSize) + 1;
if (hnts == null)
result = new BlockLocation[nrAllocs];
// starting stripe position
counter = (int) ((start / stripeSize) % stripedBricks.size());
stripeStart = start;
key = null;
while ((stripeStart < len) && !done) {
brick = stripedBricks.get(counter);
stripeEnd = (stripeStart - (stripeStart % stripeSize)) + stripeSize - 1;
if (stripeEnd > start + len) {
stripeEnd = start + len - 1;
done = true;
}
if (hnts == null)
result[allocCtr] = new BlockLocation(null, new String[] {brick2host(brick)},
stripeStart, (stripeEnd - stripeStart));
else
if (allocCtr <= stripedBricks.size()) {
hnts.put(allocCtr, new GlusterFSBrickClass(brick, stripeStart, (stripeEnd - stripeStart),
true, stripeSize, stripedBricks.size(), -1));