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 ju...@apache.org on 2013/02/20 14:58:10 UTC
svn commit: r1448169 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment:
OffsetCache.java Segment.java
Author: jukka
Date: Wed Feb 20 13:58:10 2013
New Revision: 1448169
URL: http://svn.apache.org/r1448169
Log:
OAK-593: Segment-based MK
Start moving the string and template caches from SegmentReader to Segments
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/OffsetCache.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/OffsetCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/OffsetCache.java?rev=1448169&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/OffsetCache.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/OffsetCache.java Wed Feb 20 13:58:10 2013
@@ -0,0 +1,61 @@
+/*
+ * 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.segment;
+
+import java.util.Arrays;
+
+abstract class OffsetCache<T> {
+
+ private static final int SIZE_INCREMENT = 1024;
+
+ private static final int[] NO_OFFSETS = new int[0];
+
+ private static final Object[] NO_VALUES = new Object[0];
+
+ private int length = 0;
+
+ private int[] offsets = NO_OFFSETS;
+
+ private Object[] values = NO_VALUES;
+
+ @SuppressWarnings("unchecked")
+ public synchronized T get(int offset) {
+ int i = Arrays.binarySearch(offsets, 0, length, offset);
+ if (i < 0) {
+ i = ~i;
+ if (length < offsets.length) {
+ System.arraycopy(offsets, i, offsets, i + 1, length - i);
+ System.arraycopy(values, i, values, i + 1, length - i);
+ } else {
+ int[] newOffsets = new int[length + SIZE_INCREMENT];
+ System.arraycopy(offsets, 0, newOffsets, 0, i);
+ System.arraycopy(offsets, i, newOffsets, i + 1, length - i);
+ offsets = newOffsets;
+ Object[] newValues = new Object[length + SIZE_INCREMENT];
+ System.arraycopy(values, 0, newValues, 0, i);
+ System.arraycopy(values, i, newValues, i + 1, length - i);
+ values = newValues;
+ }
+ offsets[i] = offset;
+ values[i] = load(offset);
+ }
+ return (T) values[i];
+ }
+
+ protected abstract T load(int offset);
+
+}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java?rev=1448169&r1=1448168&r2=1448169&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Segment.java Wed Feb 20 13:58:10 2013
@@ -87,6 +87,20 @@ class Segment {
private final UUID[] uuids;
+ private final OffsetCache<String> strings = new OffsetCache<String>() {
+ @Override
+ protected String load(int offset) {
+ return null;
+ }
+ };
+
+ private final OffsetCache<NodeTemplate> templates = new OffsetCache<NodeTemplate>() {
+ @Override
+ protected NodeTemplate load(int offset) {
+ return null;
+ }
+ };
+
Segment(UUID uuid, byte[] data, UUID[] uuids) {
this.uuid = uuid;
this.data = data;