diff --git a/docs/TheBook/src/main/markdown/config-scitags.md b/docs/TheBook/src/main/markdown/config-scitags.md index fb1bda2e13e..ac06d263f40 100644 --- a/docs/TheBook/src/main/markdown/config-scitags.md +++ b/docs/TheBook/src/main/markdown/config-scitags.md @@ -359,8 +359,8 @@ Main JSON sections: - `usage` (`received`, `sent`) - optional `storage-stats` when `pool.firefly.storage-statistics=true` -For end markers, `start-time` is reconstructed from mover submit time and `end-time` -is derived as `start-time + max(connectionTime, 0)`. +For end markers sent by a pool, `end-time` is the time the transfer finished and +`start-time` is derived as `end-time - max(connectionTime, 0)`. Test schema file: diff --git a/modules/dcache/src/main/java/org/dcache/pool/movers/TransferLifeCycle.java b/modules/dcache/src/main/java/org/dcache/pool/movers/TransferLifeCycle.java index 26ea20a5511..353f96b19da 100644 --- a/modules/dcache/src/main/java/org/dcache/pool/movers/TransferLifeCycle.java +++ b/modules/dcache/src/main/java/org/dcache/pool/movers/TransferLifeCycle.java @@ -152,8 +152,12 @@ public void onStart(InetSocketAddress src, InetSocketAddress dst, ProtocolInfo p * @param mover the mover's description of the completed transfer */ public void onEnd(InetSocketAddress src, InetSocketAddress dst, MoverInfoMessage mover) { + // The mover info message is created when the transfer has finished, so its + // timestamp is the end of the transfer; the start is derived from the duration. + long durationMillis = Math.max(0L, mover.getConnectionTime()); onEnd(src, dst, mover.getProtocolInfo(), mover.getSubject(), - Instant.ofEpochMilli(mover.getTimestamp()), mover.getConnectionTime(), + Instant.ofEpochMilli(mover.getTimestamp()).minusMillis(durationMillis), + durationMillis, mover.getBytesRead(), mover.getBytesWritten(), storageStatisticsEnabled ? mover : null); } diff --git a/modules/dcache/src/test/java/org/dcache/pool/movers/TransferLifeCycleTest.java b/modules/dcache/src/test/java/org/dcache/pool/movers/TransferLifeCycleTest.java index e9db2da30ef..81d064ae02b 100644 --- a/modules/dcache/src/test/java/org/dcache/pool/movers/TransferLifeCycleTest.java +++ b/modules/dcache/src/test/java/org/dcache/pool/movers/TransferLifeCycleTest.java @@ -138,7 +138,7 @@ public void shouldSendEndMarkerForTransferWithoutMover() throws Exception { } @Test - public void shouldSetEndMarkerStartTimeFromTransferDuration() throws Exception { + public void shouldDeriveEndMarkerTimesFromTransferEnd() throws Exception { try (DatagramSocket socket = new DatagramSocket(0, InetAddress.getByName("127.0.0.1"))) { socket.setSoTimeout(700); @@ -156,8 +156,9 @@ public void shouldSetEndMarkerStartTimeFromTransferDuration() throws Exception { mover.setBytesRead(1024); mover.setBytesWritten(0); - Instant expectedStart = Instant.ofEpochMilli(mover.getTimestamp()); - Instant expectedEnd = expectedStart.plusMillis(transferDuration); + // the mover info message is created when the transfer has finished + Instant expectedEnd = Instant.ofEpochMilli(mover.getTimestamp()); + Instant expectedStart = expectedEnd.minusMillis(transferDuration); lifecycle.onEnd( new InetSocketAddress("203.0.113.20", 42000), @@ -174,10 +175,13 @@ public void shouldSetEndMarkerStartTimeFromTransferDuration() throws Exception { Instant startTime = Instant.parse(lifecyclePayload.getString("start-time")); Instant endTime = Instant.parse(lifecyclePayload.getString("end-time")); + Instant currentTime = Instant.parse(lifecyclePayload.getString("current-time")); assertEquals(expectedStart, startTime); assertEquals(expectedEnd, endTime); assertEquals(transferDuration, Duration.between(startTime, endTime).toMillis()); + assertFalse("end-time must not lie after the time the marker was built", + endTime.isAfter(currentTime)); } }