diff --git metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java index aac0448..819306a 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -77,13 +77,13 @@ public class ObjectStore implements RawStore, Configurable { private static final Log LOG = LogFactory.getLog(ObjectStore.class.getName()); private static enum TXN_STATUS { - NO_STATE, OPEN, COMMITED, ROLLBACK + NO_STATE, OPEN, COMMITTED, ROLLBACK } private boolean isInitialized = false; private PersistenceManager pm = null; private Configuration hiveConf; - private int openTrasactionCalls = 0; + private int openTransactionCalls = 0; private Transaction currentTransaction = null; private TXN_STATUS transactionStatus = TXN_STATUS.NO_STATE; @@ -121,7 +121,7 @@ public class ObjectStore implements RawStore, Configurable { // Always want to re-create pm as we don't know if it were created by the // most recent instance of the pmf pm = null; - openTrasactionCalls = 0; + openTransactionCalls = 0; currentTransaction = null; transactionStatus = TXN_STATUS.NO_STATE; @@ -222,8 +222,8 @@ public class ObjectStore implements RawStore, Configurable { */ public boolean openTransaction() { - openTrasactionCalls++; - if (openTrasactionCalls == 1) { + openTransactionCalls++; + if (openTransactionCalls == 1) { currentTransaction = pm.currentTransaction(); currentTransaction.begin(); transactionStatus = TXN_STATUS.OPEN; @@ -243,15 +243,21 @@ public class ObjectStore implements RawStore, Configurable { */ @SuppressWarnings("nls") public boolean commitTransaction() { - assert (openTrasactionCalls >= 1); + if (TXN_STATUS.ROLLBACK == transactionStatus) { + return false; + } + if (openTransactionCalls <= 0) { + throw new RuntimeException("commitTransaction was called but openTransactionCalls = " + + openTransactionCalls + ". This probably indicates that there are unbalanced " + + "calls to openTransaction/commitTransaction"); + } if (!currentTransaction.isActive()) { throw new RuntimeException( - "Commit is called, but transaction is not active. Either there are" + "Commit is called, but transaction is not active. Either there are " + "mismatching open and close calls or rollback was called in the same trasaction"); } - openTrasactionCalls--; - if ((openTrasactionCalls == 0) && currentTransaction.isActive()) { - transactionStatus = TXN_STATUS.COMMITED; + if (0 == --openTransactionCalls) { + transactionStatus = TXN_STATUS.COMMITTED; currentTransaction.commit(); } return true; @@ -272,10 +278,10 @@ public class ObjectStore implements RawStore, Configurable { * Rolls back the current transaction if it is active */ public void rollbackTransaction() { - if (openTrasactionCalls < 1) { + if (openTransactionCalls < 1) { return; } - openTrasactionCalls = 0; + openTransactionCalls = 0; if (currentTransaction.isActive() && transactionStatus != TXN_STATUS.ROLLBACK) { transactionStatus = TXN_STATUS.ROLLBACK;