long bytesRemaining = length;
Path compressionPath = new Path(path.getParent(), path.getName().replaceAll("-Data.db",
"-CompressionInfo.db"));
if (!fs.exists(compressionPath)) {
OffsetScanner scanner = null;
// Only initialize if we are going to have more than a single
// split
Path indexPath = null;
if (fuzzySplit < length) {
indexPath = new Path(path.getParent(), path.getName().replaceAll("-Data.db", "-Index.db"));
if (!fs.exists(indexPath)) {
fuzzySplit = length;
} else {
FSDataInputStream fileIn = fs.open(indexPath);
scanner = new OffsetScanner(new BufferedInputStream(fileIn), indexPath.getName());
}
}
long splitStart = 0;
long indexOffset = 0;
long newIndexOffset = 0;
while (splitStart + fuzzySplit < length && scanner != null && scanner.hasNext()) {
long splitSize = 0;
// The scanner returns an offset from the start of the file.
while (splitSize < maxSplitSize && scanner.hasNext()) {
Pair<Long, Long> pair = scanner.next();
splitSize = pair.left - splitStart;
newIndexOffset = pair.right;
}
int blkIndex = getBlockIndex(blkLocations, splitStart + (splitSize / 2));
LOG.debug("split path: {}:{}:{}", path.getName(), splitStart, splitSize);
splits.add(new AegSplit(path, splitStart, splitSize, blkLocations[blkIndex].getHosts()));
indexOffset = newIndexOffset;
bytesRemaining -= splitSize;
splitStart += splitSize;
}
if (scanner != null) {
scanner.close();
}
}
if (bytesRemaining != 0) {
LOG.debug("end path: {}:{}:{}", path.getName(), length - bytesRemaining, bytesRemaining);