Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow read queries to run on Pending machines
Before this change in HA when switching to pending the Locks delegate would have set to null, which prevents to create any transactions. Indeed, at transaction creation time we create a lock client through the Locks for such transaction. Basically failing all transaction creation. This commit changes the Locks to be a ReadOnlyLocks when switching to pending. Such Locks allows for creation of ReadOnlyClient which fails all possible lock acquisition, i.e., write transaction. In such a way read transaction can execute on machine in pending state. It also improves the AbstractComponentSwitcher to be less racy by switching directly from old delegate to new delegate, without setting the delegate to null in between those 2 steps.
- Loading branch information
1 parent
839b8f2
commit 9603a65
Showing
9 changed files
with
209 additions
and
69 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
community/kernel/src/main/java/org/neo4j/kernel/impl/locking/ReadOnlyLocks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "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.locking; | ||
|
||
import org.neo4j.storageengine.api.lock.AcquireLockTimeoutException; | ||
import org.neo4j.storageengine.api.lock.ResourceType; | ||
|
||
public class ReadOnlyLocks implements Locks | ||
{ | ||
private static final ReadOnlyClient READ_ONLY_CLIENT = new ReadOnlyClient(); | ||
|
||
@Override | ||
public Client newClient() | ||
{ | ||
return READ_ONLY_CLIENT; | ||
} | ||
|
||
@Override | ||
public void accept( Visitor visitor ) | ||
{ | ||
} | ||
|
||
@Override | ||
public void close() | ||
{ | ||
} | ||
|
||
private static class ReadOnlyClient extends NoOpClient | ||
{ | ||
@Override | ||
public void acquireShared( ResourceType resourceType, long... resourceIds ) throws AcquireLockTimeoutException | ||
{ | ||
fail(); | ||
} | ||
|
||
@Override | ||
public void acquireExclusive( ResourceType resourceType, long... resourceIds ) throws AcquireLockTimeoutException | ||
{ | ||
fail(); | ||
} | ||
|
||
@Override | ||
public boolean tryExclusiveLock( ResourceType resourceType, long resourceId ) | ||
{ | ||
fail(); | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean trySharedLock( ResourceType resourceType, long resourceId ) | ||
{ | ||
fail(); | ||
return false; | ||
} | ||
|
||
@Override | ||
public void releaseShared( ResourceType resourceType, long resourceId ) | ||
{ | ||
fail(); | ||
} | ||
|
||
@Override | ||
public void releaseExclusive( ResourceType resourceType, long resourceId ) | ||
{ | ||
fail(); | ||
} | ||
|
||
private void fail() | ||
{ | ||
throw new IllegalStateException( "Cannot acquire locks in read only mode" ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.