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 md...@apache.org on 2017/03/01 17:25:40 UTC

svn commit: r1784994 - in /jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment: SegmentIdProvider.java SegmentTracker.java

Author: mduerig
Date: Wed Mar  1 17:25:40 2017
New Revision: 1784994

URL: http://svn.apache.org/viewvc?rev=1784994&view=rev
Log:
OAK-3690: Decouple SegmentBufferWriter from SegmentStore
Introduce SegmentIdProvider interface and implement it by SegmentTracker

Added:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentIdProvider.java
Modified:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentTracker.java

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentIdProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentIdProvider.java?rev=1784994&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentIdProvider.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentIdProvider.java Wed Mar  1 17:25:40 2017
@@ -0,0 +1,62 @@
+/*
+ * 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.segment;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Instances of this class provides {@link SegmentId} instances of a given
+ * {@link SegmentStore} and creates new {@code SegmentId} instances on the fly
+ * if required.
+ */
+public interface SegmentIdProvider {
+
+    /**
+     * @return The number of distinct segment ids this provider is tracking.
+     */
+    int getSegmentIdCount();
+
+    /**
+     * Provide a {@code SegmentId} represented by the given MSB/LSB pair.
+     *
+     * @param msb The most significant bits of the {@code SegmentId}.
+     * @param lsb The least significant bits of the {@code SegmentId}.
+     * @return A non-{@code null} instance of {@code SegmentId}.
+     */
+    @Nonnull
+    SegmentId newSegmentId(long msb, long lsb);
+
+
+    /**
+     * Provide a {@code SegmentId} for a segment of type "bulk".
+     *
+     * @return A non-{@code null} instance of {@code SegmentId}.
+     */
+    @Nonnull
+    SegmentId newDataSegmentId();
+
+
+    /**
+     * Provide a {@code SegmentId} for a segment of type "data".
+     *
+     * @return A non-{@code null} instance of {@code SegmentId}.
+     */
+    @Nonnull
+    SegmentId newBulkSegmentId();
+}

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentTracker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentTracker.java?rev=1784994&r1=1784993&r2=1784994&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentTracker.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentTracker.java Wed Mar  1 17:25:40 2017
@@ -35,7 +35,7 @@ import com.google.common.base.Supplier;
  * that are currently kept in memory and factory for creating {@link SegmentId}
  * instances.
  */
-public class SegmentTracker {
+public class SegmentTracker implements SegmentIdProvider {
     private static final long MSB_MASK = ~(0xfL << 12);
 
     private static final long VERSION = (0x4L << 12);
@@ -93,6 +93,11 @@ public class SegmentTracker {
         };
     }
 
+    @Override
+    public int getSegmentIdCount() {
+        return segmentCounter.get();
+    }
+
     /**
      * Returns all segment identifiers that are currently referenced in memory.
      *
@@ -114,6 +119,7 @@ public class SegmentTracker {
      * @param lsb   least  significant bits of the segment id
      * @return the segment id
      */
+    @Override
     @Nonnull
     public SegmentId newSegmentId(long msb, long lsb) {
         int index = ((int) msb) & (tables.length - 1);
@@ -125,6 +131,7 @@ public class SegmentTracker {
      *
      * @return the segment id
      */
+    @Override
     @Nonnull
     public SegmentId newDataSegmentId() {
         return newSegmentId(DATA);
@@ -135,6 +142,7 @@ public class SegmentTracker {
      *
      * @return the segment id
      */
+    @Override
     @Nonnull
     public SegmentId newBulkSegmentId() {
         return newSegmentId(BULK);