jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1504471 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java
Date Thu, 18 Jul 2013 13:50:17 GMT
Author: jukka
Date: Thu Jul 18 13:50:17 2013
New Revision: 1504471

URL: http://svn.apache.org/r1504471
Log:
OAK-630: SegmentMK: Implement compareAgainstBaseState

Add support for MapBranch-to-MapBranch comparisons

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java?rev=1504471&r1=1504470&r2=1504471&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapBranch.java
Thu Jul 18 13:50:17 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Iterables.concat;
 import static com.google.common.collect.Iterables.transform;
 import static java.lang.Integer.bitCount;
@@ -108,4 +109,48 @@ class MapBranch extends MapRecord {
                 }));
     }
 
+    @Override
+    boolean compare(MapRecord base, MapDiff diff) {
+        if (base instanceof MapBranch) {
+            return compare((MapBranch) base, diff);
+        } else {
+            return super.compare(base, diff);
+        }
+    }
+
+    private boolean compare(MapBranch before, MapDiff diff) {
+        MapBranch after = this;
+        checkState(after.level == before.level);
+
+        RecordId[] afterBuckets = after.getBuckets();
+        RecordId[] beforeBuckets = before.getBuckets();
+        for (int i = 0; i < BUCKETS_PER_LEVEL; i++) {
+            if (afterBuckets[i] == null) {
+                if (beforeBuckets[i] != null) {
+                    MapRecord map = MapRecord.readMap(store, beforeBuckets[i]);
+                    for (MapEntry entry : map.getEntries()) {
+                        if (!diff.entryDeleted(entry.getName(), entry.getValue())) {
+                            return false;
+                        }
+                    }
+                }
+            } else if (beforeBuckets[i] == null) {
+                MapRecord map = MapRecord.readMap(store, afterBuckets[i]);
+                for (MapEntry entry : map.getEntries()) {
+                    if (!diff.entryAdded(entry.getName(), entry.getValue())) {
+                        return false;
+                    }
+                }
+            } else if (!afterBuckets[i].equals(beforeBuckets[i])) {
+                MapRecord afterMap = MapRecord.readMap(store, afterBuckets[i]);
+                MapRecord beforeMap = MapRecord.readMap(store, beforeBuckets[i]);
+                if (!afterMap.compare(beforeMap, diff)) {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
 }



Mime
View raw message