use of org.keycloak.models.dblock.DBLockManager 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.DBLockManager 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.DBLockManager 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.DBLockManager 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;
});
}
use of org.keycloak.models.dblock.DBLockManager in project keycloak by keycloak.
the class DBLockTest method before.
@Before
public void before() throws Exception {
inComittedTransaction(1, (session, i) -> {
// Set timeouts for testing
DBLockManager lockManager = new DBLockManager(session);
DBLockProviderFactory lockFactory = lockManager.getDBLockFactory();
lockFactory.setTimeouts(LOCK_RECHECK_MILLIS, LOCK_TIMEOUT_MILLIS);
// Drop lock table, just to simulate racing threads for create lock table and insert lock record into it.
lockManager.getDBLock().destroyLockInfo();
return null;
});
}
Aggregations