PHOENIX-5532 Index write failure does not cleanup pendingRows entries
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java
index 77aed76..0402c6f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java
@@ -793,8 +793,8 @@
           metricSource.incrementPreIndexUpdateFailures();
           // Remove all locks as they are already unlocked. There is no need to unlock them again later when
           // postBatchMutateIndispensably() is called
-          context.rowLocks.clear();
           removePendingRows(context);
+          context.rowLocks.clear();
           rethrowIndexingException(e);
       }
       throw new RuntimeException(