[ASTERIXDB-3451][STO] Avoid unlocking twice when pin fails

- user model changes: no
- storage format changes: no
- interface changes: no

Ext-ref: MB-62713
Change-Id: I1abe2a7cfd24d19319c6606c76d479291e6638b4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18487
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-btree/src/main/java/org/apache/hyracks/storage/am/btree/impls/DiskBTree.java b/hyracks-fullstack/hyracks/hyracks-storage-am-btree/src/main/java/org/apache/hyracks/storage/am/btree/impls/DiskBTree.java
index df4ed47..87b0032 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-btree/src/main/java/org/apache/hyracks/storage/am/btree/impls/DiskBTree.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-btree/src/main/java/org/apache/hyracks/storage/am/btree/impls/DiskBTree.java
@@ -124,9 +124,10 @@
             while (!ctx.getInteriorFrame().isLeaf()) {
                 // walk down the tree until we find the leaf
                 childPageId = ctx.getInteriorFrame().getChildPageId(ctx.getPred());
+                ICachedPage nextPage =
+                        bufferCache.pin(BufferedFileHandle.getDiskPageId(getFileId(), childPageId), bcOpCtx);
                 bufferCache.unpin(currentPage, bcOpCtx);
-
-                currentPage = bufferCache.pin(BufferedFileHandle.getDiskPageId(getFileId(), childPageId), bcOpCtx);
+                currentPage = nextPage;
                 ctx.getInteriorFrame().setPage(currentPage);
             }