use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class DBLockTest method nestedTwoLevelLock.
private void nestedTwoLevelLock(KeycloakSession session, DBLockProvider.Namespace lockTop, DBLockProvider.Namespace lockInner, Semaphore semaphore) {
DBLockProvider dbLock = new DBLockManager(session).getDBLock();
dbLock.waitForLock(lockTop);
try {
// create a new session to call the lock method with the inner namespace
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), sessionInner -> lock(sessionInner, lockInner, semaphore));
} finally {
dbLock.releaseLock();
}
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class DBLockTest method simpleLockTest.
@Test
public void simpleLockTest() throws Exception {
inComittedTransaction(1, (session, i) -> {
DBLockProvider dbLock = new DBLockManager(session).getDBLock();
dbLock.waitForLock(DBLockProvider.Namespace.DATABASE);
try {
Assert.assertEquals(DBLockProvider.Namespace.DATABASE, dbLock.getCurrentLock());
} finally {
dbLock.releaseLock();
}
Assert.assertNull(dbLock.getCurrentLock());
return null;
});
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class DBLockTest method lock.
private void lock(KeycloakSession session, DBLockProvider.Namespace lock, Semaphore semaphore) {
DBLockProvider dbLock = new DBLockManager(session).getDBLock();
dbLock.waitForLock(lock);
try {
semaphore.increase();
Thread.sleep(SLEEP_TIME_MILLIS);
semaphore.decrease();
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
} finally {
dbLock.releaseLock();
}
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class KeycloakApplication method startup.
protected void startup() {
KeycloakApplication.sessionFactory = createSessionFactory();
ExportImportManager[] exportImportManager = new ExportImportManager[1];
KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() {
@Override
public void run(KeycloakSession session) {
DBLockManager dbLockManager = new DBLockManager(session);
dbLockManager.checkForcedUnlock();
DBLockProvider dbLock = dbLockManager.getDBLock();
dbLock.waitForLock(DBLockProvider.Namespace.KEYCLOAK_BOOT);
try {
exportImportManager[0] = bootstrap();
} finally {
dbLock.releaseLock();
}
}
});
if (exportImportManager[0].isRunExport()) {
exportImportManager[0].runExport();
}
KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() {
@Override
public void run(KeycloakSession session) {
boolean shouldBootstrapAdmin = new ApplianceBootstrap(session).isNoMasterUser();
BOOTSTRAP_ADMIN_USER.set(shouldBootstrapAdmin);
}
});
sessionFactory.publish(new PostMigrationEvent());
setupScheduledTasks(sessionFactory);
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class QuarkusJpaConnectionProviderFactory method initSchema.
private void initSchema(KeycloakSession session) {
ExportImportManager exportImportManager = new ExportImportManager(session);
/*
* Migrate model is executed just in case following providers are "jpa".
* In Map Storage, there is an assumption that migrateModel is not needed.
*/
if ((Config.getProvider("realm") == null || "jpa".equals(Config.getProvider("realm"))) && (Config.getProvider("client") == null || "jpa".equals(Config.getProvider("client"))) && (Config.getProvider("clientScope") == null || "jpa".equals(Config.getProvider("clientScope")))) {
logger.debug("Calling migrateModel");
migrateModel(session);
}
DBLockManager dbLockManager = new DBLockManager(session);
dbLockManager.checkForcedUnlock();
DBLockProvider dbLock = dbLockManager.getDBLock();
dbLock.waitForLock(DBLockProvider.Namespace.KEYCLOAK_BOOT);
try {
createMasterRealm(exportImportManager);
} finally {
dbLock.releaseLock();
}
if (exportImportManager.isRunExport()) {
exportImportManager.runExport();
Quarkus.asyncExit();
}
}
Aggregations