#50997: Fixed sources of inconsistencies of MDR storage caused by commiting incomplete transactions.
1.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/BtreeDatabase.java Fri Oct 29 16:59:26 2004 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/BtreeDatabase.java Sat Oct 30 11:57:20 2004 +0000
1.3 @@ -305,7 +305,7 @@
1.4 FileCache copyCache = null;
1.5 BtreeDataFile copyFile;
1.6
1.7 - if (cache.hasChanges()) {
1.8 + if (cache.getModStatus() != 0) {
1.9 throw new StorageBadRequestException(
1.10 MessageFormat.format(
1.11 "There are changes to repository {0} that have not been committed",
1.12 @@ -346,7 +346,7 @@
1.13 */
1.14 public void compress() throws StorageException {
1.15 synchronized (myStorage) {
1.16 - if (cache.hasChanges()) {
1.17 + if (cache.getModStatus() != 0) {
1.18 throw new StorageBadRequestException(
1.19 MessageFormat.format(
1.20 "There are changes to repository {0} that have not been committed",
1.21 @@ -501,51 +501,52 @@
1.22 StorageException writeError;
1.23 classIndexChanged = false;
1.24
1.25 - // First, persistently delete everything that needs it
1.26 - Iterator delIter = cache.getDeleted().iterator();
1.27 - while (delIter.hasNext()) {
1.28 - id = (MOFID)delIter.next();
1.29 - removeRecord(id);
1.30 - transactionCache.addDeleted(id);
1.31 - }
1.32 + int modStatus = cache.getModStatus();
1.33 + while (modStatus != 0) {
1.34 + // First, persistently delete everything that needs it
1.35 + if ((modStatus & MDRCache.M_DELETED) != 0) {
1.36 + Iterator delIter = cache.getDeleted().iterator();
1.37 + while (delIter.hasNext()) {
1.38 + id = (MOFID)delIter.next();
1.39 + removeRecord(id);
1.40 + transactionCache.addDeleted(id);
1.41 + }
1.42 + }
1.43
1.44 - // Next, modify what needs modification
1.45 - Iterator dirtyIter = cache.getDirty().iterator();
1.46 - while (dirtyIter.hasNext()) {
1.47 - Map.Entry entry = (Map.Entry) dirtyIter.next();
1.48 - id = (MOFID) entry.getKey();
1.49 - value = entry.getValue();
1.50 - writeError = replaceRecord(id, value);
1.51 - if (writeError == null) {
1.52 - transactionCache.addReplaced(id, baoStrmToBytes);
1.53 - }
1.54 - else /*if (commit)*/ {
1.55 - throw writeError;
1.56 - }
1.57 -// else if (loggingStream != null) {
1.58 -// loggingStream.println("Error writing streamable: " +
1.59 -// writeError.toString());
1.60 -// }
1.61 - }
1.62 + // Next, modify what needs modification
1.63 + if ((modStatus & MDRCache.M_DIRTY) != 0) {
1.64 + Iterator dirtyIter = cache.getDirty().iterator();
1.65 + while (dirtyIter.hasNext()) {
1.66 + Map.Entry entry = (Map.Entry) dirtyIter.next();
1.67 + id = (MOFID) entry.getKey();
1.68 + value = entry.getValue();
1.69 + writeError = replaceRecord(id, value);
1.70 + if (writeError == null) {
1.71 + transactionCache.addReplaced(id, baoStrmToBytes);
1.72 + } else /*if (commit)*/ {
1.73 + throw writeError;
1.74 + }
1.75 + }
1.76 + }
1.77
1.78 - // Last, add what needs adding
1.79 - Iterator newIter = cache.getNew().iterator();
1.80 - while (newIter.hasNext()) {
1.81 - Map.Entry entry = (Map.Entry) newIter.next();
1.82 - id = (MOFID) entry.getKey();
1.83 - value = entry.getValue();
1.84 - writeError = addRecord(id, value);
1.85 - if (writeError == null) {
1.86 - transactionCache.addInserted(id, baoStrmToBytes);
1.87 - }
1.88 - else /*if (commit)*/ {
1.89 - throw writeError;
1.90 - }
1.91 -// else if (loggingStream != null) {
1.92 -// loggingStream.println("Error writing streamable: " +
1.93 -// writeError.toString());
1.94 -// }
1.95 - }
1.96 + // Last, add what needs adding
1.97 + if ((modStatus & MDRCache.M_NEW) != 0) {
1.98 + Iterator newIter = cache.getNew().iterator();
1.99 + while (newIter.hasNext()) {
1.100 + Map.Entry entry = (Map.Entry) newIter.next();
1.101 + id = (MOFID) entry.getKey();
1.102 + value = entry.getValue();
1.103 + writeError = addRecord(id, value);
1.104 + if (writeError == null) {
1.105 + transactionCache.addInserted(id, baoStrmToBytes);
1.106 + } else /*if (commit)*/ {
1.107 + throw writeError;
1.108 + }
1.109 + }
1.110 + }
1.111 +
1.112 + modStatus = cache.getModStatus();
1.113 + }
1.114
1.115 if (classIndexChanged) {
1.116 writeError = replaceRecord(BtreeFactory.classIndexId, classIndex);
1.117 @@ -1053,10 +1054,9 @@
1.118 classIndex = (CounterIndex)getIfExists(BtreeFactory.classIndexId);
1.119 if (classIndex == null) {
1.120 classIndex = new CounterIndex();
1.121 - add(BtreeFactory.classIndexId, classIndex);
1.122 -
1.123 // pre-load the class for the class index itself
1.124 classIndex.add(CLASS_INDEX_TYPE);
1.125 + add(BtreeFactory.classIndexId, classIndex);
1.126 }
1.127 else {
1.128 Iterator itr = classIndex.iterator();
2.1 --- a/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/MDRCache.java Fri Oct 29 16:59:26 2004 +0000
2.2 +++ b/mdr/src/org/netbeans/mdr/persistence/btreeimpl/btreestorage/MDRCache.java Sat Oct 30 11:57:20 2004 +0000
2.3 @@ -83,6 +83,9 @@
2.4 private int localThreshhold;
2.5 private int lastLocalSize = 0;
2.6
2.7 + public static final int M_DELETED = 1;
2.8 + public static final int M_DIRTY = 2;
2.9 + public static final int M_NEW = 4;
2.10
2.11 /* caching statistics */
2.12 private static int hits;
2.13 @@ -197,8 +200,8 @@
2.14 /** returns true if the cache contains any changed objects
2.15 * @return true if any objects have been modified or deleted
2.16 */
2.17 - public synchronized boolean hasChanges() {
2.18 - return dirty.size() + newOnes.size() + deleted.size() > 0;
2.19 + public synchronized int getModStatus() {
2.20 + return (deleted.isEmpty() ? 0 : M_DELETED) + (dirty.isEmpty() ? 0 : M_DIRTY) + (newOnes.isEmpty() ? 0 : M_NEW);
2.21 }
2.22
2.23
3.1 --- a/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java Fri Oct 29 16:59:26 2004 +0000
3.2 +++ b/mdr/src/org/netbeans/mdr/storagemodel/MdrStorage.java Sat Oct 30 11:57:20 2004 +0000
3.3 @@ -487,7 +487,7 @@
3.4 // register this storage instance into the table of instances
3.5 instances.put(storage, this);
3.6 this.nullMofId.put(storageId, nullMofId);
3.7 - assert this.storages.put(storageId, storage) == null;
3.8 + this.storages.put(storageId, storage);
3.9 return result;
3.10 }
3.11