-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue with last committed tx id in query planning
This issue could result in slaves never re-planing queries after a mode switch or even directly after the startup. It occurred because function that resolved last committed transaction id held a reference to a stale TransactionIdStore. TransactionIdStore is re-initialized after the NeoStoreDataSource restart which happens after mode switch in HA. Introduced LastCommittedTxIdProvider that is able to take last committed transaction id from the given GraphDatabaseService.
- Loading branch information
Max Sumrall
committed
Nov 23, 2015
1 parent
f023de1
commit dcef31c
Showing
12 changed files
with
147 additions
and
26 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
...ty/cypher/cypher/src/main/scala/org/neo4j/cypher/internal/LastCommittedTxIdProvider.scala
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,33 @@ | ||
/* | ||
* Copyright (c) 2002-2015 "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.cypher.internal | ||
|
||
import org.neo4j.graphdb.GraphDatabaseService | ||
import org.neo4j.kernel.GraphDatabaseAPI | ||
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore | ||
|
||
case class LastCommittedTxIdProvider(db: GraphDatabaseService) extends (() => Long) { | ||
|
||
override def apply(): Long = { | ||
val resolver = db.asInstanceOf[GraphDatabaseAPI].getDependencyResolver | ||
val txIdStore = resolver.resolveDependency(classOf[TransactionIdStore]) | ||
txIdStore.getLastCommittedTransactionId | ||
} | ||
} |
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
74 changes: 74 additions & 0 deletions
74
...ypher/cypher/src/test/scala/org/neo4j/cypher/internal/LastCommittedTxIdProviderTest.scala
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,74 @@ | ||
/* | ||
* Copyright (c) 2002-2015 "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.cypher.internal | ||
|
||
import org.neo4j.cypher.internal.commons.CypherFunSuite | ||
import org.neo4j.kernel.NeoStoreDataSource | ||
import org.neo4j.test.ImpermanentGraphDatabase | ||
import org.scalatest.BeforeAndAfterAll | ||
|
||
class LastCommittedTxIdProviderTest extends CypherFunSuite with BeforeAndAfterAll { | ||
|
||
var db: ImpermanentGraphDatabase = null | ||
var lastCommittedTxIdProvider: LastCommittedTxIdProvider = null | ||
|
||
override protected def beforeAll(): Unit = { | ||
db = new ImpermanentGraphDatabase() | ||
lastCommittedTxIdProvider = LastCommittedTxIdProvider(db) | ||
} | ||
|
||
override protected def afterAll(): Unit = db.shutdown() | ||
|
||
test("should return correct last committed tx id") { | ||
val startingTxId = lastCommittedTxIdProvider() | ||
|
||
(1 to 42).foreach(_ => createNode()) | ||
|
||
val endingTxId = lastCommittedTxIdProvider() | ||
endingTxId shouldBe (startingTxId + 42) | ||
} | ||
|
||
test("should return correct last committed tx id after datasource restart") { | ||
val startingTxId = lastCommittedTxIdProvider() | ||
|
||
restartDataSource() | ||
(1 to 42).foreach(_ => createNode()) | ||
|
||
val endingTxId = lastCommittedTxIdProvider() | ||
endingTxId shouldBe (startingTxId + 42) | ||
} | ||
|
||
private def createNode(): Unit = { | ||
val tx = db.beginTx() | ||
try { | ||
db.createNode() | ||
tx.success() | ||
} | ||
finally { | ||
tx.close() | ||
} | ||
} | ||
|
||
private def restartDataSource(): Unit = { | ||
val ds = db.getDependencyResolver.resolveDependency(classOf[NeoStoreDataSource]) | ||
ds.stop() | ||
ds.start() | ||
} | ||
} |