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<UUID, Entry> 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 {
+ }
+}