From bf22612c43ca02c77d4ed77e2b446af178202a86 Mon Sep 17 00:00:00 2001 From: Anton Klaren Date: Mon, 9 Apr 2018 10:58:35 +0200 Subject: [PATCH] Fix leaking resource in StoreResource that prevented deletion of files during tests --- .../catchup/storecopy/FileSender.java | 10 +++++++--- .../catchup/storecopy/StoreResource.java | 17 ++--------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/FileSender.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/FileSender.java index 5928c33dbb3a..4bc67276113f 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/FileSender.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/FileSender.java @@ -43,14 +43,14 @@ class FileSender implements ChunkedInput private byte[] nextBytes; private State state = PRE_INIT; - FileSender( StoreResource resource ) throws IOException + FileSender( StoreResource resource ) { this.resource = resource; this.byteBuffer = ByteBuffer.allocateDirect( MAX_SIZE ); } @Override - public boolean isEndOfInput() throws Exception + public boolean isEndOfInput() { return state == FINISHED; } @@ -58,7 +58,11 @@ public boolean isEndOfInput() throws Exception @Override public void close() throws Exception { - resource.close(); + if ( channel != null ) + { + channel.close(); + channel = null; + } } @Override diff --git a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StoreResource.java b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StoreResource.java index 01d628586a08..338e7751838b 100644 --- a/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StoreResource.java +++ b/enterprise/causal-clustering/src/main/java/org/neo4j/causalclustering/catchup/storecopy/StoreResource.java @@ -19,7 +19,6 @@ */ package org.neo4j.causalclustering.catchup.storecopy; -import java.io.Closeable; import java.io.File; import java.io.IOException; import java.nio.channels.ReadableByteChannel; @@ -30,7 +29,7 @@ import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PagedFile; -class StoreResource implements Closeable +class StoreResource { private final File file; private final String path; @@ -38,8 +37,6 @@ class StoreResource implements Closeable private final PageCache pageCache; private final FileSystemAbstraction fs; - private ReadableByteChannel channel; - StoreResource( File file, String relativePath, int recordSize, PageCache pageCache, FileSystemAbstraction fs ) { this.file = file; @@ -66,16 +63,6 @@ ReadableByteChannel open() throws IOException return fs.open( file, "r" ); } - @Override - public void close() throws IOException - { - if ( channel != null ) - { - channel.close(); - channel = null; - } - } - public String path() { return path; @@ -110,6 +97,6 @@ public int hashCode() @Override public String toString() { - return "StoreResource{" + "path='" + path + '\'' + ", channel=" + channel + ", recordSize=" + recordSize + '}'; + return "StoreResource{" + "path='" + path + '\'' + ", recordSize=" + recordSize + '}'; } }