Skip to content

Commit

Permalink
driver: don't flush empty files or files without checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
kofemann committed Jun 13, 2023
1 parent 4b0b7c8 commit 5bfdfa6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/main/java/org/dcache/nearline/cta/CtaNearlineStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
import ch.cern.cta.rpc.RetrieveResponse;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.dcache.namespace.FileAttribute;
import org.dcache.nearline.cta.xrootd.DataMover;
import org.dcache.pool.nearline.spi.FlushRequest;
import org.dcache.pool.nearline.spi.NearlineStorage;
import org.dcache.pool.nearline.spi.RemoveRequest;
import org.dcache.pool.nearline.spi.StageRequest;
import org.dcache.util.Checksum;
import org.dcache.util.ChecksumType;
import org.dcache.vehicles.FileAttributes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -190,6 +193,23 @@ public void flush(Iterable<FlushRequest> requests) {

try {
fr.activate().get();

// don't flush zero-byte files
if (fr.getFileAttributes().getSize() == 0) {
LOGGER.info("Fake flush of zero-byte file {}", fr.getFileAttributes().getPnfsId());
fr.completed(Set.of(createZeroFileUri(fr.getFileAttributes())));
continue;
}

// CTA can't flush files without checksum, thus, even don't try
if (!fr.getFileAttributes().isDefined(FileAttribute.CHECKSUM) ||
fr.getFileAttributes().getChecksums().isEmpty()) {
LOGGER.warn("Can't flush file {} - no checksum", fr.getFileAttributes().getPnfsId());
fr.failed(CacheException.NO_ATTRIBUTE, "Can't flush files without checksum");
continue;
}


final AtomicLong id = new AtomicLong();

var createRequest = ctaRequestFactory.valueOf(fr.getFileAttributes());
Expand Down Expand Up @@ -336,7 +356,15 @@ public void completed(Set<Checksum> checksums) {
try {
r.activate().get();
r.allocate().get();
} catch (ExecutionException | InterruptedException e) {

// no need to stage an empty files
if (sr.getFileAttributes().getSize() == 0) {
new File(sr.getReplicaUri().getPath()).createNewFile();
sr.completed(Set.of(new Checksum(ChecksumType.ADLER32.createMessageDigest())));
continue;
}

} catch (IOException | ExecutionException | InterruptedException e) {
Throwable t = Throwables.getRootCause(e);
LOGGER.error("Failed to activate/allocate space for retrieve request: {}",
t.getMessage());
Expand Down Expand Up @@ -583,4 +611,8 @@ private CacheException asCacheException(Throwable e) {

return new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.toString());
}

private URI createZeroFileUri(FileAttributes attrs) {
return URI.create(type + "://" + name + "/" + attrs.getPnfsId() + "?archiveid=*");
}
}
34 changes: 34 additions & 0 deletions src/test/java/org/dcache/nearline/cta/CtaNearlineStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.dcache.namespace.FileAttribute;
import org.dcache.pool.nearline.spi.FlushRequest;
import org.dcache.pool.nearline.spi.RemoveRequest;
import org.dcache.pool.nearline.spi.StageRequest;
import org.dcache.util.Checksum;
import org.dcache.util.ChecksumType;
import org.dcache.vehicles.FileAttributes;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -310,6 +313,36 @@ public void testFlushRequestFailOnRpcError() {
verify(request).failed(any());
}

@Test
public void testFlushOfEmptyFile() {

var request = mockedFlushRequest();
request.getFileAttributes().setSize(0L);

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

driver.flush(Set.of(request));
// TODO: check for correct URI
verify(request).completed(any());
}


@Test
public void testFlushWithoutChecksum() {

var request = mockedFlushRequest();
request.getFileAttributes().undefine(FileAttribute.CHECKSUM);

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

driver.flush(Set.of(request));
verify(request).failed(anyInt(), any());
}

@Test
public void testSuccessOnRemove() {

Expand Down Expand Up @@ -662,6 +695,7 @@ private FlushRequest mockedFlushRequest() {
.hsm("z")
.creationTime(System.currentTimeMillis())
.pnfsId("0000C9B4E3768770452E8B1B8E0232584872")
.checksum(new Checksum(ChecksumType.ADLER32.createMessageDigest()))
.build();

var request = mock(FlushRequest.class);
Expand Down

0 comments on commit 5bfdfa6

Please sign in to comment.