Skip to content

Commit

Permalink
Fix leaking resource in StoreResource that prevented deletion of file…
Browse files Browse the repository at this point in the history
…s during tests
  • Loading branch information
klaren committed Apr 9, 2018
1 parent 9db0c01 commit bf22612
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Expand Up @@ -43,22 +43,26 @@ class FileSender implements ChunkedInput<FileChunk>
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;
}

@Override
public void close() throws Exception
{
resource.close();
if ( channel != null )
{
channel.close();
channel = null;
}
}

@Override
Expand Down
Expand Up @@ -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;
Expand All @@ -30,16 +29,14 @@
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;
private final int recordSize;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 + '}';
}
}

0 comments on commit bf22612

Please sign in to comment.