mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
Flush database changes after switching to READONLY mode
This commit is contained in:
@@ -810,6 +810,15 @@ public class Context implements AutoCloseable {
|
|||||||
readOnlyCache.clear();
|
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
|
//save the new mode
|
||||||
mode = newMode;
|
mode = newMode;
|
||||||
}
|
}
|
||||||
@@ -880,16 +889,6 @@ public class Context implements AutoCloseable {
|
|||||||
dbConnection.uncacheEntity(entity);
|
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) {
|
public Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson) {
|
||||||
if (isReadOnly()) {
|
if (isReadOnly()) {
|
||||||
return readOnlyCache.getCachedAuthorizationResult(dspaceObject, action, eperson);
|
return readOnlyCache.getCachedAuthorizationResult(dspaceObject, action, eperson);
|
||||||
|
@@ -202,10 +202,6 @@ public class IndexEventConsumer implements Consumer {
|
|||||||
public void end(Context ctx) throws Exception {
|
public void end(Context ctx) throws Exception {
|
||||||
|
|
||||||
// Change the mode to readonly to improve performance
|
// 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();
|
Context.Mode originalMode = ctx.getCurrentMode();
|
||||||
ctx.setMode(Context.Mode.READ_ONLY);
|
ctx.setMode(Context.Mode.READ_ONLY);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user