Skip to content

Commit 69dc452

Browse files
committed
fix(mps-sync-plugin): several fixes after trying to import MPS-extensions
1 parent 774bcc3 commit 69dc452

File tree

16 files changed

+177
-61
lines changed

16 files changed

+177
-61
lines changed

datastructures/src/commonMain/kotlin/org/modelix/datastructures/btree/BTreeNode.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.modelix.datastructures.btree
33
import org.modelix.datastructures.objects.IObjectData
44
import org.modelix.datastructures.objects.IObjectDeserializer
55
import org.modelix.datastructures.objects.IObjectReferenceFactory
6+
import org.modelix.datastructures.objects.Object
7+
import org.modelix.datastructures.objects.getDescendantsAndSelf
68
import org.modelix.datastructures.serialization.SerializationSeparators
79
import org.modelix.streams.IStream
810

@@ -33,6 +35,11 @@ sealed class BTreeNode<K, V> : IObjectData {
3335
fun splitIfNecessary(): Replacement<K, V> = if (isOverfilled()) split() else Replacement.Single(this)
3436
abstract fun mergeWithSibling(knownSeparator: K, right: BTreeNode<K, V>): BTreeNode<K, V>
3537

38+
override fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>> {
39+
// TODO performance
40+
return self.getDescendantsAndSelf()
41+
}
42+
3643
class Deserializer<K, V>(val config: BTreeConfig<K, V>) : IObjectDeserializer<BTreeNode<K, V>> {
3744
override fun deserialize(
3845
serialized: String,

datastructures/src/commonMain/kotlin/org/modelix/datastructures/objects/IObjectData.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ interface IObjectData {
1919
* Callers should compare the hashes of the old and new object before calling this method.
2020
* It assumes that the [oldObject] is different from this one and calling it anyway will result in a bigger diff.
2121
*/
22-
fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>> {
23-
requireDifferentHash(oldObject?.data)
24-
return self.getDescendantsAndSelf()
25-
}
22+
fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>>
2623
}
2724

2825
@Deprecated("Just don't use it and assume they are different")

datastructures/src/commonMain/kotlin/org/modelix/datastructures/patricia/PatriciaNode.kt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.modelix.datastructures.objects.IObjectGraph
1212
import org.modelix.datastructures.objects.IObjectReferenceFactory
1313
import org.modelix.datastructures.objects.Object
1414
import org.modelix.datastructures.objects.ObjectReference
15+
import org.modelix.datastructures.objects.asObject
16+
import org.modelix.datastructures.objects.getDescendantsAndSelf
1517
import org.modelix.datastructures.objects.getHashString
1618
import org.modelix.datastructures.objects.upcast
1719
import org.modelix.datastructures.serialization.SplitJoinSerializer
@@ -315,6 +317,60 @@ data class PatriciaNode<K, V : Any>(
315317
}
316318
}
317319

320+
override fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>> {
321+
return objectDiff(self, oldObject, "")
322+
}
323+
324+
fun objectDiff(self: Object<*>, oldObject: Object<*>?, path: CharSequence): IStream.Many<Object<*>> {
325+
if (oldObject == null) {
326+
return self.getDescendantsAndSelf()
327+
}
328+
self as Object<PatriciaNode<K, V>>
329+
oldObject as Object<PatriciaNode<K, V>>
330+
val oldNode: PatriciaNode<K, V> = oldObject.data as PatriciaNode<K, V>
331+
return if (ownPrefix == oldNode.ownPrefix) {
332+
val pathForChildren = path + ownPrefix
333+
val matchingChildren = if (firstChars == oldNode.firstChars) {
334+
children.zip(oldNode.children)
335+
} else {
336+
val newChildren = firstChars.asSequence().zip(children.asSequence()).toMap()
337+
val oldChildren = oldNode.firstChars.asSequence().zip(oldNode.children.asSequence()).toMap()
338+
val allFirstChars = newChildren.keys.plus(oldChildren.keys).distinct()
339+
allFirstChars.map { newChildren[it] to oldChildren[it] }
340+
}
341+
val changesFromChildren = IStream.many(matchingChildren).flatMap { (newChildRef, oldChildRef) ->
342+
if (newChildRef == null) {
343+
IStream.empty()
344+
} else {
345+
if (oldChildRef == null) {
346+
newChildRef.resolve().flatMap { it.getDescendantsAndSelf() }
347+
} else {
348+
if (newChildRef.getHash() == oldChildRef.getHash()) {
349+
IStream.empty()
350+
} else {
351+
newChildRef.resolve().zipWith(oldChildRef.resolve()) { newChild, oldChild ->
352+
newChild.data.objectDiff(newChild, oldChild, pathForChildren)
353+
}.flatten()
354+
}
355+
}
356+
}
357+
}
358+
359+
IStream.of(self) + changesFromChildren
360+
} else {
361+
val commonPrefix = ownPrefix.commonPrefixWith(oldNode.ownPrefix)
362+
self.split(commonPrefix).let {
363+
it.data.objectDiff(it, oldObject.split(commonPrefix), path).filter { it.graph == config.graph }
364+
}
365+
}
366+
}
367+
368+
private fun <K, V : Any> Object<PatriciaNode<K, V>>.split(commonPrefix: CharSequence): Object<PatriciaNode<K, V>> {
369+
val splitted = data.split(commonPrefix)
370+
if (splitted === data) return this
371+
return splitted.asObject(IObjectGraph.FREE_FLOATING)
372+
}
373+
318374
class Deserializer<K, V : Any>(val config: (IObjectGraph) -> PatriciaTrieConfig<K, V>) : IObjectDeserializer<PatriciaNode<K, V>> {
319375
constructor(config: PatriciaTrieConfig<K, V>) : this({ config })
320376
override fun deserialize(

model-datastructure/src/commonMain/kotlin/org/modelix/datastructures/model/IdTranslatingModelTree.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,18 @@ abstract class IdTranslatingModelTree<ExternalId, InternalId>(val tree: IGeneric
176176

177177
@JvmName("withIdTranslationToInt64")
178178
fun IGenericModelTree<INodeReference>.withIdTranslation(): IGenericModelTree<Long> {
179-
return NodeReferenceAsLongModelTree(this)
179+
return when (this) {
180+
is LongAsNodeReferenceModelTree -> this.tree
181+
else -> NodeReferenceAsLongModelTree(this)
182+
}
180183
}
181184

182185
@JvmName("withIdTranslationToNodeReferences")
183186
fun IGenericModelTree<Long>.withIdTranslation(): IGenericModelTree<INodeReference> {
184-
return LongAsNodeReferenceModelTree(this)
187+
return when (this) {
188+
is NodeReferenceAsLongModelTree -> this.tree
189+
else -> LongAsNodeReferenceModelTree(this)
190+
}
185191
}
186192

187193
fun INodeReference.extractInt64Id(expectedTree: TreeId): Long {

model-datastructure/src/commonMain/kotlin/org/modelix/datastructures/model/NodeObjectData.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.modelix.datastructures.objects.IObjectData
99
import org.modelix.datastructures.objects.IObjectDeserializer
1010
import org.modelix.datastructures.objects.IObjectReferenceFactory
1111
import org.modelix.datastructures.objects.LongDataTypeConfiguration
12+
import org.modelix.datastructures.objects.Object
1213
import org.modelix.datastructures.objects.ObjectReference
1314
import org.modelix.datastructures.objects.asKSerializer
1415
import org.modelix.datastructures.serialization.SplitJoinFormat
@@ -23,6 +24,7 @@ import org.modelix.model.api.IReadableNode
2324
import org.modelix.model.api.IReferenceLinkReference
2425
import org.modelix.model.api.NullChildLinkReference
2526
import org.modelix.model.api.meta.NullConcept
27+
import org.modelix.streams.IStream
2628

2729
@Serializable
2830
data class NodeObjectData<NodeId>(
@@ -109,6 +111,10 @@ data class NodeObjectData<NodeId>(
109111
return copy(children = children.filterNot { deserializer!!.nodeIdTypeConfig.equal(it, childId) })
110112
}
111113

114+
override fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>> {
115+
return IStream.of(self)
116+
}
117+
112118
class Deserializer<NodeId>(
113119
val nodeIdTypeConfig: IDataTypeConfiguration<NodeId>,
114120
val treeId: TreeId,

model-datastructure/src/commonMain/kotlin/org/modelix/model/mutable/VersionedModelTree.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,18 @@ class VersionedModelTree(
171171
override fun mutate(parameters: MutationParameters<INodeReference>) {
172172
when (parameters) {
173173
is MutationParameters.AddNew<INodeReference> -> {
174-
apply(
175-
AddNewChildrenOp(
176-
position = PositionInRole(parameters.nodeId, parameters.role, parameters.index),
177-
childIdsAndConcepts = parameters.newIdAndConcept.toList(),
178-
),
179-
)
174+
// split operation into smaller chunks to avoid large operation objects
175+
var indexOffset = 0
176+
for (chunk in parameters.newIdAndConcept.asSequence().chunked(100)) {
177+
val index = if (parameters.index >= 0) parameters.index + indexOffset else parameters.index
178+
apply(
179+
AddNewChildrenOp(
180+
position = PositionInRole(parameters.nodeId, parameters.role, index),
181+
childIdsAndConcepts = chunk,
182+
),
183+
)
184+
indexOffset += chunk.size
185+
}
180186
}
181187
is MutationParameters.Move<INodeReference> -> {
182188
val targetPosition = PositionInRole(parameters.nodeId, parameters.role, parameters.index)

model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/CPNode.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.modelix.model.persistent
33
import org.modelix.datastructures.objects.IObjectData
44
import org.modelix.datastructures.objects.IObjectDeserializer
55
import org.modelix.datastructures.objects.IObjectReferenceFactory
6+
import org.modelix.datastructures.objects.Object
67
import org.modelix.datastructures.objects.ObjectReference
78
import org.modelix.model.lazy.COWArrays.copy
89
import org.modelix.model.lazy.COWArrays.insert
@@ -14,6 +15,7 @@ import org.modelix.model.persistent.SerializationUtil.escape
1415
import org.modelix.model.persistent.SerializationUtil.longFromHex
1516
import org.modelix.model.persistent.SerializationUtil.longToHex
1617
import org.modelix.model.persistent.SerializationUtil.unescape
18+
import org.modelix.streams.IStream
1719
import kotlin.jvm.JvmStatic
1820

1921
class CPNode(
@@ -52,6 +54,10 @@ class CPNode(
5254
return sb.toString()
5355
}
5456

57+
override fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>> {
58+
return IStream.of(self)
59+
}
60+
5561
fun getChildrenIds(): Iterable<Long> {
5662
return Iterable { childrenIds.iterator() }
5763
}

model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/CPVersion.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.modelix.datastructures.hamt.HamtNode
44
import org.modelix.datastructures.objects.IObjectData
55
import org.modelix.datastructures.objects.IObjectDeserializer
66
import org.modelix.datastructures.objects.IObjectReferenceFactory
7+
import org.modelix.datastructures.objects.Object
78
import org.modelix.datastructures.objects.ObjectReference
89
import org.modelix.datastructures.objects.getHashString
910
import org.modelix.datastructures.patricia.PatriciaNode
@@ -14,6 +15,7 @@ import org.modelix.model.persistent.SerializationUtil.escape
1415
import org.modelix.model.persistent.SerializationUtil.longFromHex
1516
import org.modelix.model.persistent.SerializationUtil.longToHex
1617
import org.modelix.model.persistent.SerializationUtil.unescape
18+
import org.modelix.streams.IStream
1719

1820
data class CPVersion(
1921
val id: Long,
@@ -230,4 +232,8 @@ data class CPVersion(
230232
originalVersion = originalVersion?.asUnloaded(),
231233
)
232234
}
235+
236+
override fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>> {
237+
throw UnsupportedOperationException("CLVersion.diff")
238+
}
233239
}

model-datastructure/src/commonMain/kotlin/org/modelix/model/persistent/OperationsList.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package org.modelix.model.persistent
33
import org.modelix.datastructures.objects.IObjectData
44
import org.modelix.datastructures.objects.IObjectDeserializer
55
import org.modelix.datastructures.objects.IObjectReferenceFactory
6+
import org.modelix.datastructures.objects.Object
67
import org.modelix.datastructures.objects.ObjectReference
8+
import org.modelix.datastructures.objects.getDescendantsAndSelf
79
import org.modelix.datastructures.objects.getHashString
810
import org.modelix.model.operations.IOperation
911
import org.modelix.streams.IStream
@@ -44,6 +46,10 @@ abstract class OperationsList() : IObjectData {
4446
}
4547

4648
abstract fun getOperations(): IStream.Many<IOperation>
49+
50+
override fun objectDiff(self: Object<*>, oldObject: Object<*>?): IStream.Many<Object<*>> {
51+
return self.getDescendantsAndSelf()
52+
}
4753
}
4854

4955
class LargeOperationsList(val subLists: Array<out ObjectReference<OperationsList>>) : OperationsList() {

model-server/src/main/resources/org/modelix/model/server/store/ignite.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@
4141
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
4242
<property name="dataStorageConfiguration">
4343
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
44+
<property name="pageSize" value="16384" />
4445
<property name="defaultDataRegionConfiguration">
4546
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
4647
<property name="maxSize" value="${ignite.cache.size}"/>
4748
<property name="pageEvictionMode" value="RANDOM_LRU" />
48-
<property name="emptyPagesPoolSize" value="2000" />
49+
<property name="emptyPagesPoolSize" value="630" />
50+
<property name="evictionThreshold" value="0.8" />
4951
</bean>
5052
</property>
5153
</bean>

0 commit comments

Comments
 (0)