Skip to content

Commit 7409913

Browse files
committed
fix(model-server): writing to a branch using the v1 API failed
Ignite doesn't support nested transactions. Starting a transaction from inside a transaction throws the following exception: java.lang.IllegalStateException: Failed to start new transaction (current thread already has a transaction): ... at org.apache.ignite.internal.processors.cache.transactions.IgniteTransactionsImpl.txStart0(IgniteTransactionsImpl.java:184) at org.apache.ignite.internal.processors.cache.transactions.IgniteTransactionsImpl.txStart(IgniteTransactionsImpl.java:70) at org.modelix.model.server.store.IgniteStoreClient.runTransaction(IgniteStoreClient.kt:139) at org.modelix.model.server.handlers.RepositoriesManager.mergeChanges(RepositoriesManager.kt:151) at org.modelix.model.server.handlers.KeyValueLikeModelServer$putEntries$1.invoke(KeyValueLikeModelServer.kt:323) at org.modelix.model.server.handlers.KeyValueLikeModelServer$putEntries$1.invoke(KeyValueLikeModelServer.kt:316) at org.modelix.model.server.store.IgniteStoreClient.runTransaction(IgniteStoreClient.kt:140) at org.modelix.model.server.handlers.KeyValueLikeModelServer.putEntries(KeyValueLikeModelServer.kt:316) at org.modelix.model.server.handlers.KeyValueLikeModelServer$modelServerModule$1$3$7.invokeSuspend(KeyValueLikeModelServer.kt:163) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda$1$lambda$0(NettyApplicationEngine.kt:296) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) skip-lint
1 parent 137f8d7 commit 7409913

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

model-server/src/main/kotlin/org/modelix/model/server/store/IgniteStoreClient.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,15 @@ class IgniteStoreClient(jdbcConfFile: File?) : IStoreClient {
136136

137137
override fun <T> runTransaction(body: () -> T): T {
138138
val transactions = ignite.transactions()
139-
transactions.txStart().use { tx ->
140-
val result = body()
141-
tx.commit()
142-
return result
139+
if (transactions.tx() == null) {
140+
transactions.txStart().use { tx ->
141+
val result = body()
142+
tx.commit()
143+
return result
144+
}
145+
} else {
146+
// already in a transaction
147+
return body()
143148
}
144149
}
145150

0 commit comments

Comments
 (0)