Skip to content

Commit

Permalink
driver: shortcut zero-byte files
Browse files Browse the repository at this point in the history
  • Loading branch information
kofemann committed Feb 19, 2024
1 parent d9dea09 commit 3d99040
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/org/dcache/nearline/cta/CtaNearlineStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ public void onCompleted() {
public void remove(Iterable<RemoveRequest> requests) {

for (var r : requests) {

// short-circuit zero-byte files
if (r.getUri().getQuery().contains("archiveid=*")) {
r.completed(null);
continue;
}

var deleteRequest = ctaRequestFactory.valueOf(r);
cta.withDeadline(getRequestDeadline()).delete(deleteRequest, new StreamObserver<>() {
@Override
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/org/dcache/nearline/cta/CtaNearlineStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -358,6 +359,25 @@ public void testSuccessOnRemove() {
verify(request).completed(any());
}

@Test
public void testRemoveZeroByteFiles() {

var request = mockedRemoveRequest();
when(request.getUri()).thenReturn(
URI.create("cta://cta/0000C9B4E3768770452E8B1B8E0232584872?archiveid=*"));

driver = new CtaNearlineStorage("foo", "bar");
driver.configure(drvConfig);
driver.start();

driver.remove(Set.of(request));
waitToComplete();

verify(request).completed(any());
// ensure that shortcut is used
verify(cta.ctaSvc(), never()).delete(any(), any());
}

@Test
public void testRemoveRequestOnRpcError() {

Expand Down
12 changes: 11 additions & 1 deletion src/test/java/org/dcache/nearline/cta/DummyCta.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dcache.nearline.cta;

import static org.mockito.Mockito.spy;
import ch.cern.cta.rpc.ArchiveResponse;
import ch.cern.cta.rpc.CreateResponse;
import ch.cern.cta.rpc.CtaRpcGrpc;
Expand Down Expand Up @@ -29,7 +30,12 @@ public class DummyCta {

private volatile boolean drop;

private final CtaRpcGrpc.CtaRpcImplBase ctaSvc;

public DummyCta(File cert, File key) throws Exception {

ctaSvc = spy(new CtaSvc());

server = NettyServerBuilder.forPort(0)
.sslContext(GrpcSslContexts.forServer(cert, key)
.clientAuth(ClientAuth.NONE)
Expand All @@ -39,7 +45,7 @@ public DummyCta(File cert, File key) throws Exception {
.bossEventLoopGroup( new NioEventLoopGroup(2, new ThreadFactoryBuilder().setNameFormat("dummy-cta-server-accept-%d").build()))
.workerEventLoopGroup(new NioEventLoopGroup(2, new ThreadFactoryBuilder().setNameFormat("dummy-cta-server-worker-%d").build()))
.channelType(NioServerSocketChannel.class)
.addService(new CtaSvc())
.addService(ctaSvc)
.directExecutor()
.build();
}
Expand All @@ -55,6 +61,10 @@ public void shutdown() throws InterruptedException {
}
}

public CtaRpcGrpc.CtaRpcImplBase ctaSvc() {
return ctaSvc;
}

public String getConnectString() {
return "localhost:" + server.getPort();
}
Expand Down

0 comments on commit 3d99040

Please sign in to comment.