Skip to content

Commit fed769f

Browse files
committed
drv: add dCache admin command to show panding requests
easy way to match dcache to cta requests
1 parent 03aecf4 commit fed769f

3 files changed

Lines changed: 91 additions & 7 deletions

File tree

src/main/java/org/dcache/nearline/cta/CtaNearlineStorage.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.google.common.net.HostAndPort;
1010
import com.google.common.util.concurrent.ThreadFactoryBuilder;
1111
import diskCacheV111.util.CacheException;
12+
import dmg.util.command.Command;
1213
import io.grpc.ChannelCredentials;
1314
import io.grpc.ConnectivityState;
1415
import io.grpc.Deadline;
@@ -27,13 +28,15 @@
2728
import java.util.Objects;
2829
import java.util.Set;
2930
import java.util.UUID;
30-
31+
import java.util.concurrent.Callable;
3132
import java.util.concurrent.ConcurrentHashMap;
3233
import java.util.concurrent.ConcurrentMap;
3334
import java.util.concurrent.ExecutionException;
34-
import ch.cern.cta.rpc.CtaRpcGrpc.CtaRpcBlockingStub;
3535
import java.util.concurrent.Executors;
3636
import java.util.concurrent.TimeUnit;
37+
import java.util.stream.Collectors;
38+
39+
import ch.cern.cta.rpc.CtaRpcGrpc.CtaRpcBlockingStub;
3740
import org.dcache.namespace.FileAttribute;
3841
import org.dcache.nearline.cta.xrootd.DataMover;
3942
import org.dcache.pool.nearline.spi.FlushRequest;
@@ -249,7 +252,7 @@ public void completed(Set<URI> uris) {
249252

250253
var cancelRequest = ctaRequestFactory.getAbortStoreRequest(ar, response);
251254

252-
pendingRequests.put(id, new PendingRequest(r) {
255+
pendingRequests.put(id, new PendingRequest(r, response.getRequestObjectstoreId(), PendingRequest.Type.FLUSH) {
253256
@Override
254257
public void cancel() {
255258
try {
@@ -318,7 +321,7 @@ public void completed(Set<Checksum> checksums) {
318321
);
319322

320323
var cancelRequest = ctaRequestFactory.getAbortStageRequest(rr, response);
321-
pendingRequests.put(id, new PendingRequest(r) {
324+
pendingRequests.put(id, new PendingRequest(r, response.getRequestObjectstoreId(), PendingRequest.Type.STAGE) {
322325
@Override
323326
public void cancel() {
324327
// on cancel send the request to CTA; on success cancel the requests
@@ -543,4 +546,33 @@ private CacheException asCacheException(Throwable e) {
543546
private URI createZeroFileUri(FileAttributes attrs) {
544547
return URI.create(type + "://" + name + "/" + attrs.getPnfsId() + "?archiveid=*");
545548
}
549+
550+
@Command(name="show requests")
551+
public class ShowRequestsCommand implements Callable<String> {
552+
@Override
553+
public String call() {
554+
if (pendingRequests.isEmpty()) {
555+
return "No pending requests";
556+
}
557+
558+
StringBuilder sb = new StringBuilder();
559+
sb.append("Pending requests:\n");
560+
561+
pendingRequests.entrySet().stream()
562+
.collect(Collectors.groupingBy(e -> e.getValue().getAction()))
563+
.forEach((type, entries) -> {
564+
sb.append(type).append(":\n");
565+
sb.append(" count: ").append(entries.size()).append("\n");
566+
for (var entry : entries) {
567+
sb.append(" ")
568+
.append(entry.getKey())
569+
.append(" -> ")
570+
.append(entry.getValue().getCtaRequestId()).append("\n");
571+
}
572+
sb.append("\n");
573+
});
574+
575+
return sb.toString();
576+
}
577+
}
546578
}

src/main/java/org/dcache/nearline/cta/PendingRequest.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
*/
1111
public class PendingRequest {
1212

13+
/**
14+
* The type of the request.
15+
* <p>
16+
* STAGE - request to stage file from nearline storage to online storage.
17+
* FLUSH - request to flush file from online storage to nearline storage.
18+
* CANCEL - request to cancel staged file.
19+
* DELETE - request to delete archived file.
20+
*/
21+
public enum Type {
22+
STAGE, // request to stage file
23+
FLUSH, // request to flush file
24+
CANCEL, // request to cancel staged file
25+
DELETE // request to delete arcived file
26+
}
27+
1328
/**
1429
* Point on the time-line when request was submitted into pending queue.
1530
*/
@@ -20,9 +35,28 @@ public class PendingRequest {
2035
*/
2136
private final NearlineRequest request;
2237

23-
public PendingRequest(NearlineRequest request) {
38+
/**
39+
* CTA scheduler request ID (aka object store ID).
40+
*/
41+
private final String ctaRequestId;
42+
43+
/**
44+
* The type of the request.
45+
*/
46+
private Type action;
47+
48+
/**
49+
* Constructs a new pending request.
50+
*
51+
* @param request the nearline request.
52+
* @param ctaRequestId the CTA request ID (aka object store ID).
53+
* @param action the type of the request.
54+
*/
55+
public PendingRequest(NearlineRequest request, String ctaRequestId, Type action) {
2456
this.submissionTime = Instant.now();
2557
this.request = request;
58+
this.ctaRequestId = ctaRequestId;
59+
this.action = action;
2660
}
2761

2862
/**
@@ -52,6 +86,24 @@ public UUID getRequestId() {
5286
return request.getId();
5387
}
5488

89+
/**
90+
* Returns CTA request ID (aka object store ID).
91+
*
92+
* @return CTA request ID.
93+
*/
94+
public String getCtaRequestId() {
95+
return ctaRequestId;
96+
}
97+
98+
/**
99+
* Returns the request type.
100+
*
101+
* @return the request type.
102+
*/
103+
public Type getAction() {
104+
return action;
105+
}
106+
55107
public void cancel() {
56108
request.failed(new CancellationException("Canceled by dCache"));
57109
}

src/test/java/org/dcache/nearline/cta/xrootd/DataServerHandlerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private StageRequest mockedStageRequest() throws IOException {
531531

532532
when(request.getReplicaUri()).thenReturn(f.toURI());
533533

534-
requests.put("0000C9B4E3768770452E8B1B8E0232584872", new PendingRequest(request));
534+
requests.put("0000C9B4E3768770452E8B1B8E0232584872", new PendingRequest(request, "stage", PendingRequest.Type.STAGE));
535535

536536
waitForComplete = new CompletableFuture<>();
537537

@@ -573,7 +573,7 @@ private FlushRequest mockedFlushRequest() throws IOException {
573573

574574
when(request.getReplicaUri()).thenReturn(f.toURI());
575575

576-
requests.put("0000C9B4E3768770452E8B1B8E0232584872", new PendingRequest(request));
576+
requests.put("0000C9B4E3768770452E8B1B8E0232584872", new PendingRequest(request, "flush", PendingRequest.Type.FLUSH));
577577

578578
return request;
579579
}

0 commit comments

Comments
 (0)