Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue YTDB 226 - YTDB upgrade #235

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun shouldApplyDokka(project: Project): Boolean {
}

tasks.wrapper {
gradleVersion = "8.5"
gradleVersion = "8.12"
}

defaultTasks("assemble")
Expand All @@ -64,7 +64,7 @@ nexusStaging {
allprojects {
repositories {
mavenCentral()
maven { url = uri("https://packages.jetbrains.team/maven/p/xodus/orientdb-daily") }
maven { url = uri("https://packages.jetbrains.team/maven/p/xodus/youtrackdb-daily") }
}
}

Expand Down Expand Up @@ -158,7 +158,7 @@ subprojects {
isFailOnError = false
options.quiet()
(options as CoreJavadocOptions).addStringOption("Xdoclint:none", "-quiet")
(options as CoreJavadocOptions).addStringOption("source", 17.toString())
(options as CoreJavadocOptions).addStringOption("source", 21.toString())
}


Expand Down Expand Up @@ -186,7 +186,7 @@ subprojects {
withSourcesJar()

toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand Down
2 changes: 1 addition & 1 deletion entity-store/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
api(project(":xodus-openAPI"))
api("com.orientechnologies:orientdb-core:4.0.0-20241126.153402-203")
api("io.youtrackdb:youtrackdb-core:1.0.0-20250110.154816-3")

implementation(project(":xodus-utils"))
implementation(project(":xodus-environment"))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/
package jetbrains.exodus.entitystore.orientdb

import com.orientechnologies.orient.core.db.record.OTrackedSet
import com.jetbrains.youtrack.db.internal.core.db.record.TrackedSet

class OComparableSet<E>(val source: MutableSet<E>) : MutableSet<E> by source, Comparable<MutableSet<E>> {

val isDirty: Boolean
get() {
return if (source is OTrackedSet) {
return if (source is TrackedSet) {
source.isTransactionModified
} else {
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/
package jetbrains.exodus.entitystore.orientdb

import com.orientechnologies.orient.core.command.OCommandOutputListener
import com.orientechnologies.orient.core.db.ODatabaseSessionInternal
import com.orientechnologies.orient.core.db.OrientDB
import com.orientechnologies.orient.core.db.tool.ODatabaseExport
import com.orientechnologies.orient.core.db.tool.ODatabaseImport
import com.jetbrains.youtrack.db.api.YouTrackDB
import com.jetbrains.youtrack.db.internal.core.command.CommandOutputListener
import com.jetbrains.youtrack.db.internal.core.db.DatabaseSessionInternal
import com.jetbrains.youtrack.db.internal.core.db.tool.DatabaseExport
import com.jetbrains.youtrack.db.internal.core.db.tool.DatabaseImport
import mu.KLogging
import java.io.File

class ODatabaseCompacter(
private val db: OrientDB,
private val db: YouTrackDB,
private val dbProvider: ODatabaseProvider,
private val config: ODatabaseConfig
) {
Expand All @@ -34,11 +34,11 @@ class ODatabaseCompacter(
val databaseLocation = File(dbProvider.databaseLocation)
val backupFile = File(databaseLocation, "temp${System.currentTimeMillis()}")
backupFile.parentFile.mkdirs()
val listener = OCommandOutputListener { iText -> logger.info("Compacting database: $iText") }
val listener = CommandOutputListener { iText -> logger.info("Compacting database: $iText") }

dbProvider.withSession { session ->
val exporter = ODatabaseExport(
session as ODatabaseSessionInternal,
val exporter = DatabaseExport(
session as DatabaseSessionInternal,
backupFile.outputStream(),
listener
)
Expand All @@ -49,12 +49,13 @@ class ODatabaseCompacter(
logger.info("Dropping existing database...")
db.drop(config.databaseName)

db.create(config.databaseName, config.databaseType)
db.create(config.databaseName, config.databaseType,
config.connectionConfig.userName, config.connectionConfig.password, "admin")

dbProvider.withSession { session ->
logger.info("Importing database from dump")
val importer = ODatabaseImport(
session as ODatabaseSessionInternal,
val importer = DatabaseImport(
session as DatabaseSessionInternal,
backupFile.inputStream(),
listener
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package jetbrains.exodus.entitystore.orientdb

import com.orientechnologies.orient.core.db.ODatabaseType
import com.orientechnologies.orient.core.db.OrientDBConfigBuilder
import com.jetbrains.youtrack.db.api.DatabaseType
import com.jetbrains.youtrack.db.api.config.YouTrackDBConfigBuilder
import kotlin.math.min

class ODatabaseConfig private constructor(
val connectionConfig: ODatabaseConnectionConfig,
val databaseName: String,
val databaseType: ODatabaseType,
val databaseType: DatabaseType,
val closeAfterDelayTimeout: Int,
val cipherKey: ByteArray?,
val closeDatabaseInDbProvider: Boolean,
val tweakConfig: OrientDBConfigBuilder.() -> Unit
val tweakConfig: YouTrackDBConfigBuilder.() -> Unit
) {
companion object {
fun builder(): Builder {
Expand All @@ -39,17 +39,17 @@ class ODatabaseConfig private constructor(
class Builder internal constructor() {
private lateinit var connectionConfig: ODatabaseConnectionConfig
private var databaseName: String = ""
private var databaseType: ODatabaseType? = null
private var databaseType: DatabaseType? = null
private var closeAfterDelayTimeout: Int? = null
private var cipherKey: ByteArray? = null
private var closeDatabaseInDbProvider = true
private var tweakConfig: OrientDBConfigBuilder.() -> Unit = {}
private var tweakConfig: YouTrackDBConfigBuilder.() -> Unit = {}

fun withDatabaseName(databaseName: String) = apply { this.databaseName = databaseName }
fun withConnectionConfig(connectionConfig: ODatabaseConnectionConfig) =
apply { this.connectionConfig = connectionConfig }

fun withDatabaseType(databaseType: ODatabaseType) = apply { this.databaseType = databaseType }
fun withDatabaseType(databaseType: DatabaseType) = apply { this.databaseType = databaseType }
fun withCloseAfterDelayTimeout(closeAfterDelayTimeout: Int) =
apply { this.closeAfterDelayTimeout = closeAfterDelayTimeout }

Expand All @@ -63,7 +63,7 @@ class ODatabaseConfig private constructor(
cipherKey = hexStringToByteArray(key.substring(0, min(16 * 2, key.length))) + longToByteArray(IV)
}

fun tweakConfig(tweakConfig: OrientDBConfigBuilder.() -> Unit) = apply { this.tweakConfig = tweakConfig }
fun tweakConfig(tweakConfig: YouTrackDBConfigBuilder.() -> Unit) = apply { this.tweakConfig = tweakConfig }

fun build() = ODatabaseConfig(
connectionConfig, databaseName, databaseType ?: connectionConfig.databaseType, closeAfterDelayTimeout ?: connectionConfig.closeAfterDelayTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package jetbrains.exodus.entitystore.orientdb

import com.orientechnologies.orient.core.db.ODatabaseType
import com.jetbrains.youtrack.db.api.DatabaseType

class ODatabaseConnectionConfig private constructor(
val databaseRoot: String,
val userName: String,
val password: String,
val databaseType: ODatabaseType,
val databaseType: DatabaseType,
val closeAfterDelayTimeout: Int
) {
companion object {
Expand All @@ -35,13 +35,13 @@ class ODatabaseConnectionConfig private constructor(
private lateinit var databaseRoot: String
private lateinit var userName: String
private lateinit var password: String
private var databaseType: ODatabaseType = ODatabaseType.MEMORY
private var databaseType: DatabaseType = DatabaseType.MEMORY
private var closeAfterDelayTimeout: Int = 10

fun withDatabaseRoot(databaseURL: String) = apply { this.databaseRoot = databaseURL }
fun withUserName(userName: String) = apply { this.userName = userName }
fun withPassword(password: String) = apply { this.password = password }
fun withDatabaseType(databaseType: ODatabaseType) = apply { this.databaseType = databaseType }
fun withDatabaseType(databaseType: DatabaseType) = apply { this.databaseType = databaseType }
fun withCloseAfterDelayTimeout(closeAfterDelayTimeout: Int) =
apply { this.closeAfterDelayTimeout = closeAfterDelayTimeout }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
*/
package jetbrains.exodus.entitystore.orientdb

import com.orientechnologies.orient.core.config.OGlobalConfiguration
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal
import com.orientechnologies.orient.core.db.ODatabaseSession
import com.orientechnologies.orient.core.db.OrientDB
import com.orientechnologies.orient.core.db.OrientDBConfigBuilder
import com.jetbrains.youtrack.db.api.DatabaseSession
import com.jetbrains.youtrack.db.api.YouTrackDB
import com.jetbrains.youtrack.db.api.YourTracks
import com.jetbrains.youtrack.db.api.config.GlobalConfiguration
import com.jetbrains.youtrack.db.api.config.YouTrackDBConfig
import com.jetbrains.youtrack.db.api.exception.RecordDuplicatedException
import com.jetbrains.youtrack.db.internal.core.db.DatabaseRecordThreadLocal

interface ODatabaseProvider {
val databaseLocation: String
fun acquireSession(): ODatabaseSession
fun acquireSession(): DatabaseSession

/**
* If there is a session on the current thread, create a new session, executes the action in it,
Expand All @@ -33,8 +35,8 @@ interface ODatabaseProvider {
* and do not hesitate to invite people to review your code.
*/
fun <T> executeInASeparateSession(
currentSession: ODatabaseSession,
action: (ODatabaseSession) -> T
currentSession: DatabaseSession,
action: (DatabaseSession) -> T
): T

/**
Expand All @@ -46,18 +48,18 @@ interface ODatabaseProvider {
fun close()
}

fun <R> ODatabaseProvider.withSession(block: (ODatabaseSession) -> R): R {
fun <R> ODatabaseProvider.withSession(block: (DatabaseSession) -> R): R {
acquireSession().use { session ->
return block(session)
}
}

fun <R> ODatabaseProvider.withCurrentOrNewSession(
requireNoActiveTransaction: Boolean = false,
block: (ODatabaseSession) -> R
block: (DatabaseSession) -> R
): R {
return if (hasActiveSession()) {
val activeSession = ODatabaseSession.getActiveSession() as ODatabaseSession
val activeSession = DatabaseRecordThreadLocal.instance().getIfDefined() as DatabaseSession
if (requireNoActiveTransaction) {
activeSession.requireNoActiveTransaction()
}
Expand All @@ -69,15 +71,15 @@ fun <R> ODatabaseProvider.withCurrentOrNewSession(
}
}

internal fun ODatabaseSession.hasActiveTransaction(): Boolean {
internal fun DatabaseSession.hasActiveTransaction(): Boolean {
return isActiveOnCurrentThread && activeTxCount() > 0
}

internal fun ODatabaseSession.requireActiveTransaction() {
internal fun DatabaseSession.requireActiveTransaction() {
require(hasActiveTransaction()) { "No active transaction is found. Happy debugging, pal!" }
}

internal fun ODatabaseSession.requireNoActiveTransaction() {
internal fun DatabaseSession.requireNoActiveTransaction() {
assert(isActiveOnCurrentThread && activeTxCount() == 0) { "Active transaction is detected. Changes in the schema must not happen in a transaction." }
}

Expand All @@ -86,24 +88,28 @@ internal fun requireNoActiveSession() {
}

internal fun hasActiveSession(): Boolean {
val db = ODatabaseRecordThreadLocal.instance().getIfDefined()
val db = DatabaseRecordThreadLocal.instance().getIfDefined()
return db != null
}

fun initOrientDbServer(config: ODatabaseConnectionConfig): OrientDB {
val orientConfig = OrientDBConfigBuilder().apply {
addConfig(OGlobalConfiguration.AUTO_CLOSE_AFTER_DELAY, true)
addConfig(OGlobalConfiguration.AUTO_CLOSE_DELAY, config.closeAfterDelayTimeout)
addConfig(OGlobalConfiguration.NON_TX_READS_WARNING_MODE, "SILENT")
fun iniYouTrackDb(config: ODatabaseConnectionConfig): YouTrackDB {
val orientConfig = YouTrackDBConfig.builder().apply {
addGlobalConfigurationParameter(GlobalConfiguration.AUTO_CLOSE_AFTER_DELAY, true)
addGlobalConfigurationParameter(
GlobalConfiguration.AUTO_CLOSE_DELAY,
config.closeAfterDelayTimeout
)
addGlobalConfigurationParameter(GlobalConfiguration.NON_TX_READS_WARNING_MODE, "SILENT")
}.build()
require(config.userName.matches(Regex("^[a-zA-Z0-9]*$")))
val dbType = config.databaseType.name.lowercase()
val db = OrientDB("$dbType:${config.databaseRoot}", orientConfig)
val db = YourTracks.embedded(config.databaseRoot, orientConfig)

try {
db.execute("create system user ${config.userName} identified by :pass role root", mapOf(
"pass" to config.password,
))
} catch (_: com.orientechnologies.orient.core.storage.ORecordDuplicatedException) {
} catch (_: RecordDuplicatedException) {
}

return db
}
Loading
Loading