* i2psnark:
- Priority mapping bugfix - Close files as we go when creating/checking so we don't run out of file descriptors
This commit is contained in:
@ -422,7 +422,7 @@ public class Storage
|
|||||||
file++;
|
file++;
|
||||||
long oldFileEnd = fileEnd;
|
long oldFileEnd = fileEnd;
|
||||||
fileEnd += lengths[file];
|
fileEnd += lengths[file];
|
||||||
if (priorities[file] > pri && pcEnd < oldFileEnd)
|
if (priorities[file] > pri && oldFileEnd < pcEnd)
|
||||||
pri = priorities[file];
|
pri = priorities[file];
|
||||||
}
|
}
|
||||||
rv[i] = pri;
|
rv[i] = pri;
|
||||||
@ -669,6 +669,10 @@ public class Storage
|
|||||||
changed = true;
|
changed = true;
|
||||||
synchronized(RAFlock[i]) {
|
synchronized(RAFlock[i]) {
|
||||||
allocateFile(i);
|
allocateFile(i);
|
||||||
|
// close as we go so we don't run out of file descriptors
|
||||||
|
try {
|
||||||
|
closeRAF(i);
|
||||||
|
} catch (IOException ioe) {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_util.debug("File '" + names[i] + "' exists, but has wrong length - repairing corruption", Snark.ERROR);
|
_util.debug("File '" + names[i] + "' exists, but has wrong length - repairing corruption", Snark.ERROR);
|
||||||
@ -677,8 +681,10 @@ public class Storage
|
|||||||
synchronized(RAFlock[i]) {
|
synchronized(RAFlock[i]) {
|
||||||
checkRAF(i);
|
checkRAF(i);
|
||||||
rafs[i].setLength(lengths[i]);
|
rafs[i].setLength(lengths[i]);
|
||||||
|
try {
|
||||||
|
closeRAF(i);
|
||||||
|
} catch (IOException ioe) {}
|
||||||
}
|
}
|
||||||
// will be closed below
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,10 +693,25 @@ public class Storage
|
|||||||
{
|
{
|
||||||
pieces = metainfo.getPieces();
|
pieces = metainfo.getPieces();
|
||||||
byte[] piece = new byte[metainfo.getPieceLength(0)];
|
byte[] piece = new byte[metainfo.getPieceLength(0)];
|
||||||
|
int file = 0;
|
||||||
|
long fileEnd = lengths[0];
|
||||||
|
long pieceEnd = 0;
|
||||||
for (int i = 0; i < pieces; i++)
|
for (int i = 0; i < pieces; i++)
|
||||||
{
|
{
|
||||||
int length = getUncheckedPiece(i, piece);
|
int length = getUncheckedPiece(i, piece);
|
||||||
boolean correctHash = metainfo.checkPiece(i, piece, 0, length);
|
boolean correctHash = metainfo.checkPiece(i, piece, 0, length);
|
||||||
|
// close as we go so we don't run out of file descriptors
|
||||||
|
pieceEnd += length;
|
||||||
|
while (fileEnd <= pieceEnd) {
|
||||||
|
synchronized(RAFlock[file]) {
|
||||||
|
try {
|
||||||
|
closeRAF(file);
|
||||||
|
} catch (IOException ioe) {}
|
||||||
|
}
|
||||||
|
if (++file >= rafs.length)
|
||||||
|
break;
|
||||||
|
fileEnd += lengths[file];
|
||||||
|
}
|
||||||
if (correctHash)
|
if (correctHash)
|
||||||
{
|
{
|
||||||
bitfield.set(i);
|
bitfield.set(i);
|
||||||
@ -705,13 +726,14 @@ public class Storage
|
|||||||
_probablyComplete = complete();
|
_probablyComplete = complete();
|
||||||
// close all the files so we don't end up with a zillion open ones;
|
// close all the files so we don't end up with a zillion open ones;
|
||||||
// we will reopen as needed
|
// we will reopen as needed
|
||||||
for (int i = 0; i < rafs.length; i++) {
|
// Now closed above to avoid running out of file descriptors
|
||||||
synchronized(RAFlock[i]) {
|
//for (int i = 0; i < rafs.length; i++) {
|
||||||
try {
|
// synchronized(RAFlock[i]) {
|
||||||
closeRAF(i);
|
// try {
|
||||||
} catch (IOException ioe) {}
|
// closeRAF(i);
|
||||||
}
|
// } catch (IOException ioe) {}
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.storageAllChecked(this);
|
listener.storageAllChecked(this);
|
||||||
@ -720,6 +742,7 @@ public class Storage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** this calls openRAF(); caller must synnchronize and call closeRAF() */
|
||||||
private void allocateFile(int nr) throws IOException
|
private void allocateFile(int nr) throws IOException
|
||||||
{
|
{
|
||||||
// caller synchronized
|
// caller synchronized
|
||||||
|
Reference in New Issue
Block a user