From 5f60f8b308bb747c01557c35695b6ad83732b22a Mon Sep 17 00:00:00 2001 From: broneill Date: Sun, 12 Apr 2015 08:02:29 -0700 Subject: Prevent deadlock between cursor close and TransactionScope cleanup. --- .../java/com/amazon/carbonado/raw/RawCursor.java | 98 +++++++++++----------- 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/raw/RawCursor.java b/src/main/java/com/amazon/carbonado/raw/RawCursor.java index 4b7ef09..b3dbb0b 100644 --- a/src/main/java/com/amazon/carbonado/raw/RawCursor.java +++ b/src/main/java/com/amazon/carbonado/raw/RawCursor.java @@ -111,8 +111,8 @@ public abstract class RawCursor extends AbstractCursor { } public boolean hasNext() throws FetchException { - mLock.lock(); try { + mLock.lock(); try { switch (mState) { case UNINITIALIZED: @@ -137,47 +137,47 @@ public abstract class RawCursor extends AbstractCursor { case HAS_NEXT: return true; } - } catch (FetchException e) { - // Auto-close in response to FetchException. - try { - close(); - } catch (FetchException e2) { - // Ignore. - } - throw e; + } finally { + mLock.unlock(); } - - // Reached the end naturally, so close. - close(); - } finally { - mLock.unlock(); + } catch (FetchException e) { + // Auto-close in response to FetchException. + try { + close(); + } catch (FetchException e2) { + // Ignore. + } + throw e; } + // Reached the end naturally, so close. + close(); + return false; } public S next() throws FetchException, NoSuchElementException { - mLock.lock(); try { - if (!hasNext()) { - handleNoSuchElement(); - throw new NoSuchElementException(); - } + mLock.lock(); try { + if (!hasNext()) { + handleNoSuchElement(); + throw new NoSuchElementException(); + } S obj = instantiateCurrent(); mState = TRY_NEXT; return obj; - } catch (FetchException e) { - // Auto-close in response to FetchException. - try { - close(); - } catch (FetchException e2) { - // Ignore. - } - throw e; + } finally { + mLock.unlock(); } - } finally { - mLock.unlock(); + } catch (FetchException e) { + // Auto-close in response to FetchException. + try { + close(); + } catch (FetchException e2) { + // Ignore. + } + throw e; } } @@ -190,38 +190,38 @@ public abstract class RawCursor extends AbstractCursor { return 0; } - mLock.lock(); try { int actual = 0; - if (hasNext()) { - try { + mLock.lock(); + try { + if (hasNext()) { actual += mReverse ? toBoundedPrevious(amount) : toBoundedNext(amount); - } catch (FetchException e) { - // Auto-close in response to FetchException. - try { - close(); - } catch (FetchException e2) { - // Ignore. - } - throw e; - } - if (actual >= amount) { - return actual; + if (actual >= amount) { + return actual; + } + mState = TRY_NEXT; + // Since state was HAS_NEXT and is forced into TRY_NEXT, actual + // amount skipped is effectively one more. + actual++; } - mState = TRY_NEXT; - // Since state was HAS_NEXT and is forced into TRY_NEXT, actual - // amount skipped is effectively one more. - actual++; + } finally { + mLock.unlock(); } // Reached the end naturally, so close. close(); return actual; - } finally { - mLock.unlock(); + } catch (FetchException e) { + // Auto-close in response to FetchException. + try { + close(); + } catch (FetchException e2) { + // Ignore. + } + throw e; } } -- cgit v1.2.3 From 0265480e804135e33574d8dfd7d4a49b71d0953b Mon Sep 17 00:00:00 2001 From: broneill Date: Wed, 14 Oct 2015 07:06:04 -0700 Subject: Handle more retryable exceptions during index build. --- src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java index f7717b3..aa4cc63 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java @@ -30,11 +30,13 @@ import org.apache.commons.logging.LogFactory; import com.amazon.carbonado.CorruptEncodingException; import com.amazon.carbonado.Cursor; +import com.amazon.carbonado.FetchDeadlockException; import com.amazon.carbonado.FetchException; import com.amazon.carbonado.FetchTimeoutException; import com.amazon.carbonado.IsolationLevel; -import com.amazon.carbonado.PersistTimeoutException; +import com.amazon.carbonado.PersistDeadlockException; import com.amazon.carbonado.PersistException; +import com.amazon.carbonado.PersistTimeoutException; import com.amazon.carbonado.Query; import com.amazon.carbonado.Repository; import com.amazon.carbonado.RepositoryException; @@ -584,7 +586,9 @@ class ManagedIndex implements IndexEntryAccessor { retry = false; } catch (RepositoryException e) { if (e instanceof FetchTimeoutException || - e instanceof PersistTimeoutException) + e instanceof FetchDeadlockException || + e instanceof PersistTimeoutException || + e instanceof PersistDeadlockException) { log.warn("Lock conflict during index repair; will retry: " + indexEntry + ", " + e); -- cgit v1.2.3 From f89ee377ab4b197959191849e8acfba16f7cbda0 Mon Sep 17 00:00:00 2001 From: broneill Date: Mon, 25 Apr 2016 23:01:01 +0000 Subject: Add explicit int->boolean conversions, as required by JDK 1.8.0_91. --- src/main/java/com/amazon/carbonado/gen/StorableGenerator.java | 2 ++ src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java | 2 ++ 2 files changed, 4 insertions(+) mode change 100644 => 100755 src/main/java/com/amazon/carbonado/gen/StorableGenerator.java mode change 100644 => 100755 src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java old mode 100644 new mode 100755 index 59312c8..b1d529c --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -1818,6 +1818,7 @@ public final class StorableGenerator { b.loadConstant(PROPERTY_STATE_MASK << ((versionOrdinal & 0xf) * 2)); b.math(Opcode.IAND); // zero == false, not zero == true + b.convert(TypeDesc.INT, TypeDesc.BOOLEAN); b.returnValue(TypeDesc.BOOLEAN); } } @@ -2481,6 +2482,7 @@ public final class StorableGenerator { b.loadConstant(PROPERTY_STATE_MASK << ((ordinal & 0xf) * 2)); b.math(Opcode.IAND); // zero == false, not zero == true + b.convert(TypeDesc.INT, TypeDesc.BOOLEAN); b.returnValue(TypeDesc.BOOLEAN); return; } diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java old mode 100644 new mode 100755 index 7fbf3a5..c4accab --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java @@ -1239,6 +1239,7 @@ class JDBCStorableGenerator { yieldConAndHandleException(b, supportVar, tryBeforeCon, conVar, tryAfterCon, true); b.loadLocal(updateCount); + b.convert(TypeDesc.INT, TypeDesc.BOOLEAN); b.returnValue(TypeDesc.BOOLEAN); } @@ -1277,6 +1278,7 @@ class JDBCStorableGenerator { yieldConAndHandleException(b, supportVar, tryBeforeCon, conVar, tryAfterCon, true); b.loadLocal(resultVar); + b.convert(TypeDesc.INT, TypeDesc.BOOLEAN); b.returnValue(TypeDesc.BOOLEAN); } -- cgit v1.2.3