Flush database changes after switching to READONLY mode

This commit is contained in:
Toni Prieto
2023-10-13 20:52:08 +02:00
parent c33d3fa87d
commit 00a65312cc
2 changed files with 9 additions and 14 deletions

View File

@@ -810,6 +810,15 @@ public class Context implements AutoCloseable {
readOnlyCache.clear();
}
// When going to READ_ONLY, flush database changes to ensure that the current data is retrieved
if (newMode == Mode.READ_ONLY && mode != Mode.READ_ONLY) {
try {
dbConnection.flushSession();
} catch (SQLException ex) {
log.warn("Unable to flush database changes after switching to READ_ONLY mode", ex);
}
}
//save the new mode
mode = newMode;
}
@@ -880,16 +889,6 @@ public class Context implements AutoCloseable {
dbConnection.uncacheEntity(entity);
}
/**
* Flush the current Session to synchronizes the in-memory state of the Session
* with the database (write changes to the database)
*
* @throws SQLException passed through.
*/
public void flushDBChanges() throws SQLException {
dbConnection.flushSession();
}
public Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson) {
if (isReadOnly()) {
return readOnlyCache.getCachedAuthorizationResult(dspaceObject, action, eperson);

View File

@@ -202,10 +202,6 @@ public class IndexEventConsumer implements Consumer {
public void end(Context ctx) throws Exception {
// Change the mode to readonly to improve performance
// First, we flush the changes to database, if session is dirty, has pending changes
// to synchronize with database, without this flush it could index an old version of
// the object
ctx.flushDBChanges();
Context.Mode originalMode = ctx.getCurrentMode();
ctx.setMode(Context.Mode.READ_ONLY);