use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class JpaMapStorageProviderFactory method update.
private void update(Class<?> modelType, Connection connection, KeycloakSession session) {
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession lockSession) -> {
// TODO locking tables based on modelType: https://github.com/keycloak/keycloak/issues/9388
DBLockProvider dbLock = session.getProvider(DBLockProvider.class);
dbLock.waitForLock(DBLockProvider.Namespace.DATABASE);
try {
session.getProvider(MapJpaUpdaterProvider.class).update(modelType, connection, config.get("schema"));
} finally {
dbLock.releaseLock();
}
});
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class QuarkusJpaConnectionProviderFactory method update.
private void update(Connection connection, String schema, KeycloakSession session, JpaUpdaterProvider updater) {
DBLockManager dbLockManager = new DBLockManager(session);
DBLockProvider dbLock2 = dbLockManager.getDBLock();
dbLock2.waitForLock(DBLockProvider.Namespace.DATABASE);
try {
updater.update(connection, schema);
} finally {
dbLock2.releaseLock();
}
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class QuarkusJpaConnectionProviderFactory method export.
private void export(Connection connection, String schema, File databaseUpdateFile, KeycloakSession session, JpaUpdaterProvider updater) {
DBLockManager dbLockManager = new DBLockManager(session);
DBLockProvider dbLock2 = dbLockManager.getDBLock();
dbLock2.waitForLock(DBLockProvider.Namespace.DATABASE);
try {
updater.export(connection, schema, databaseUpdateFile);
} finally {
dbLock2.releaseLock();
}
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class DBLockBasedCacheInitializer method startLoading.
/**
* Just coordinator will run this. And there is DB-lock, so the delegate.startLoading() will be permitted just by the single DC
*/
@Override
protected void startLoading() {
DBLockManager dbLockManager = new DBLockManager(session);
dbLockManager.checkForcedUnlock();
DBLockProvider dbLock = dbLockManager.getDBLock();
dbLock.waitForLock(DBLockProvider.Namespace.OFFLINE_SESSIONS);
try {
if (isFinished()) {
log.infof("Task already finished when DBLock retrieved");
} else {
delegate.startLoading();
}
} finally {
dbLock.releaseLock();
}
}
use of org.keycloak.models.dblock.DBLockProvider in project keycloak by keycloak.
the class DBLockTest method simpleNestedLockTest.
@Test
public void simpleNestedLockTest() throws Exception {
inComittedTransaction(1, (session, i) -> {
// first session lock DATABASE
DBLockProvider dbLock1 = new DBLockManager(session).getDBLock();
dbLock1.waitForLock(DBLockProvider.Namespace.DATABASE);
try {
Assert.assertEquals(DBLockProvider.Namespace.DATABASE, dbLock1.getCurrentLock());
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionLC2) -> {
// a second session/dblock-provider can lock another namespace OFFLINE_SESSIONS
DBLockProvider dbLock2 = new DBLockManager(sessionLC2).getDBLock();
dbLock2.waitForLock(DBLockProvider.Namespace.OFFLINE_SESSIONS);
try {
// getCurrentLock is local, each provider instance has one
Assert.assertEquals(DBLockProvider.Namespace.OFFLINE_SESSIONS, dbLock2.getCurrentLock());
} finally {
dbLock2.releaseLock();
}
Assert.assertNull(dbLock2.getCurrentLock());
});
} finally {
dbLock1.releaseLock();
}
Assert.assertNull(dbLock1.getCurrentLock());
return null;
});
}
Aggregations