Skip to content

Commit

Permalink
core-edge: minor reader pool improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfurmanski authored and jimwebber committed Jul 14, 2016
1 parent ef9b7e7 commit 4187e20
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Expand Up @@ -36,7 +36,7 @@
// TODO: Prune stale readers with a recurring job. // TODO: Prune stale readers with a recurring job.
class ReaderPool class ReaderPool
{ {
private final ArrayList<Reader> pool; private ArrayList<Reader> pool;
private final int maxSize; private final int maxSize;
private final Log log; private final Log log;
private final FileNames fileNames; private final FileNames fileNames;
Expand Down Expand Up @@ -125,16 +125,23 @@ private void dispose( Reader reader )
} }
} }


synchronized void disposeAll() throws IOException synchronized void close() throws IOException
{ {
for ( Reader reader : pool ) for ( Reader reader : pool )
{ {
reader.close(); reader.close();
} }
pool.clear();
pool = null;
} }


public synchronized void prune( long version ) public synchronized void prune( long version )
{ {
if ( pool == null )
{
return;
}

Iterator<Reader> itr = pool.iterator(); Iterator<Reader> itr = pool.iterator();
while ( itr.hasNext() ) while ( itr.hasNext() )
{ {
Expand Down
Expand Up @@ -104,7 +104,7 @@ public synchronized void start() throws IOException, DamagedLogStorageException,
@Override @Override
public synchronized void stop() throws DisposedException, IOException public synchronized void stop() throws DisposedException, IOException
{ {
readerPool.disposeAll(); readerPool.close();
state.segments.close(); state.segments.close();
} }


Expand Down
Expand Up @@ -147,7 +147,7 @@ public void shouldDisposeAllReleasedReaders() throws Exception
pool.release( readerC ); pool.release( readerC );


// when // when
pool.disposeAll(); pool.close();


// then // then
verify( readerA ).close(); verify( readerA ).close();
Expand Down

0 comments on commit 4187e20

Please sign in to comment.