Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DB918EF20 for ; Wed, 20 Feb 2013 13:58:32 +0000 (UTC) Received: (qmail 42075 invoked by uid 500); 20 Feb 2013 13:58:32 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 42010 invoked by uid 500); 20 Feb 2013 13:58:31 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 41984 invoked by uid 99); 20 Feb 2013 13:58:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2013 13:58:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2013 13:58:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D9309238890B; Wed, 20 Feb 2013 13:58:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1448169 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: OffsetCache.java Segment.java Date: Wed, 20 Feb 2013 13:58:10 -0000 To: oak-commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130220135810.D9309238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 { + + 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 strings = new OffsetCache() { + @Override + protected String load(int offset) { + return null; + } + }; + + private final OffsetCache templates = new OffsetCache() { + @Override + protected NodeTemplate load(int offset) { + return null; + } + }; + Segment(UUID uuid, byte[] data, UUID[] uuids) { this.uuid = uuid; this.data = data;