summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-10-16 00:35:37 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-10-16 00:35:37 +0000
commit609cea3eb9d65330dee18b1893729e0438b83981 (patch)
tree7de3ca549429633cfe6b0e636727db37bd083099 /src
parentf0ec30fd9cc7fa19f9f9bf82d7d7449a65d90359 (diff)
Resolved deadlocks.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/amazon/carbonado/layout/LayoutFactory.java3
-rw-r--r--src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java65
2 files changed, 46 insertions, 22 deletions
diff --git a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java
index 8a0ede8..691d9d4 100644
--- a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java
+++ b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java
@@ -26,6 +26,7 @@ import org.cojen.util.SoftValuedHashMap;
import com.amazon.carbonado.Cursor;
import com.amazon.carbonado.FetchException;
import com.amazon.carbonado.FetchNoneException;
+import com.amazon.carbonado.IsolationLevel;
import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.Repository;
import com.amazon.carbonado.RepositoryException;
@@ -85,7 +86,7 @@ public class LayoutFactory implements LayoutCapability {
StorableInfo<?> info = StorableIntrospector.examine(type);
- Transaction txn = mRepository.enterTransaction();
+ Transaction txn = mRepository.enterTopTransaction(IsolationLevel.READ_COMMITTED);
try {
// If type represents a new generation, then a new layout needs to
// be inserted.
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
index 6eba33a..b885399 100644
--- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java
@@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFactory;
import com.amazon.carbonado.Cursor;
import com.amazon.carbonado.FetchException;
+import com.amazon.carbonado.IsolationLevel;
import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.Query;
import com.amazon.carbonado.Repository;
@@ -33,6 +34,7 @@ import com.amazon.carbonado.RepositoryException;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.Storage;
import com.amazon.carbonado.SupportException;
+import com.amazon.carbonado.Transaction;
import com.amazon.carbonado.Trigger;
import com.amazon.carbonado.capability.IndexInfo;
@@ -425,7 +427,14 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
primaryInfo.setIndexTypeDescriptor(pkIndex.getTypeDescriptor());
if (!readOnly) {
- primaryInfo.update();
+ Repository repo = mRepository.getRootRepository();
+ Transaction txn = repo.enterTopTransaction(IsolationLevel.READ_COMMITTED);
+ try {
+ primaryInfo.update();
+ txn.commit();
+ } finally {
+ txn.exit();
+ }
}
}
}
@@ -698,25 +707,37 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
// Can't register itself in itself.
return null;
}
+
+ Repository repo = mRepository.getRootRepository();
+
StoredDatabaseInfo info;
try {
- info = prepareStoredDatabaseInfo();
+ info = repo.storageFor(StoredDatabaseInfo.class).prepare();
} catch (SupportException e) {
return null;
}
info.setDatabaseName(getStorableType().getName());
- if (!info.tryLoad()) {
- if (layout == null) {
- info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_NONE);
- } else {
- info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_STANDARD);
- }
- info.setCreationTimestamp(System.currentTimeMillis());
- info.setVersionNumber(0);
- if (!readOnly) {
- info.insert();
+
+
+ Transaction txn = repo.enterTopTransaction(IsolationLevel.READ_COMMITTED);
+ try {
+ if (!info.tryLoad()) {
+ if (layout == null) {
+ info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_NONE);
+ } else {
+ info.setEvolutionStrategy(StoredDatabaseInfo.EVOLUTION_STANDARD);
+ }
+ info.setCreationTimestamp(System.currentTimeMillis());
+ info.setVersionNumber(0);
+ if (!readOnly) {
+ info.insert();
+ }
}
+ txn.commit();
+ } finally {
+ txn.exit();
}
+
return info;
}
@@ -726,22 +747,24 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag
return;
}
if (!readOnly) {
+ Repository repo = mRepository.getRootRepository();
+
StoredDatabaseInfo info;
try {
- info = prepareStoredDatabaseInfo();
+ info = repo.storageFor(StoredDatabaseInfo.class).prepare();
} catch (SupportException e) {
return;
}
info.setDatabaseName(name);
- info.delete();
- }
- }
- /**
- * @throws SupportException if StoredDatabaseInfo is not supported by codec factory
- */
- private StoredDatabaseInfo prepareStoredDatabaseInfo() throws RepositoryException {
- return mRepository.getRootRepository().storageFor(StoredDatabaseInfo.class).prepare();
+ Transaction txn = repo.enterTopTransaction(IsolationLevel.READ_COMMITTED);
+ try {
+ info.delete();
+ txn.commit();
+ } finally {
+ txn.exit();
+ }
+ }
}
// Note: BDBStorage could just implement the RawSupport interface, but