diff options
author | Simon Rettberg | 2019-10-21 16:59:32 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-10-21 17:08:16 +0200 |
commit | 535fc19e824abfe170b6fe03792519cb6e1105eb (patch) | |
tree | d6a5e7801eba3421f5f1bc40dcb17eabdb732ab3 /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java | |
parent | [client] Update virtualizer download link (diff) | |
download | tutor-module-535fc19e824abfe170b6fe03792519cb6e1105eb.tar.gz tutor-module-535fc19e824abfe170b6fe03792519cb6e1105eb.tar.xz tutor-module-535fc19e824abfe170b6fe03792519cb6e1105eb.zip |
[server] Disallow deleting busy images, fix multiple clones from master
Deleting images that are currently being up- or downloaded would create
some confusion server-side, so disallow this.
We accidentally didn't use the image version id as the transfer id for
downloads from the master server; fix that so that triggering the
download of the same image multiple times won't actually download the
same image multiple times.
Closes #3651
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java index e868ceaa..cf3bddf2 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java @@ -49,7 +49,7 @@ public class SyncTransferHandler { Thread.NORM_PRIORITY - 3)); /** - * All currently running downloads from master, indexed by token + * All currently running downloads from master, indexed by token, which is == versionId */ private static final Map<String, IncomingDataTransfer> downloads = new ConcurrentHashMap<>(); @@ -105,7 +105,7 @@ public class SyncTransferHandler { }; @Override - public void fire() { + public synchronized void fire() { if (uploadsByTransferId.isEmpty() && uploadsByVersionId.isEmpty() && downloads.isEmpty()) return; // Nothing to do anyways, don't wake up another thread if (transferPool.getMaximumPoolSize() - transferPool.getActiveCount() < 2 && ++skips < 10) @@ -182,12 +182,12 @@ public class SyncTransferHandler { throw new TInvocationException(InvocationError.INTERNAL_SERVER_ERROR, "Communication with master server failed"); } - OutgoingDataTransfer transfer = new OutgoingDataTransfer(transferInfo, absFile); + OutgoingDataTransfer transfer = new OutgoingDataTransfer(transferInfo, absFile, imgVersion.imageVersionId); uploadsByVersionId.put(imgVersion.imageVersionId, transfer); uploadsByTransferId.put(transfer.getId(), transfer); - transfer.heartBeat(transferPool); LOGGER.info("Client wants to upload image " + imgVersion.imageVersionId + ", created transfer " + transfer.getId()); + heartBeatTask.fire(); return transfer.getId(); } @@ -239,6 +239,7 @@ public class SyncTransferHandler { IncomingDataTransfer transfer = new IncomingDataTransfer(image, tmpFile, transferInfo, localImageData != null); downloads.put(transfer.getId(), transfer); + heartBeatTask.fire(); return transfer.getId(); } catch (FileNotFoundException e) { LOGGER.warn("Could not open " + tmpFile.getAbsolutePath()); @@ -308,5 +309,26 @@ public class SyncTransferHandler { return null; return downloads.get(downloadToken); } + + /** + * Check whether the given imageVersionId refers to an active transfer. + */ + public static boolean isActiveTransfer(String baseId, String versionId) { + if (versionId != null) { + OutgoingDataTransfer odt = uploadsByVersionId.get(versionId); + if (odt != null && !odt.isComplete(System.currentTimeMillis()) && odt.isActive()) + return true; + } + long now = System.currentTimeMillis(); + for (IncomingDataTransfer idt : downloads.values()) { + if (idt.isComplete(now) || !idt.isActive()) + continue; + if (versionId != null && versionId.equals(idt.getVersionId())) + return true; + if (baseId != null && baseId.equals(idt.getBaseId())) + return true; + } + return false; + } } |