Compare commits

...

1 Commits

Author SHA1 Message Date
alexandremerle cc94a13ebc wip 2017-10-29 18:51:57 +01:00
2 changed files with 40 additions and 3 deletions

View File

@ -4,7 +4,7 @@
* @return {array} parsedLocations - dataLocations filtered for * @return {array} parsedLocations - dataLocations filtered for
* what needed and ranges added for particular parts as needed * what needed and ranges added for particular parts as needed
*/ */
function setPartRanges(dataLocations, outerRange) { function setPartRanges(dataLocations, outerRange, log) {
const parsedLocations = []; const parsedLocations = [];
if (!outerRange) { if (!outerRange) {
@ -13,6 +13,9 @@ function setPartRanges(dataLocations, outerRange) {
const begin = outerRange[0]; const begin = outerRange[0];
const end = outerRange[1]; const end = outerRange[1];
if (log) {
log.info('begin set parts', { begin , end });
}
// If have single location, do not need to break up range among parts // If have single location, do not need to break up range among parts
// and might not have a start and size property // and might not have a start and size property
// on the dataLocation (because might be pre- md-model-version 2), // on the dataLocation (because might be pre- md-model-version 2),
@ -30,14 +33,20 @@ function setPartRanges(dataLocations, outerRange) {
soleLocation.size = soleLocation.size =
Math.min(partSize, end - begin + 1).toString(); Math.min(partSize, end - begin + 1).toString();
} }
if (log) {
log.info('soleLocation', { soleLocation });
}
parsedLocations.push(soleLocation); parsedLocations.push(soleLocation);
return parsedLocations; return parsedLocations;
} }
// Range is inclusive of endpoint so need plus 1 // Range is inclusive of endpoint so need plus 1
const max = end - begin + 1; const max = end - begin + 1;
if (log) {
log.info('multiple locations', { max });
}
let total = 0; let total = 0;
for (let i = 0; i < dataLocations.length; i++) { for (let i = 0; i < dataLocations.length; i++) {
if (total >= max) { if (total >= (max - 1)) {
break; break;
} }
const partStart = parseInt(dataLocations[i].start, 10); const partStart = parseInt(dataLocations[i].start, 10);
@ -50,6 +59,15 @@ function setPartRanges(dataLocations, outerRange) {
if (partSize + total <= max) { if (partSize + total <= max) {
const partWithoutRange = dataLocations[i]; const partWithoutRange = dataLocations[i];
partWithoutRange.size = partSize.toString(); partWithoutRange.size = partSize.toString();
if (log) {
log.info('add part without range', {
partSize,
total,
max,
partStart,
partWithoutRange,
});
}
parsedLocations.push(partWithoutRange); parsedLocations.push(partWithoutRange);
total += partSize; total += partSize;
// Otherwise set a range limit on the part end // Otherwise set a range limit on the part end
@ -62,6 +80,15 @@ function setPartRanges(dataLocations, outerRange) {
partWithRange.range = [0, endPart]; partWithRange.range = [0, endPart];
// modify size to be stored for object put part copy // modify size to be stored for object put part copy
partWithRange.size = (endPart + 1).toString(); partWithRange.size = (endPart + 1).toString();
if (log) {
log.info('add part with range', {
partSize,
total,
max,
partStart,
partWithRange,
});
}
parsedLocations.push(dataLocations[i]); parsedLocations.push(dataLocations[i]);
break; break;
} }
@ -77,6 +104,15 @@ function setPartRanges(dataLocations, outerRange) {
partWithRange.range = [startOffset, endPart]; partWithRange.range = [startOffset, endPart];
// modify size to be stored for object put part copy // modify size to be stored for object put part copy
partWithRange.size = (endPart - startOffset + 1).toString(); partWithRange.size = (endPart - startOffset + 1).toString();
if (log) {
log.info('add part with range, second path', {
partSize,
total,
max,
partStart,
partWithRange,
});
}
parsedLocations.push(partWithRange); parsedLocations.push(partWithRange);
// Need to add byte back since with total we are counting // Need to add byte back since with total we are counting
// number of bytes while the endPart and startOffset // number of bytes while the endPart and startOffset
@ -84,6 +120,7 @@ function setPartRanges(dataLocations, outerRange) {
total += endPart - startOffset + 1; total += endPart - startOffset + 1;
} }
} }
log.info('parsed locations', { parsedLocations });
return parsedLocations; return parsedLocations;
} }

View File

@ -183,7 +183,7 @@ function objectGet(authInfo, request, returnTagCount, log, callback) {
const end = endLocation.start + endLocation.size; const end = endLocation.start + endLocation.size;
responseMetaHeaders['Content-Length'] = end - start; responseMetaHeaders['Content-Length'] = end - start;
const partByteRange = [start, end]; const partByteRange = [start, end];
dataLocator = setPartRanges(dataLocator, partByteRange); dataLocator = setPartRanges(dataLocator, partByteRange, log);
} else { } else {
dataLocator = setPartRanges(dataLocator, byteRange); dataLocator = setPartRanges(dataLocator, byteRange);
} }