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 66A5F10CBC for ; Thu, 12 Sep 2013 00:30:43 +0000 (UTC) Received: (qmail 39974 invoked by uid 500); 12 Sep 2013 00:30:43 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 39956 invoked by uid 500); 12 Sep 2013 00:30:43 -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 39948 invoked by uid 99); 12 Sep 2013 00:30:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Sep 2013 00:30:42 +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; Thu, 12 Sep 2013 00:30:41 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 03A07238890D; Thu, 12 Sep 2013 00:30:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1522094 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file: ClassicFile.java MappedFile.java SegmentFile.java Date: Thu, 12 Sep 2013 00:30:20 -0000 To: oak-commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130912003021.03A07238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Thu Sep 12 00:30:20 2013 New Revision: 1522094 URL: http://svn.apache.org/r1522094 Log: OAK-1001: SegmentMK: 32bit support for the file backend Extract basic file handling code to separate classes. WIP. Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/ClassicFile.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/MappedFile.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/SegmentFile.java Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/ClassicFile.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/ClassicFile.java?rev=1522094&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/ClassicFile.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/ClassicFile.java Thu Sep 12 00:30:20 2013 @@ -0,0 +1,55 @@ +/* + * 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.file; + +import static com.google.common.base.Preconditions.checkState; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; + +class ClassicFile extends SegmentFile { + + private final RandomAccessFile file; + + ClassicFile(File file) throws IOException { + this.file = new RandomAccessFile(file, "rw"); + } + + @Override + protected synchronized ByteBuffer read(int position, int length) + throws IOException { + ByteBuffer entry = ByteBuffer.allocate(length); + file.seek(position); + file.readFully(entry.array()); + return entry; + } + + @Override + protected int length() throws IOException { + long length = file.length(); + checkState(length < Integer.MAX_VALUE); + return (int) length; + } + + @Override + void close() throws IOException { + file.close(); + } + +} Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/MappedFile.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/MappedFile.java?rev=1522094&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/MappedFile.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/MappedFile.java Thu Sep 12 00:30:20 2013 @@ -0,0 +1,52 @@ +/* + * 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.file; + +import static java.nio.channels.FileChannel.MapMode.READ_WRITE; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; + +class MappedFile extends SegmentFile { + + private final ByteBuffer buffer; + + MappedFile(File file) throws IOException { + RandomAccessFile f = new RandomAccessFile(file, "rw"); + try { + buffer = f.getChannel().map(READ_WRITE, 0, f.length()); + } finally { + f.close(); + } + } + + @Override + protected int length() { + return buffer.limit(); + } + + @Override + protected ByteBuffer read(int position, int length) { + ByteBuffer entry = buffer.asReadOnlyBuffer(); + entry.position(position); + entry.limit(position + length); + return entry; + } + +} Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/SegmentFile.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/SegmentFile.java?rev=1522094&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/SegmentFile.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/SegmentFile.java Thu Sep 12 00:30:20 2013 @@ -0,0 +1,59 @@ +/* + * 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.file; + +import static java.util.Collections.emptyMap; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Map; +import java.util.UUID; + +abstract class SegmentFile { + + protected static class Entry { + + int position; + + int length; + + Entry(int position, int length) { + this.position = position; + this.length = length; + } + + } + + private volatile Map entries = emptyMap(); + + ByteBuffer readEntry(UUID id) throws IOException { + Entry entry = entries.get(id); + if (entry != null) { + return read(entry.position, entry.length); + } else { + return null; + } + } + + protected abstract int length() throws IOException; + + protected abstract ByteBuffer read(int position, int length) + throws IOException; + + void close() throws IOException { + } +}