summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-19 20:04:12 +0200
committerSimon Rettberg2015-08-19 20:04:12 +0200
commit17d4a4b2bf4c16d8b68b03cb2945a926a8146929 (patch)
treeba933a01c0fbde84df449431a7a66741ecc984e9 /dozentenmodulserver
parentMerge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff)
downloadtutor-module-17d4a4b2bf4c16d8b68b03cb2945a926a8146929.tar.gz
tutor-module-17d4a4b2bf4c16d8b68b03cb2945a926a8146929.tar.xz
tutor-module-17d4a4b2bf4c16d8b68b03cb2945a926a8146929.zip
[server] Make a copy of the chunk before passing it to the async hash checker
Diffstat (limited to 'dozentenmodulserver')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
index f03c06f3..b3bf4133 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/ActiveUpload.java
@@ -106,7 +106,7 @@ public class ActiveUpload implements HashCheckCallback {
static {
HashChecker hc;
try {
- hc = new HashChecker("SHA1");
+ hc = new HashChecker("SHA-1");
} catch (NoSuchAlgorithmException e) {
hc = null;
}
@@ -117,7 +117,7 @@ public class ActiveUpload implements HashCheckCallback {
long fileSize, List<byte[]> sha1Sums, byte[] machineDescription) throws FileNotFoundException {
this.destinationFile = destinationFile;
this.outFile = new RandomAccessFile(destinationFile, "rw");
- this.chunks = new ChunkList(fileSize, sha1Sums);
+ this.chunks = new ChunkList(fileSize, hashChecker == null ? null : sha1Sums);
this.owner = owner;
this.image = image;
this.fileSize = fileSize;
@@ -154,7 +154,7 @@ public class ActiveUpload implements HashCheckCallback {
* discarded
*/
public synchronized boolean addConnection(final Downloader connection, ThreadPoolExecutor pool) {
- if (chunks.isComplete() || state == TransferState.FINISHED || state == TransferState.ERROR)
+ if (state == TransferState.FINISHED || state == TransferState.ERROR)
return false;
synchronized (downloads) {
if (downloads.size() >= MAX_CONNECTIONS)
@@ -222,6 +222,7 @@ public class ActiveUpload implements HashCheckCallback {
Util.safeClose(outFile);
state = TransferState.FINISHED;
}
+ LOGGER.info("Finalizing uploaded image " + image.imageName);
File file = destinationFile;
// Ready to go. First step: Rename temp file to something usable
File destination = new File(file.getParent(), Formatter.vmName(owner, image.imageName));
@@ -332,6 +333,7 @@ public class ActiveUpload implements HashCheckCallback {
Thread.currentThread().interrupt();
return null;
}
+ buffer = new byte[buffer.length];
} else {
writeFileData(currentChunk.range.startOffset, currentChunk.range.getLength(), buffer);
chunks.markSuccessful(currentChunk);
@@ -370,14 +372,22 @@ public class ActiveUpload implements HashCheckCallback {
case VALID:
writeFileData(chunk.range.startOffset, chunk.range.getLength(), data);
chunks.markSuccessful(chunk);
+ if (chunks.isComplete()) {
+ finishUpload();
+ }
break;
case INVALID:
+ LOGGER.warn("Hash check of chunk " + chunk.getChunkIndex() + " resulted in mismatch "
+ + chunk.getFailCount() + "x :-(");
chunks.markFailed(chunk);
+ break;
}
}
private byte[] loadChunkFromFile(FileChunk chunk) {
synchronized (outFile) {
+ if (state != TransferState.IDLE && state != TransferState.WORKING)
+ return null;
try {
outFile.seek(chunk.range.startOffset);
byte[] buffer = new byte[chunk.range.getLength()];
@@ -393,15 +403,22 @@ public class ActiveUpload implements HashCheckCallback {
}
public void updateBlockHashList(List<byte[]> hashList) {
+ if (state != TransferState.IDLE && state != TransferState.WORKING)
+ return;
if (hashChecker == null)
return;
chunks.updateSha1Sums(hashList);
- for (FileChunk chunk = chunks.getUnhashedComplete(); chunk != null;) {
+ FileChunk chunk;
+ while (null != (chunk = chunks.getUnhashedComplete())) {
byte[] data = loadChunkFromFile(chunk);
+ if (data == null) {
+ LOGGER.warn("Will mark unloadable chunk as valid :-(");
+ chunks.markSuccessful(chunk);
+ continue;
+ }
try {
hashChecker.queue(chunk, data, this);
} catch (InterruptedException e) {
- LOGGER.warn("Got interrupted while queueing block for hash check", e);
Thread.currentThread().interrupt();
return;
}