Do I need to set comparator with each transaction of nested calls ?
Closed this issue · 1 comments
unoexperto commented
Let's say I have
- merge method that schematically looks like below.
- two databases. One with actual data and another with metadata.
Schematically code looks like this
def getObject(id: Int, txnParent: Transaction): ValueType = {
val txn = env.createTransaction(txnParent, true)
dbRaw.setComparator(txn, rawComparator)
....
}
def deleteObject(id: Int, txnParent: Transaction): Unit = {
val txn = env.createTransaction(txnParent)
dbRaw.setComparator(txn, rawComparator)
....
}
def saveObject(id: Int, value: ValueType, txnParent: Transaction): Unit = {
val txn = env.createTransaction(txnParent)
dbRaw.setComparator(txn, rawComparator)
....
}
def getMeta(id: Int, txnParent: Transaction): MetaType = {
val txn = env.createTransaction(txnParent, true)
dbMeta.setComparator(txn, metaComparator)
....
}
def deleteMeta(id: Int, txnParent: Transaction): Unit = {
val txn = env.createTransaction(txnParent)
dbMeta.setComparator(txn, metaComparator)
....
}
def saveMeta(id: Int, value: ValueType, txnParent: Transaction): Unit = {
val txn = env.createTransaction(txnParent)
dbMeta.setComparator(txn, metaComparator)
....
}
def mergeObjects(idOld: Int, idTarget: Int): Unit = {
val txn = env.createWriteTransaction()
dbMeta.setComparator(txn, metaComparator)
dbRaw.setComparator(txn, rawComparator)
val objOld = getObject(idOld, txn)
val objTarget = getObject(idTarget, txn)
val metaOld = getMeta(idOld, txn)
val metaTarget = getMeta(idTarget, txn)
deleteObject(idOld, txn)
deleteMeta(idOld, txn)
// do something with objects and save merged ones
saveObject(idTarget, mergedObj, txn)
saveMeta(idTarget, mergedMeta, txn)
txn.close()
}
I have two questions
- Do I need to set comparators in nested calls ?
- Can I share parent transaction accross databases ?
Thanks!
krisskross commented
- Have not tested but is suspect that the comparator is valid for a child tx also. Give it a try or read the LMDB docs.
- Yes.