Commit 90794260 authored by Johan Svensson's avatar Johan Svensson
Browse files

Fixed bug that caused RWLock not to free up entries in txLockElementMap.

The mark flag is used to guard against creating multiple RWLocks for the same resource and has nothing to do with TxLockElement entries.

TxLockElement creation and removal is still safe since it is synchronized on the RWLock.
parent d802c37d
Showing with 75 additions and 9 deletions
+75 -9
......@@ -40,7 +40,6 @@ import org.neo4j.kernel.info.WaitingThread;
import static java.lang.Thread.currentThread;
import static java.lang.Thread.interrupted;
import static org.neo4j.kernel.impl.transaction.LockType.READ;
import static org.neo4j.kernel.impl.transaction.LockType.WRITE;
......@@ -214,10 +213,7 @@ class RWLock implements Visitor<LineLogger, RuntimeException>
tle.readCount--;
if ( tle.isFree() )
{
if ( !this.isMarked() )
{
txLockElementMap.remove( tx );
}
txLockElementMap.remove( tx );
ragManager.lockReleased( this, tx );
}
if ( waitingThreadList.size() > 0 )
......@@ -380,10 +376,7 @@ class RWLock implements Visitor<LineLogger, RuntimeException>
tle.writeCount--;
if ( tle.isFree() )
{
if ( !this.isMarked() )
{
txLockElementMap.remove( tx );
}
txLockElementMap.remove( tx );
ragManager.lockReleased( this, tx );
}
......@@ -580,4 +573,9 @@ class RWLock implements Visitor<LineLogger, RuntimeException>
}
return tle;
}
synchronized int getTxLockElementCount()
{
return txLockElementMap.size();
}
}
/**
* Copyright (c) 2002-2014 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.transaction;
import static org.mockito.Mockito.mock;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class RWLockLeakTest
{
@Test
public void assertWriteLockDoesNotLeakMemory() throws InterruptedException
{
final TransactionManager tm = mock( TransactionManager.class );
final RagManager ragManager = new RagManager( tm );
final Object resource = new Object();
final RWLock lock = new RWLock( resource, ragManager );
final Transaction tx1 = mock( Transaction.class );
lock.mark();
lock.acquireWriteLock( tx1 );
lock.mark();
assertEquals( 1, lock.getTxLockElementCount() );
lock.releaseWriteLock( tx1 );
assertEquals( 0, lock.getTxLockElementCount() );
}
@Test
public void assertReadLockDoesNotLeakMemory() throws InterruptedException
{
final TransactionManager tm = mock( TransactionManager.class );
final RagManager ragManager = new RagManager( tm );
final Object resource = new Object();
final RWLock lock = new RWLock( resource, ragManager );
final Transaction tx1 = mock( Transaction.class );
lock.mark();
lock.acquireReadLock( tx1 );
lock.mark();
assertEquals( 1, lock.getTxLockElementCount() );
lock.releaseReadLock( tx1 );
assertEquals( 0, lock.getTxLockElementCount() );
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment