Skip to content

Commit 00a6531

Browse files
committed
Flush database changes after switching to READONLY mode
1 parent c33d3fa commit 00a6531

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

dspace-api/src/main/java/org/dspace/core/Context.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,15 @@ public void setMode(Mode newMode) {
810810
readOnlyCache.clear();
811811
}
812812

813+
// When going to READ_ONLY, flush database changes to ensure that the current data is retrieved
814+
if (newMode == Mode.READ_ONLY && mode != Mode.READ_ONLY) {
815+
try {
816+
dbConnection.flushSession();
817+
} catch (SQLException ex) {
818+
log.warn("Unable to flush database changes after switching to READ_ONLY mode", ex);
819+
}
820+
}
821+
813822
//save the new mode
814823
mode = newMode;
815824
}
@@ -880,16 +889,6 @@ public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLExcep
880889
dbConnection.uncacheEntity(entity);
881890
}
882891

883-
/**
884-
* Flush the current Session to synchronizes the in-memory state of the Session
885-
* with the database (write changes to the database)
886-
*
887-
* @throws SQLException passed through.
888-
*/
889-
public void flushDBChanges() throws SQLException {
890-
dbConnection.flushSession();
891-
}
892-
893892
public Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson) {
894893
if (isReadOnly()) {
895894
return readOnlyCache.getCachedAuthorizationResult(dspaceObject, action, eperson);

dspace-api/src/main/java/org/dspace/discovery/IndexEventConsumer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ public void consume(Context ctx, Event event) throws Exception {
202202
public void end(Context ctx) throws Exception {
203203

204204
// Change the mode to readonly to improve performance
205-
// First, we flush the changes to database, if session is dirty, has pending changes
206-
// to synchronize with database, without this flush it could index an old version of
207-
// the object
208-
ctx.flushDBChanges();
209205
Context.Mode originalMode = ctx.getCurrentMode();
210206
ctx.setMode(Context.Mode.READ_ONLY);
211207

0 commit comments

Comments
 (0)