You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2015/05/05 14:47:14 UTC

svn commit: r1677806 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/ main/java/org/apache/jackrabbit/oak/plugins/document/util/ main/java/org/apache/jackrabbit/oak/plugins/observation/ test/java/org/apache...

Author: mreutegg
Date: Tue May  5 12:47:14 2015
New Revision: 1677806

URL: http://svn.apache.org/r1677806
Log:
OAK-2685: Track root state revision when reading the tree

Commit missing part of the patch

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java   (with props)
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ContentChangeInfo.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ContentChangeInfoProvider.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java?rev=1677806&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java Tue May  5 12:47:14 2015
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.collect.Iterables;
+
+import org.apache.jackrabbit.oak.cache.CacheStats;
+
+/**
+ * Implements a tiered diff cache which consists of a {@link LocalDiffCache} and
+ * a {@link MemoryDiffCache}.
+ */
+class TieredDiffCache implements DiffCache {
+
+    private final LocalDiffCache localCache;
+    private final MemoryDiffCache memoryCache;
+
+    TieredDiffCache(DocumentMK.Builder builder) {
+        this.localCache = new LocalDiffCache(builder);
+        this.memoryCache = new MemoryDiffCache(builder);
+    }
+
+    @Override
+    public String getChanges(@Nonnull Revision from,
+                             @Nonnull Revision to,
+                             @Nonnull String path,
+                             @Nullable Loader loader) {
+        // check local first without loader
+        String changes = localCache.getChanges(from, to, path, null);
+        if (changes != null) {
+            return changes;
+        }
+        return memoryCache.getChanges(from, to, path, loader);
+    }
+
+    /**
+     * Creates a new entry in the {@link LocalDiffCache} only!
+     *
+     * @param from the from revision.
+     * @param to the to revision.
+     * @return the new entry.
+     */
+    @Nonnull
+    @Override
+    public Entry newEntry(@Nonnull Revision from, @Nonnull Revision to) {
+        return localCache.newEntry(from, to);
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<CacheStats> getStats() {
+        return Iterables.concat(localCache.getStats(), memoryCache.getStats());
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java?rev=1677806&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java Tue May  5 12:47:14 2015
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document.util;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.cache.CacheValue;
+import org.apache.jackrabbit.oak.plugins.document.Revision;
+import org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A cache key implementation which consists of two {@link Revision}s.
+ */
+public final class RevisionsKey implements CacheValue, Comparable<RevisionsKey> {
+
+    private final Revision r1, r2;
+
+    public RevisionsKey(Revision r1, Revision r2) {
+        this.r1 = checkNotNull(r1);
+        this.r2 = checkNotNull(r2);
+    }
+
+    @Override
+    public int getMemory() {
+        return 88;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof RevisionsKey)) {
+            return false;
+        }
+        RevisionsKey other = (RevisionsKey) obj;
+        return r1.equals(other.r1) && r2.equals(other.r2);
+    }
+
+    @Override
+    public int hashCode() {
+        return r1.hashCode() ^ r2.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return asString();
+    }
+
+    public String asString() {
+        return r1 + "/" + r2;
+    }
+
+    public int compareTo(@Nonnull RevisionsKey k) {
+        int c = StableRevisionComparator.INSTANCE.compare(r1, k.r1);
+        if (c != 0) {
+            return c;
+        }
+        return StableRevisionComparator.INSTANCE.compare(r2, k.r2);
+    }
+
+    public static RevisionsKey fromString(String s) {
+        int idx = s.indexOf('/');
+        if (idx == -1) {
+            throw new IllegalArgumentException(s);
+        }
+        return new RevisionsKey(
+                Revision.fromString(s.substring(0, idx)),
+                Revision.fromString(s.substring(idx + 1)));
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java?rev=1677806&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java Tue May  5 12:47:14 2015
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document.util;
+
+import org.apache.jackrabbit.oak.plugins.document.Revision;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * <code>RevisionsKeyTest</code>...
+ */
+public class RevisionsKeyTest {
+
+    @Test
+    public void fromAsString() {
+        RevisionsKey k1 = new RevisionsKey(
+                new Revision(1, 0, 1), new Revision(2, 1, 2));
+        RevisionsKey k2 = RevisionsKey.fromString(k1.asString());
+        assertEquals(k1, k2);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native