afs commented on a change in pull request #537: JENA-1676 , JENA-1677: Make the 
commit step more robust against external factors
URL: https://github.com/apache/jena/pull/537#discussion_r261577353
 
 

 ##########
 File path: 
jena-db/jena-dboe-transaction/src/main/java/org/apache/jena/dboe/transaction/txn/TransactionCoordinator.java
 ##########
 @@ -683,28 +687,80 @@ private boolean promotionWaitForWriters() {
         // Do here because it needs access to the journal.
         notifyPrepareStart(transaction);
         transaction.getComponents().forEach(sysTrans -> {
-            TransactionalComponent c = sysTrans.getComponent() ;
-            ByteBuffer data = c.commitPrepare(transaction) ;
+            ByteBuffer data = sysTrans.commitPrepare() ;
             if ( data != null ) {
-                PrepareState s = new PrepareState(c.getComponentId(), data) ;
+                PrepareState s = new PrepareState(sysTrans.getComponentId(), 
data) ;
                 journal.write(s) ;
             }
         }) ;
         notifyPrepareFinish(transaction);
     }
-
-    /*package*/ void executeCommit(Transaction transaction, Runnable commit, 
Runnable finish) {
+    
+    /*package*/ void executeCommit(Transaction transaction, Runnable commit, 
Runnable finish, Runnable sysabort) {
         if ( transaction.getMode() == ReadWrite.READ ) {
             finish.run();
             notifyCommitFinish(transaction);
             return;
         }
-        
-        // This is the commit for a write transaction  
+        journal.startWrite();
+        try {
+            executeCommitWriter(transaction, commit, finish, sysabort);
+            journal.commitWrite();
+        } catch (TransactionException ex) {
+            throw ex;
+        } catch (Throwable th) {
+            throw th;
+        } finally { journal.endWrite(); }
+    }
+    
+    private void executeCommitWriter(Transaction transaction, Runnable commit, 
Runnable finish, Runnable sysabort) {
         synchronized(coordinatorLock) {
-            // *** COMMIT POINT
-            journal.sync() ;
-            // *** COMMIT POINT
+            try {
+                // Simulate a Thread.interrupt during I/O.
+//                if ( true )
+//                    throw new FileException(new 
ClosedByInterruptException());
+                
+                // *** COMMIT POINT
+                journal.writeJournal(JournalEntry.COMMIT);
+                journal.sync();
+                // *** COMMIT POINT
+            }
+            // catch (ClosedByInterruptException ex) {}
+            // Some low level system error - probably a sign of something 
serious like disk error.
+            catch(FileException ex)  {
+                if ( ex.getCause() instanceof ClosedByInterruptException ) {
+                    // Thread interrupt during java I/O.
+                    // File was closed by java.nio.
+                    // Reopen - this truncates to the last write start 
position.
+                    journal.reopen();
+                    // This call should clear up the transaction state.
+                    rollback(transaction, sysabort);
+                    SysLog.warn("Thread interrupt during I/O in 'commit' : 
executed transaction rollback: "+ex.getMessage());
+                    throw new TransactionException("Thread interrupt during 
I/O in 'commit' : transaction rollback.", ex);
+                }
+                if ( isIOException(ex) )
+                    SysErr.warn("IOException during 'commit' : transaction may 
have committed. Attempting rollback: "+ex.getMessage());
+                else
+                    SysErr.warn("Exception during 'commit' : transaction may 
have committed. Attempting rollback. Details:",ex);
+                if ( abandonTxn(transaction, sysabort) ) {
+                    SysErr.warn("Transaction rollback");
+                    throw new TransactionException("Exception during 'commit' 
- transaction rollback.", ex);
+                }
+                // Very bad. (This have been dealt with already and should get 
to here.)
+                SysErr.error("Transaction rollback failed. System unstable.");
+                throw new TransactionException("Exception during 'rollback' - 
System unstable.", ex);
 
 Review comment:
   If it gets here, I don't know what happened but likely some external 
environment (I/O) issue. Rollback does not use more disk space; it does do I/O 
to reset the journal removing bytes at the end.
   
   It is a log message so won't be seen until later.
   
   "System unstable" was supposed to communicate that.
   
   How about changing it to include "contact users@jena" and making it a 
`java.lang.Error`?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to