in entity-store/src/main/kotlin/jetbrains/exodus/entitystore/PersistentEntityStoreRefactorings.kt [177:238]
override fun execute(tx: StoreTransaction) {
val txn = tx as PersistentStoreTransaction
val entityTypeId = store.getEntityTypeId(txn, entityType, false)
var links = store.getLinksTable(txn, entityTypeId)
var allLinksIndex = links.allLinksIndex
val envTxn = txn.environmentTransaction
if (allLinksIndex.getStore().count(envTxn) > 0) {
logger.warn("Refactoring creating null-value link indices looped for [$entityType]")
envTxn.environment.truncateStore(allLinksIndex.getStore().name, envTxn)
store.linksTables.remove(entityTypeId)
links = store.getLinksTable(txn, entityTypeId)
allLinksIndex = links.allLinksIndex
}
val readonlySnapshot = envTxn.readonlySnapshot
try {
val cursor = links.getSecondIndexCursor(readonlySnapshot)
val total = links.getSecondaryCount(readonlySnapshot)
var done: Long = 0
var prevLinkId = -1
val idSet = PersistentLong23TreeSet().beginWrite()
val format = "done %4.1f%% for $entityType"
while (cursor.next) {
val linkKey = PropertyKey.entryToPropertyKey(cursor.value)
val linkId = linkKey.propertyId
val entityLocalId = linkKey.entityLocalId
if (prevLinkId != linkId) {
if (prevLinkId == -1) {
prevLinkId = linkId
} else {
if (linkId < prevLinkId) {
throw IllegalStateException("Unsorted index")
}
done = dumpSetAndFlush(
format,
allLinksIndex,
txn,
total.toDouble(),
done,
prevLinkId,
idSet
)
prevLinkId = linkId
}
}
idSet.add(entityLocalId)
}
if (prevLinkId != -1) {
dumpSetAndFlush(
format,
allLinksIndex,
txn,
total.toDouble(),
done,
prevLinkId,
idSet
)
}
cursor.close()
} finally {
readonlySnapshot.abort()
}
}