@@ -48,6 +48,7 @@ import org.modelix.model.server.api.v2.ImmutableObjectsStream
48
48
import org.modelix.model.server.api.v2.VersionDelta
49
49
import org.modelix.model.server.api.v2.VersionDeltaStream
50
50
import org.modelix.model.server.api.v2.VersionDeltaStreamV2
51
+ import org.modelix.model.server.store.RequiresTransaction
51
52
import org.modelix.model.server.store.StoreManager
52
53
import org.modelix.model.server.store.runReadIO
53
54
import org.modelix.model.server.store.runWriteIO
@@ -91,6 +92,7 @@ class ModelReplicationServer(
91
92
92
93
override suspend fun PipelineContext <Unit , ApplicationCall >.getRepositories () {
93
94
call.respondText(
95
+ @OptIn(RequiresTransaction ::class )
94
96
runRead { repositoriesManager.getRepositories() }
95
97
.filter { call.hasPermission(ModelServerPermissionSchema .repository(it).list) }
96
98
.joinToString(" \n " ) { it.id },
@@ -99,6 +101,7 @@ class ModelReplicationServer(
99
101
100
102
override suspend fun PipelineContext <Unit , ApplicationCall >.getRepositoryBranches (repository : String ) {
101
103
call.respondText(
104
+ @OptIn(RequiresTransaction ::class )
102
105
runRead { repositoriesManager.getBranchNames(repositoryId(repository)) }
103
106
.filter { call.hasPermission(ModelServerPermissionSchema .repository(repository).branch(it).list) }
104
107
.joinToString(" \n " ),
@@ -112,6 +115,8 @@ class ModelReplicationServer(
112
115
) {
113
116
checkPermission(ModelServerPermissionSchema .repository(repository).branch(branch).pull)
114
117
val branchRef = repositoryId(repository).getBranchReference(branch)
118
+
119
+ @OptIn(RequiresTransaction ::class )
115
120
val versionHash = runRead {
116
121
repositoriesManager.getVersionHash(branchRef) ? : throw BranchNotFoundException (branchRef)
117
122
}
@@ -125,7 +130,11 @@ class ModelReplicationServer(
125
130
) {
126
131
checkPermission(ModelServerPermissionSchema .repository(repository).branch(branch).pull)
127
132
val branchRef = repositoryId(repository).getBranchReference(branch)
128
- val versionHash = runRead { repositoriesManager.getVersionHash(branchRef) ? : throw BranchNotFoundException (branchRef) }
133
+
134
+ @OptIn(RequiresTransaction ::class )
135
+ val versionHash = runRead {
136
+ repositoriesManager.getVersionHash(branchRef) ? : throw BranchNotFoundException (branchRef)
137
+ }
129
138
call.respond(BranchV1 (branch, versionHash))
130
139
}
131
140
@@ -141,6 +150,7 @@ class ModelReplicationServer(
141
150
142
151
checkPermission(ModelServerPermissionSchema .repository(repositoryId).branch(branch).delete)
143
152
153
+ @OptIn(RequiresTransaction ::class )
144
154
runWrite {
145
155
if (! repositoriesManager.getBranchNames(repositoryId).contains(branch)) {
146
156
throw BranchNotFoundException (branch, repositoryId.id)
@@ -158,7 +168,11 @@ class ModelReplicationServer(
158
168
) {
159
169
checkPermission(ModelServerPermissionSchema .repository(repository).branch(branch).pull)
160
170
val branchRef = repositoryId(repository).getBranchReference(branch)
161
- val versionHash = runRead { repositoriesManager.getVersionHash(branchRef) ? : throw BranchNotFoundException (branchRef) }
171
+
172
+ @OptIn(RequiresTransaction ::class )
173
+ val versionHash = runRead {
174
+ repositoriesManager.getVersionHash(branchRef) ? : throw BranchNotFoundException (branchRef)
175
+ }
162
176
call.respondText(versionHash)
163
177
}
164
178
@@ -168,6 +182,7 @@ class ModelReplicationServer(
168
182
legacyGlobalStorage : Boolean? ,
169
183
) {
170
184
checkPermission(ModelServerPermissionSchema .repository(repository).create)
185
+ @OptIn(RequiresTransaction ::class )
171
186
val initialVersion = runWrite {
172
187
repositoriesManager.createRepository(
173
188
repositoryId(repository),
@@ -182,6 +197,7 @@ class ModelReplicationServer(
182
197
override suspend fun PipelineContext <Unit , ApplicationCall >.deleteRepository (repository : String ) {
183
198
checkPermission(ModelServerPermissionSchema .repository(repository).delete)
184
199
200
+ @OptIn(RequiresTransaction ::class )
185
201
val foundAndDeleted = runWrite {
186
202
repositoriesManager.removeRepository(repositoryId(repository))
187
203
}
@@ -200,7 +216,9 @@ class ModelReplicationServer(
200
216
val branchRef = repositoryId(repository).getBranchReference(branch)
201
217
val deltaFromClient = call.receive<VersionDelta >()
202
218
deltaFromClient.checkObjectHashes()
219
+ @OptIn(RequiresTransaction ::class ) // no transactions required for immutable store
203
220
repositoriesManager.getStoreClient(RepositoryId (repository), true ).putAll(deltaFromClient.getAllObjects())
221
+ @OptIn(RequiresTransaction ::class )
204
222
val mergedHash = runWrite {
205
223
repositoriesManager.mergeChanges(branchRef, deltaFromClient.versionHash)
206
224
}
@@ -228,6 +246,7 @@ class ModelReplicationServer(
228
246
}
229
247
230
248
val objects = withContext(Dispatchers .IO ) {
249
+ @OptIn(RequiresTransaction ::class ) // no transactions required for immutable store
231
250
repositoriesManager.getStoreClient(RepositoryId (repository), true ).getAll(keys)
232
251
}
233
252
@@ -271,6 +290,7 @@ class ModelReplicationServer(
271
290
) {
272
291
val branchRef = repositoryId(repository).getBranchReference(branchName)
273
292
checkPermission(ModelServerPermissionSchema .branch(branchRef).query)
293
+ @OptIn(RequiresTransaction ::class )
274
294
val version = runRead { repositoriesManager.getVersion(branchRef) ? : throw BranchNotFoundException (branchRef) }
275
295
LOG .trace(" Running query on {} @ {}" , branchRef, version)
276
296
val initialTree = version.getTree()
@@ -301,6 +321,7 @@ class ModelReplicationServer(
301
321
baseVersion = version,
302
322
operations = ops.map { it.getOriginalOp() }.toTypedArray(),
303
323
)
324
+ @OptIn(RequiresTransaction ::class )
304
325
runWrite {
305
326
repositoriesManager.mergeChanges(branchRef, newVersion.getContentHash())
306
327
}
@@ -343,6 +364,7 @@ class ModelReplicationServer(
343
364
}
344
365
345
366
withContext(Dispatchers .IO ) {
367
+ @OptIn(RequiresTransaction ::class ) // no transactions required for immutable store
346
368
repositoriesManager.getStoreClient(RepositoryId (repository), true ).putAll(entries, true )
347
369
}
348
370
call.respondText(" ${entries.size} objects received" )
@@ -354,6 +376,7 @@ class ModelReplicationServer(
354
376
lastKnown : String? ,
355
377
) {
356
378
checkPermission(ModelServerPermissionSchema .legacyGlobalObjects.read)
379
+ @OptIn(RequiresTransaction ::class )
357
380
if (runRead { stores.getGlobalStoreClient()[versionHash] } == null ) {
358
381
throw VersionNotFoundException (versionHash)
359
382
}
0 commit comments