summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-09-19 06:07:30 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-09-19 06:07:30 +0000
commit2278740878264362fd0f51e5f782715a89e4964f (patch)
treef8868ed6487d0522e79ed5482b531f9ce8c785c0
parent32a236a80b7a7a537ffbd5f10e4a4348c417d3cb (diff)
Removed all cursor synchronization. It just adds overhead and no real (or needed) thread safety.
-rw-r--r--src/main/java/com/amazon/carbonado/Cursor.java2
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java5
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java6
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java70
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java104
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java6
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java86
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/SortedCursor.java8
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java6
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java70
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/UnionCursor.java6
-rw-r--r--src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java178
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java8
13 files changed, 257 insertions, 298 deletions
diff --git a/src/main/java/com/amazon/carbonado/Cursor.java b/src/main/java/com/amazon/carbonado/Cursor.java
index 00b2dbc..13c9784 100644
--- a/src/main/java/com/amazon/carbonado/Cursor.java
+++ b/src/main/java/com/amazon/carbonado/Cursor.java
@@ -42,7 +42,7 @@ import java.util.NoSuchElementException;
* repository in the interim. To guard against this, operate within a
* serializable {@link IsolationLevel isolation level}.
*
- * <p>Cursor instances are mutable, but they should be thread-safe. Still, only
+ * <p>Cursor instances are mutable and not guaranteed to be thread-safe. Only
* one thread should ever operate on a cursor instance.
*
* @author Brian S O'Neill
diff --git a/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java b/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java
index cf64a24..fb34617 100644
--- a/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java
@@ -64,10 +64,7 @@ public abstract class AbstractCursor<S> implements Cursor<S> {
return list;
}
- public synchronized int skipNext(int amount) throws FetchException {
- // This method is synchronized to avoid potential race conditions
- // between calls to hasNext and next in the loop below.
-
+ public int skipNext(int amount) throws FetchException {
if (amount <= 0) {
if (amount < 0) {
throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
diff --git a/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java b/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java
index 39455c8..8b330ea 100644
--- a/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java
@@ -59,14 +59,14 @@ public class DifferenceCursor<S> extends AbstractCursor<S> {
mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNext = null;
mNextRight = null;
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
if (mNext != null) {
return true;
}
@@ -109,7 +109,7 @@ public class DifferenceCursor<S> extends AbstractCursor<S> {
}
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
if (hasNext()) {
S next = mNext;
mNext = null;
diff --git a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java
index 60b3c81..f426f36 100644
--- a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java
@@ -82,61 +82,53 @@ public abstract class FilteredCursor<S> extends AbstractCursor<S> {
protected abstract boolean isAllowed(S storable);
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- mNext = null;
- }
+ mCursor.close();
+ mNext = null;
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNext != null) {
- return true;
- }
- try {
- int count = 0;
- while (mCursor.hasNext()) {
- S next = mCursor.next();
- if (isAllowed(next)) {
- mNext = next;
- return true;
- }
- interruptCheck(++count);
+ if (mNext != null) {
+ return true;
+ }
+ try {
+ int count = 0;
+ while (mCursor.hasNext()) {
+ S next = mCursor.next();
+ if (isAllowed(next)) {
+ mNext = next;
+ return true;
}
- } catch (NoSuchElementException e) {
+ interruptCheck(++count);
}
- return false;
+ } catch (NoSuchElementException e) {
}
+ return false;
}
public S next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- S next = mNext;
- mNext = null;
- return next;
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ S next = mNext;
+ mNext = null;
+ return next;
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
- }
-
- int count = 0;
- while (--amount >= 0 && hasNext()) {
- interruptCheck(++count);
- mNext = null;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- return count;
+ int count = 0;
+ while (--amount >= 0 && hasNext()) {
+ interruptCheck(++count);
+ mNext = null;
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java b/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java
index 0b17e50..bf838b1 100644
--- a/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java
@@ -113,87 +113,79 @@ public abstract class GroupedCursor<S, G> extends AbstractCursor<G> {
protected abstract G finishGroup() throws FetchException;
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- mGroupLeader = null;
- mNextAggregate = null;
- }
+ mCursor.close();
+ mGroupLeader = null;
+ mNextAggregate = null;
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNextAggregate != null) {
- return true;
- }
+ if (mNextAggregate != null) {
+ return true;
+ }
- try {
- int count = 0;
- if (mCursor.hasNext()) {
- if (mGroupLeader == null) {
- beginGroup(mGroupLeader = mCursor.next());
- }
+ try {
+ int count = 0;
+ if (mCursor.hasNext()) {
+ if (mGroupLeader == null) {
+ beginGroup(mGroupLeader = mCursor.next());
+ }
- while (mCursor.hasNext()) {
- S groupMember = mCursor.next();
+ while (mCursor.hasNext()) {
+ S groupMember = mCursor.next();
- if (mGroupComparator.compare(mGroupLeader, groupMember) == 0) {
- addToGroup(groupMember);
- } else {
- G aggregate = finishGroup();
+ if (mGroupComparator.compare(mGroupLeader, groupMember) == 0) {
+ addToGroup(groupMember);
+ } else {
+ G aggregate = finishGroup();
- beginGroup(mGroupLeader = groupMember);
+ beginGroup(mGroupLeader = groupMember);
- if (aggregate != null) {
- mNextAggregate = aggregate;
- return true;
- }
+ if (aggregate != null) {
+ mNextAggregate = aggregate;
+ return true;
}
-
- interruptCheck(++count);
}
- G aggregate = finishGroup();
+ interruptCheck(++count);
+ }
- if (aggregate != null) {
- mNextAggregate = aggregate;
- return true;
- }
+ G aggregate = finishGroup();
+
+ if (aggregate != null) {
+ mNextAggregate = aggregate;
+ return true;
}
- } catch (NoSuchElementException e) {
}
-
- return false;
+ } catch (NoSuchElementException e) {
}
+
+ return false;
}
public G next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- G next = mNextAggregate;
- mNextAggregate = null;
- return next;
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ G next = mNextAggregate;
+ mNextAggregate = null;
+ return next;
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
- }
-
- int count = 0;
- while (--amount >= 0 && hasNext()) {
- interruptCheck(++count);
- mNextAggregate = null;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- return count;
+ int count = 0;
+ while (--amount >= 0 && hasNext()) {
+ interruptCheck(++count);
+ mNextAggregate = null;
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java b/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java
index 9d11b2f..58aba0d 100644
--- a/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java
@@ -58,13 +58,13 @@ public class IntersectionCursor<S> extends AbstractCursor<S> {
mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNext = null;
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
if (mNext != null) {
return true;
}
@@ -107,7 +107,7 @@ public class IntersectionCursor<S> extends AbstractCursor<S> {
}
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
if (hasNext()) {
S next = mNext;
mNext = null;
diff --git a/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java b/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java
index 0cfd197..feeb414 100644
--- a/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java
@@ -54,73 +54,65 @@ public abstract class MultiTransformedCursor<S, T> extends AbstractCursor<T> {
protected abstract Cursor<T> transform(S storable) throws FetchException;
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- if (mNextCursor != null) {
- mNextCursor.close();
- mNextCursor = null;
- }
+ mCursor.close();
+ if (mNextCursor != null) {
+ mNextCursor.close();
+ mNextCursor = null;
}
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNextCursor != null) {
- if (mNextCursor.hasNext()) {
- return true;
- }
- mNextCursor.close();
- mNextCursor = null;
+ if (mNextCursor != null) {
+ if (mNextCursor.hasNext()) {
+ return true;
}
- try {
- int count = 0;
- while (mCursor.hasNext()) {
- Cursor<T> nextCursor = transform(mCursor.next());
- if (nextCursor != null) {
- if (nextCursor.hasNext()) {
- mNextCursor = nextCursor;
- return true;
- }
- nextCursor.close();
+ mNextCursor.close();
+ mNextCursor = null;
+ }
+ try {
+ int count = 0;
+ while (mCursor.hasNext()) {
+ Cursor<T> nextCursor = transform(mCursor.next());
+ if (nextCursor != null) {
+ if (nextCursor.hasNext()) {
+ mNextCursor = nextCursor;
+ return true;
}
- interruptCheck(++count);
+ nextCursor.close();
}
- } catch (NoSuchElementException e) {
+ interruptCheck(++count);
}
- return false;
+ } catch (NoSuchElementException e) {
}
+ return false;
}
public T next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- return mNextCursor.next();
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ return mNextCursor.next();
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- int count = 0;
- while (hasNext()) {
- int chunk = mNextCursor.skipNext(amount);
- count += chunk;
- if ((amount -= chunk) <= 0) {
- break;
- }
- interruptCheck(count);
+ int count = 0;
+ while (hasNext()) {
+ int chunk = mNextCursor.skipNext(amount);
+ count += chunk;
+ if ((amount -= chunk) <= 0) {
+ break;
}
-
- return count;
+ interruptCheck(count);
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java b/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java
index 7a728bb..9cee89b 100644
--- a/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java
@@ -198,13 +198,13 @@ public class SortedCursor<S> extends AbstractCursor<S> {
};
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mCursor.close();
mChunkIterator = null;
mChunkBuffer.close();
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
prepareNextChunk();
try {
if (mChunkIterator.hasNext()) {
@@ -217,7 +217,7 @@ public class SortedCursor<S> extends AbstractCursor<S> {
return false;
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
prepareNextChunk();
try {
return mChunkIterator.next();
@@ -233,7 +233,7 @@ public class SortedCursor<S> extends AbstractCursor<S> {
}
}
- public synchronized int skipNext(int amount) throws FetchException {
+ public int skipNext(int amount) throws FetchException {
if (amount <= 0) {
if (amount < 0) {
throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
diff --git a/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java b/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java
index 6851464..1f94e30 100644
--- a/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java
@@ -60,7 +60,7 @@ public class SymmetricDifferenceCursor<S> extends AbstractCursor<S> {
mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNextLeft = null;
@@ -76,7 +76,7 @@ public class SymmetricDifferenceCursor<S> extends AbstractCursor<S> {
* left source cursor, and &gt;0 if next element is from right source
* cursor.
*/
- public synchronized int compareNext() throws FetchException {
+ public int compareNext() throws FetchException {
if (mCompareResult != 0) {
return mCompareResult;
}
@@ -105,7 +105,7 @@ public class SymmetricDifferenceCursor<S> extends AbstractCursor<S> {
}
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
S next;
int result = compareNext();
if (result < 0) {
diff --git a/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java b/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java
index 0860cf0..9f9efe7 100644
--- a/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java
@@ -53,61 +53,53 @@ public abstract class TransformedCursor<S, T> extends AbstractCursor<T> {
protected abstract T transform(S storable) throws FetchException;
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- mNext = null;
- }
+ mCursor.close();
+ mNext = null;
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNext != null) {
- return true;
- }
- try {
- int count = 0;
- while (mCursor.hasNext()) {
- T next = transform(mCursor.next());
- if (next != null) {
- mNext = next;
- return true;
- }
- interruptCheck(++count);
+ if (mNext != null) {
+ return true;
+ }
+ try {
+ int count = 0;
+ while (mCursor.hasNext()) {
+ T next = transform(mCursor.next());
+ if (next != null) {
+ mNext = next;
+ return true;
}
- } catch (NoSuchElementException e) {
+ interruptCheck(++count);
}
- return false;
+ } catch (NoSuchElementException e) {
}
+ return false;
}
public T next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- T next = mNext;
- mNext = null;
- return next;
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ T next = mNext;
+ mNext = null;
+ return next;
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
- }
-
- int count = 0;
- while (--amount >= 0 && hasNext()) {
- interruptCheck(++count);
- mNext = null;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- return count;
+ int count = 0;
+ while (--amount >= 0 && hasNext()) {
+ interruptCheck(++count);
+ mNext = null;
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java b/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java
index 7a62678..7e4fde3 100644
--- a/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java
@@ -59,14 +59,14 @@ public class UnionCursor<S> extends AbstractCursor<S> {
mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNextLeft = null;
mNextRight = null;
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
if (mNextLeft == null && mLeftCursor.hasNext()) {
mNextLeft = mLeftCursor.next();
}
@@ -76,7 +76,7 @@ public class UnionCursor<S> extends AbstractCursor<S> {
return mNextLeft != null || mNextRight != null;
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
if (hasNext()) {
S next;
if (mNextLeft == null) {
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java
index a6df5e0..075df1b 100644
--- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java
+++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java
@@ -61,123 +61,117 @@ class IndexedCursor<S extends Storable> extends AbstractCursor<S> {
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNext != null) {
- return true;
- }
- while (mCursor.hasNext()) {
- final Storable indexEntry = mCursor.next();
- S master = mGenerator.loadMaster(indexEntry);
- if (master == null) {
- LogFactory.getLog(getClass()).warn
- ("Master is missing for index entry: " + indexEntry);
- } else {
- if (mGenerator.isConsistent(indexEntry, master)) {
+ if (mNext != null) {
+ return true;
+ }
+ while (mCursor.hasNext()) {
+ final Storable indexEntry = mCursor.next();
+ S master = mGenerator.loadMaster(indexEntry);
+ if (master == null) {
+ LogFactory.getLog(getClass()).warn
+ ("Master is missing for index entry: " + indexEntry);
+ } else {
+ if (mGenerator.isConsistent(indexEntry, master)) {
+ mNext = master;
+ return true;
+ }
+
+ // This index entry is stale. Repair is needed.
+
+ // Insert a correct index entry, just to be sure.
+ try {
+ final IndexedRepository repo = mStorage.mRepository;
+ final Storage<?> indexEntryStorage =
+ repo.getIndexEntryStorageFor(mGenerator.getIndexEntryClass());
+ Storable newIndexEntry = indexEntryStorage.prepare();
+ mGenerator.setAllProperties(newIndexEntry, master);
+
+ if (newIndexEntry.tryLoad()) {
+ // Good, the correct index entry exists. We'll see
+ // the master record eventually, so skip.
+ } else {
+ // We have no choice but to return the master, at
+ // the risk of seeing it multiple times. This is
+ // better than seeing it never.
+ LogFactory.getLog(getClass()).warn
+ ("Inconsistent index entry: " + indexEntry);
mNext = master;
- return true;
}
- // This index entry is stale. Repair is needed.
-
- // Insert a correct index entry, just to be sure.
- try {
- final IndexedRepository repo = mStorage.mRepository;
- final Storage<?> indexEntryStorage =
- repo.getIndexEntryStorageFor(mGenerator.getIndexEntryClass());
- Storable newIndexEntry = indexEntryStorage.prepare();
- mGenerator.setAllProperties(newIndexEntry, master);
-
- if (newIndexEntry.tryLoad()) {
- // Good, the correct index entry exists. We'll see
- // the master record eventually, so skip.
- } else {
- // We have no choice but to return the master, at
- // the risk of seeing it multiple times. This is
- // better than seeing it never.
- LogFactory.getLog(getClass()).warn
- ("Inconsistent index entry: " + indexEntry);
- mNext = master;
- }
+ // Repair the stale index entry.
+ RepairExecutor.execute(new Runnable() {
+ public void run() {
+ Transaction txn = repo.enterTransaction();
+ try {
+ // Reload master and verify inconsistency.
+ S master = mGenerator.loadMaster(indexEntry);
+ if (mGenerator.isConsistent(indexEntry, master)) {
+ return;
+ }
- // Repair the stale index entry.
- RepairExecutor.execute(new Runnable() {
- public void run() {
- Transaction txn = repo.enterTransaction();
+ Storable newIndexEntry = indexEntryStorage.prepare();
+ mGenerator.setAllProperties(newIndexEntry, master);
+
+ newIndexEntry.tryInsert();
+
+ indexEntry.tryDelete();
+ txn.commit();
+ } catch (FetchException fe) {
+ LogFactory.getLog(IndexedCursor.class).warn
+ ("Unable to check if repair required for " +
+ "inconsistent index entry " +
+ indexEntry, fe);
+ } catch (PersistException pe) {
+ LogFactory.getLog(IndexedCursor.class).error
+ ("Unable to repair inconsistent index entry " +
+ indexEntry, pe);
+ } finally {
try {
- // Reload master and verify inconsistency.
- S master = mGenerator.loadMaster(indexEntry);
- if (mGenerator.isConsistent(indexEntry, master)) {
- return;
- }
-
- Storable newIndexEntry = indexEntryStorage.prepare();
- mGenerator.setAllProperties(newIndexEntry, master);
-
- newIndexEntry.tryInsert();
-
- indexEntry.tryDelete();
- txn.commit();
- } catch (FetchException fe) {
- LogFactory.getLog(IndexedCursor.class).warn
- ("Unable to check if repair required for " +
- "inconsistent index entry " +
- indexEntry, fe);
+ txn.exit();
} catch (PersistException pe) {
LogFactory.getLog(IndexedCursor.class).error
("Unable to repair inconsistent index entry " +
indexEntry, pe);
- } finally {
- try {
- txn.exit();
- } catch (PersistException pe) {
- LogFactory.getLog(IndexedCursor.class).error
- ("Unable to repair inconsistent index entry " +
- indexEntry, pe);
- }
}
}
- });
- } catch (RepositoryException re) {
- LogFactory.getLog(getClass()).error
- ("Unable to inspect inconsistent index entry " +
- indexEntry, re);
- }
+ }
+ });
+ } catch (RepositoryException re) {
+ LogFactory.getLog(getClass()).error
+ ("Unable to inspect inconsistent index entry " +
+ indexEntry, re);
+ }
- if (mNext != null) {
- return true;
- }
+ if (mNext != null) {
+ return true;
}
}
- return false;
}
+ return false;
}
public S next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- S next = mNext;
- mNext = null;
- return next;
- }
+ if (hasNext()) {
+ S next = mNext;
+ mNext = null;
+ return next;
}
throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (mNext == null) {
- return mCursor.skipNext(amount);
- }
+ if (mNext == null) {
+ return mCursor.skipNext(amount);
+ }
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
-
- mNext = null;
- return 1 + mCursor.skipNext(amount - 1);
+ return 0;
}
+
+ mNext = null;
+ return 1 + mCursor.skipNext(amount - 1);
}
}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java
index 7ef2510..f0a3752 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCCursor.java
@@ -52,7 +52,7 @@ class JDBCCursor<S extends Storable> extends AbstractCursor<S> {
mResultSet = statement.executeQuery();
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
if (mResultSet != null) {
try {
mResultSet.close();
@@ -66,7 +66,7 @@ class JDBCCursor<S extends Storable> extends AbstractCursor<S> {
}
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
ResultSet rs = mResultSet;
if (rs == null) {
return false;
@@ -84,7 +84,7 @@ class JDBCCursor<S extends Storable> extends AbstractCursor<S> {
return mHasNext;
}
- public synchronized S next() throws FetchException, NoSuchElementException {
+ public S next() throws FetchException, NoSuchElementException {
if (!hasNext()) {
throw new NoSuchElementException();
}
@@ -97,7 +97,7 @@ class JDBCCursor<S extends Storable> extends AbstractCursor<S> {
}
}
- public synchronized int skipNext(int amount) throws FetchException {
+ public int skipNext(int amount) throws FetchException {
if (amount <= 0) {
if (amount < 0) {
throw new IllegalArgumentException("Cannot skip negative amount: " + amount);