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 fr...@apache.org on 2018/04/19 12:05:53 UTC

svn commit: r1829528 [1/2] - in /jackrabbit/oak/trunk/oak-segment-tar/src: main/java/org/apache/jackrabbit/oak/segment/ main/java/org/apache/jackrabbit/oak/segment/file/ main/java/org/apache/jackrabbit/oak/segment/file/proc/ main/java/org/apache/jackra...

Author: frm
Date: Thu Apr 19 12:05:52 2018
New Revision: 1829528

URL: http://svn.apache.org/viewvc?rev=1829528&view=rev
Log:
OAK-7416 - Implement a proc tree for the Segment Store

Added:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreProcBackend.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/AbstractNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/NodeUtils.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/Proc.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentBlob.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentEntry.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/TarNode.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ProcTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNodeTest.java   (with props)
    jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/TarNodeTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
    jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java?rev=1829528&r1=1829527&r2=1829528&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/Segment.java Thu Apr 19 12:05:52 2018
@@ -381,7 +381,7 @@ public class Segment {
      * @return the segment meta data
      */
     @CheckForNull
-    String getSegmentInfo() {
+    public String getSegmentInfo() {
         if (info == null && id.isDataSegmentId()) {
             info = readString(recordNumbers.iterator().next().getRecordNumber());
         }
@@ -563,9 +563,8 @@ public class Segment {
                 }
                 for (Entry entry : recordNumbers) {
                     int offset = entry.getOffset();
-                    int address = data.size() - (MAX_SEGMENT_SIZE - offset);
                     writer.format("%10s record %08x: %08x @ %08x%n",
-                                  entry.getType(), entry.getRecordNumber(), offset, address);
+                                  entry.getType(), entry.getRecordNumber(), offset, getAddress(offset));
                 }
             }
             writer.println("--------------------------------------------------------------------------");
@@ -584,6 +583,15 @@ public class Segment {
     }
 
     /**
+     * Convert an offset into an address.
+     * @param offset
+     * @return  the address corresponding the {@code offset}
+     */
+    public int getAddress(int offset) {
+        return data.size() - (MAX_SEGMENT_SIZE - offset);
+    }
+
+    /**
      * A consumer of record data.
      */
     public interface RecordConsumer {

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java?rev=1829528&r1=1829527&r2=1829528&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java Thu Apr 19 12:05:52 2018
@@ -40,15 +40,16 @@ import com.google.common.base.Predicate;
 import org.apache.jackrabbit.oak.segment.CacheWeights.NodeCacheWeigher;
 import org.apache.jackrabbit.oak.segment.CacheWeights.StringCacheWeigher;
 import org.apache.jackrabbit.oak.segment.CacheWeights.TemplateCacheWeigher;
-import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
-import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration;
 import org.apache.jackrabbit.oak.segment.RecordCache;
 import org.apache.jackrabbit.oak.segment.SegmentNotFoundExceptionListener;
 import org.apache.jackrabbit.oak.segment.WriterCacheManager;
 import org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.tar.GCGeneration;
+import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
 import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor;
 import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter;
-import org.apache.jackrabbit.oak.segment.file.tar.TarPersistence;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
 import org.apache.jackrabbit.oak.spi.blob.BlobStore;
 import org.apache.jackrabbit.oak.spi.gc.DelegatingGCMonitor;
 import org.apache.jackrabbit.oak.spi.gc.GCMonitor;
@@ -324,6 +325,10 @@ public class FileStoreBuilder {
         return this;
     }
 
+    public Backend buildProcBackend(AbstractFileStore fileStore) throws IOException {
+        return new FileStoreProcBackend(fileStore, persistence);
+    }
+
     /**
      * Create a new {@link FileStore} instance with the settings specified in this
      * builder. If none of the {@code with} methods have been called before calling

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreProcBackend.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreProcBackend.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreProcBackend.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreProcBackend.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,340 @@
+/*
+ * 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.file;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+
+import org.apache.jackrabbit.oak.segment.RecordId;
+import org.apache.jackrabbit.oak.segment.RecordType;
+import org.apache.jackrabbit.oak.segment.SegmentId;
+import org.apache.jackrabbit.oak.segment.SegmentNotFoundException;
+import org.apache.jackrabbit.oak.segment.SegmentVersion;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.spi.monitor.FileStoreMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitorAdapter;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveManager;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader;
+import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class FileStoreProcBackend implements Backend {
+
+    private final AbstractFileStore fileStore;
+
+    private final SegmentNodeStorePersistence persistence;
+
+    private final SegmentArchiveManager archiveManager;
+
+    FileStoreProcBackend(AbstractFileStore fileStore, SegmentNodeStorePersistence persistence) throws IOException {
+        this.fileStore = fileStore;
+        this.persistence = persistence;
+        this.archiveManager = persistence.createArchiveManager(true, new IOMonitorAdapter(), new FileStoreMonitorAdapter());
+    }
+
+    @Override
+    public boolean tarExists(String name) {
+        try {
+            return archiveManager.listArchives().contains(name);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public Optional<Long> getTarSize(String name) {
+        try (SegmentArchiveReader reader = archiveManager.open(name)) {
+            return Optional.ofNullable(reader).map(SegmentArchiveReader::length);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public Iterable<String> getTarNames() {
+        try {
+            return archiveManager.listArchives();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public boolean segmentExists(String name, String segmentId) {
+        try (SegmentArchiveReader reader = archiveManager.open(name)) {
+            if (reader == null) {
+                return false;
+            }
+            return segmentExists(reader, UUID.fromString(segmentId));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private boolean segmentExists(SegmentArchiveReader reader, UUID id) {
+        return reader.containsSegment(id.getMostSignificantBits(), id.getLeastSignificantBits());
+    }
+
+    @Override
+    public Iterable<String> getSegmentIds(String name) {
+        try (SegmentArchiveReader reader = archiveManager.open(name)) {
+            if (reader == null) {
+                return Collections.emptyList();
+            }
+            return getSegmentIds(reader);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private Iterable<String> getSegmentIds(SegmentArchiveReader reader) {
+        List<String> ids = new ArrayList<>();
+        for (SegmentArchiveEntry entry : reader.listSegments()) {
+            ids.add(new UUID(entry.getMsb(), entry.getLsb()).toString());
+        }
+        return ids;
+    }
+
+    private Optional<org.apache.jackrabbit.oak.segment.Segment> readSegment(String id) {
+        return readSegment(UUID.fromString(id));
+    }
+
+    private Optional<org.apache.jackrabbit.oak.segment.Segment> readSegment(UUID id) {
+        return readSegment(fileStore.getSegmentIdProvider().newSegmentId(
+            id.getMostSignificantBits(),
+            id.getLeastSignificantBits()
+        ));
+    }
+
+    private Optional<org.apache.jackrabbit.oak.segment.Segment> readSegment(SegmentId id) {
+        try {
+            return Optional.of(fileStore.readSegment(id));
+        } catch (SegmentNotFoundException e) {
+            return Optional.empty();
+        }
+    }
+
+    @Override
+    public Optional<Segment> getSegment(String id) {
+        return readSegment(id).map(segment -> new Segment() {
+
+            @Override
+            public int getGeneration() {
+                return segment.getGcGeneration().getGeneration();
+            }
+
+            @Override
+            public int getFullGeneration() {
+                return segment.getGcGeneration().getFullGeneration();
+            }
+
+            @Override
+            public boolean isCompacted() {
+                return segment.getGcGeneration().isCompacted();
+            }
+
+            @Override
+            public int getLength() {
+                return segment.size();
+            }
+
+            @Override
+            public int getVersion() {
+                return SegmentVersion.asByte(segment.getSegmentVersion());
+            }
+
+            @Override
+            public boolean isDataSegment() {
+                return segment.getSegmentId().isDataSegmentId();
+            }
+
+            @Override
+            public Optional<String> getInfo() {
+                return Optional.ofNullable(segment.getSegmentInfo());
+            }
+
+        });
+    }
+
+    @Override
+    public Optional<InputStream> getSegmentData(String segmentId) {
+        return readSegment(segmentId).map(segment -> {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+            try {
+                segment.writeTo(out);
+            } catch (IOException e) {
+                return null;
+            }
+
+            return new ByteArrayInputStream(out.toByteArray());
+        });
+    }
+
+    @Override
+    public Optional<Iterable<String>> getSegmentReferences(String segmentId) {
+        return readSegment(segmentId).map(segment -> {
+            List<String> references = new ArrayList<>(segment.getReferencedSegmentIdCount());
+
+            for (int i = 0; i < segment.getReferencedSegmentIdCount(); i++) {
+                references.add(segment.getReferencedSegmentId(i).toString());
+            }
+
+            return references;
+        });
+    }
+
+    @Override
+    public Optional<Iterable<Record>> getSegmentRecords(String segmentId) {
+        return readSegment(segmentId).map(segment -> {
+            List<Record> records = new ArrayList<>();
+
+            segment.forEachRecord((number, type, offset) -> {
+                records.add(new Record() {
+
+                    @Override
+                    public int getNumber() {
+                        return number;
+                    }
+
+                    @Override
+                    public String getSegmentId() {
+                        return segmentId;
+                    }
+
+                    @Override
+                    public int getOffset() {
+                        return offset;
+                    }
+
+                    @Override
+                    public int getAddress() {
+                        return segment.getAddress(offset);
+                    }
+
+                    @Override
+                    public String getType() {
+                        return type.name();
+                    }
+
+                    @Override
+                    public Optional<NodeState> getRoot() {
+                        if (RecordType.NODE == type) {
+                            RecordId id = new RecordId(segment.getSegmentId(), number);
+                            return Optional.of(fileStore.getReader().readNode(id));
+                        } else {
+                            return Optional.empty();
+                        }
+                    }
+                });
+            });
+
+            return records;
+        });
+    }
+
+    @Override
+    public boolean commitExists(String handle) {
+        long timestamp = Long.parseLong(handle);
+
+        try (JournalReader reader = new JournalReader(persistence.getJournalFile())) {
+            for (JournalEntry entry : iterable(reader)) {
+                if (entry.getTimestamp() == timestamp) {
+                    return true;
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        return false;
+    }
+
+    private <T> Iterable<T> iterable(Iterator<T> i) {
+        return () -> i;
+    }
+
+    @Override
+    public Iterable<String> getCommitHandles() {
+        try (JournalReader reader = new JournalReader(persistence.getJournalFile())) {
+            List<String> handles = new ArrayList<>();
+            for (JournalEntry entry : iterable(reader)) {
+                handles.add(Long.toString(entry.getTimestamp()));
+            }
+            return handles;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public Optional<Commit> getCommit(String handle) {
+        JournalEntry entry;
+
+        try (JournalReader reader = new JournalReader(persistence.getJournalFile())) {
+            entry = getEntry(reader, Long.parseLong(handle));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        if (entry == null) {
+            return Optional.empty();
+        }
+
+        return Optional.of(new Commit() {
+
+            @Override
+            public long getTimestamp() {
+                return entry.getTimestamp();
+            }
+
+            @Override
+            public String getRevision() {
+                return entry.getRevision();
+            }
+
+            @Override
+            public Optional<NodeState> getRoot() {
+                RecordId id = RecordId.fromString(fileStore.getSegmentIdProvider(), entry.getRevision());
+                return Optional.of(fileStore.getReader().readNode(id));
+            }
+
+        });
+    }
+
+    private JournalEntry getEntry(JournalReader reader, long timestamp) {
+        for (JournalEntry entry : iterable(reader)) {
+            if (entry.getTimestamp() == timestamp) {
+                return entry;
+            }
+        }
+        return null;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreProcBackend.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/AbstractNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/AbstractNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/AbstractNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/AbstractNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,68 @@
+/*
+ * 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.file.proc;
+
+import java.util.Collections;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+abstract class AbstractNode extends AbstractNodeState {
+
+    @Override
+    public boolean exists() {
+        return true;
+    }
+
+    @Override
+    public boolean hasChildNode(@Nonnull String name) {
+        return NodeUtils.hasChildNode(getChildNodeEntries(), name);
+    }
+
+    @Nonnull
+    @Override
+    public NodeState getChildNode(@Nonnull String name) throws IllegalArgumentException {
+        return NodeUtils.getChildNode(getChildNodeEntries(), name);
+    }
+
+    @Nonnull
+    @Override
+    public NodeBuilder builder() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return Collections.emptyList();
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        return Collections.emptyList();
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/AbstractNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNode.java Thu Apr 19 12:05:52 2018
@@ -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.segment.file.proc;
+
+import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
+
+import java.util.Arrays;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+
+class BulkSegmentNode extends AbstractNode {
+
+    private final Backend backend;
+
+    private final String segmentId;
+
+    private final Segment segment;
+
+    BulkSegmentNode(Backend backend, String segmentId, Segment segment) {
+        this.backend = backend;
+        this.segmentId = segmentId;
+        this.segment = segment;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return Arrays.asList(
+            createProperty("length", (long) segment.getLength(), Type.LONG),
+            createProperty("data", new SegmentBlob(backend, segmentId, segment), Type.BINARY),
+            createProperty("isDataSegment", false, Type.BOOLEAN),
+            createProperty("id", segmentId, Type.STRING),
+            createProperty("exists", true, Type.BOOLEAN)
+        );
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,69 @@
+/*
+ * 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.file.proc;
+
+import static java.util.Collections.emptySet;
+import static java.util.Collections.singleton;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.collect.Lists;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Commit;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class CommitNode extends AbstractNode {
+
+    private final Proc.Backend backend;
+
+    private final String handle;
+
+    CommitNode(Proc.Backend backend, String handle) {
+        this.backend = backend;
+        this.handle = handle;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return backend.getCommit(handle).map(this::getProperties).orElse(emptySet());
+    }
+
+    private Iterable<PropertyState> getProperties(Commit entry) {
+        return Lists.newArrayList(
+            PropertyStates.createProperty("timestamp", entry.getTimestamp(), Type.LONG),
+            PropertyStates.createProperty("revision", entry.getRevision())
+        );
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        return backend.getCommit(handle)
+            .flatMap(Proc.Backend.Commit::getRoot)
+            .map(r -> singleton(new MemoryChildNodeEntry("root", r)))
+            .orElse(emptySet());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,75 @@
+/*
+ * 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.file.proc;
+
+import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
+
+import java.util.Arrays;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+
+class DataSegmentNode extends AbstractNode {
+
+    private final Backend backend;
+
+    private final String segmentId;
+
+    private final Segment segment;
+
+    DataSegmentNode(Backend backend, String segmentId, Segment segment) {
+        this.backend = backend;
+        this.segmentId = segmentId;
+        this.segment = segment;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return Arrays.asList(
+            createProperty("generation", (long) segment.getGeneration(), Type.LONG),
+            createProperty("fullGeneration", (long) segment.getFullGeneration(), Type.LONG),
+            createProperty("compacted", segment.isCompacted(), Type.BOOLEAN),
+            createProperty("length", (long) segment.getLength(), Type.LONG),
+            createProperty("data", new SegmentBlob(backend, segmentId, segment), Type.BINARY),
+            createProperty("version", (long) segment.getVersion(), Type.LONG),
+            createProperty("isDataSegment", true, Type.BOOLEAN),
+            createProperty("info", segment.getInfo().orElse(""), Type.STRING),
+            createProperty("id", segmentId, Type.STRING),
+            createProperty("exists", true, Type.BOOLEAN)
+        );
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        return Arrays.asList(
+            new MemoryChildNodeEntry("references", new ReferencesNode(backend, segmentId)),
+            new MemoryChildNodeEntry("records", new RecordsNode(backend, segmentId))
+        );
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,65 @@
+/*
+ * 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.file.proc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class JournalNode extends AbstractNode {
+
+    private final Proc.Backend backend;
+
+    JournalNode(Proc.Backend backend) {
+        this.backend = backend;
+    }
+
+    @Override
+    public boolean hasChildNode(@Nonnull String name) {
+        return backend.commitExists(name);
+    }
+
+    @Nonnull
+    @Override
+    public NodeState getChildNode(@Nonnull String name) throws IllegalArgumentException {
+        if (backend.commitExists(name)) {
+            return new CommitNode(backend, name);
+        }
+        return EmptyNodeState.MISSING_NODE;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        List<ChildNodeEntry> entries = new ArrayList<>();
+
+        for (String handle : backend.getCommitHandles()) {
+            entries.add(new MemoryChildNodeEntry(handle, new CommitNode(backend, handle)));
+        }
+
+        return entries;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/JournalNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,48 @@
+/*
+ * 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.file.proc;
+
+import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
+
+import java.util.Arrays;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+
+class MissingSegmentNode extends AbstractNode {
+
+    private final String segmentId;
+
+    MissingSegmentNode(String segmentId) {
+        this.segmentId = segmentId;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return Arrays.asList(
+            createProperty("id", segmentId, Type.STRING),
+            createProperty("exists", false, Type.BOOLEAN)
+        );
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/MissingSegmentNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/NodeUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/NodeUtils.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/NodeUtils.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/NodeUtils.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,48 @@
+/*
+ * 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.file.proc;
+
+import java.util.stream.StreamSupport;
+
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class NodeUtils {
+
+    private NodeUtils() {
+        // Prevent instantiation.
+    }
+
+    static boolean hasChildNode(Iterable<? extends ChildNodeEntry> entries, String name) {
+        return StreamSupport.stream(entries.spliterator(), false)
+            .map(ChildNodeEntry::getName)
+            .anyMatch(name::equals);
+    }
+
+    static NodeState getChildNode(Iterable<? extends ChildNodeEntry> entries, String name) {
+        return StreamSupport.stream(entries.spliterator(), false)
+            .filter(e -> e.getName().equals(name))
+            .map(ChildNodeEntry::getNodeState)
+            .findFirst()
+            .orElse(EmptyNodeState.MISSING_NODE);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/NodeUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/Proc.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/Proc.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/Proc.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/Proc.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,112 @@
+/*
+ * 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.file.proc;
+
+import java.io.InputStream;
+import java.util.Optional;
+
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+public class Proc {
+
+    public interface Backend {
+
+        interface Segment {
+
+            int getGeneration();
+
+            int getFullGeneration();
+
+            boolean isCompacted();
+
+            int getLength();
+
+            int getVersion();
+
+            boolean isDataSegment();
+
+            Optional<String> getInfo();
+
+        }
+
+        interface Commit {
+
+            long getTimestamp();
+
+            String getRevision();
+
+            Optional<NodeState> getRoot();
+
+        }
+
+        interface Record {
+            int getNumber();
+
+            String getSegmentId();
+
+            int getOffset();
+
+            int getAddress();
+
+            String getType();
+
+            Optional<NodeState> getRoot();
+        }
+
+        boolean tarExists(String name);
+
+        Optional<Long> getTarSize(String name);
+
+        Iterable<String> getTarNames();
+
+        boolean segmentExists(String name, String segmentId);
+
+        Iterable<String> getSegmentIds(String name);
+
+        Optional<Segment> getSegment(String segmentId);
+
+        Optional<InputStream> getSegmentData(String segmentId);
+
+        Optional<Iterable<String>> getSegmentReferences(String segmentId);
+
+        Optional<Iterable<Record>> getSegmentRecords(String segmentId);
+
+        boolean commitExists(String handle);
+
+        Iterable<String> getCommitHandles();
+
+        Optional<Commit> getCommit(String handle);
+
+    }
+
+    public static NodeState of(Backend backend) {
+        NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
+        builder.setChildNode("store", new StoreNode(backend));
+        builder.setChildNode("journal", new JournalNode(backend));
+        return builder.getNodeState();
+    }
+
+    private Proc() {
+        // Prevent external instantiation.
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/Proc.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,64 @@
+/*
+ * 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.file.proc;
+
+import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Record;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+
+class RecordNode extends AbstractNode {
+
+    private final Record record;
+
+    RecordNode(Record record) {
+        this.record = record;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return Arrays.asList(
+            createProperty("number", (long) record.getNumber(), Type.LONG),
+            createProperty("segmentId", record.getSegmentId(), Type.STRING),
+            createProperty("offset", (long) record.getOffset(), Type.LONG),
+            createProperty("address", (long) record.getAddress(), Type.LONG),
+            createProperty("type", record.getType(), Type.STRING)
+        );
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        return record.getRoot()
+            .map(root -> new MemoryChildNodeEntry("root", root))
+            .map(Collections::singletonList)
+            .orElseGet(Collections::emptyList);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,58 @@
+/*
+ * 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.file.proc;
+
+import java.util.Collections;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Record;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+
+class RecordsNode extends AbstractNode {
+    
+    private final Backend backend;
+
+    private final String segmentId;
+
+    RecordsNode(Backend backend, String segmentId) {
+        this.backend = backend;
+        this.segmentId = segmentId;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        return backend.getSegmentRecords(segmentId)
+            .map(this::toChildNodeEntries)
+            .orElse(Collections.emptyList());
+    }
+
+    private Iterable<ChildNodeEntry> toChildNodeEntries(Iterable<Record> records) {
+        return StreamSupport.stream(records.spliterator(), false)
+            .map(r -> new MemoryChildNodeEntry(Integer.toString(r.getNumber()), new RecordNode(r)))
+            .collect(Collectors.toList());
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/RecordsNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,60 @@
+/*
+ * 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.file.proc;
+
+import java.util.Collections;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+
+class ReferencesNode extends AbstractNode {
+
+    private final Backend backend;
+
+    private final String segmentId;
+
+    ReferencesNode(Backend backend, String segmentId) {
+        this.backend = backend;
+        this.segmentId = segmentId;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        return backend.getSegmentReferences(segmentId)
+            .map(this::getChildNodeEntries)
+            .orElse(Collections.emptyList());
+    }
+
+    private Iterable<ChildNodeEntry> getChildNodeEntries(Iterable<String> references) {
+        return StreamSupport.stream(references.spliterator(), false)
+            .map(this::newSegmentNodeEntry)
+            .collect(Collectors.toList());
+    }
+
+    private ChildNodeEntry newSegmentNodeEntry(String segmentId) {
+        return new SegmentEntry(backend, segmentId);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/ReferencesNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentBlob.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentBlob.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentBlob.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentBlob.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,69 @@
+/*
+ * 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.file.proc;
+
+import java.io.InputStream;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.Blob;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+
+class SegmentBlob implements Blob {
+
+    private final Backend backend;
+
+    private final String segmentId;
+
+    private final Segment segment;
+
+    SegmentBlob(Backend backend, String segmentId, Segment segment) {
+        this.backend = backend;
+        this.segmentId = segmentId;
+        this.segment = segment;
+    }
+
+    @Nonnull
+    @Override
+    public InputStream getNewStream() {
+        return backend.getSegmentData(segmentId)
+            .orElseThrow(() -> new IllegalStateException("segment not found"));
+    }
+
+    @Override
+    public long length() {
+        return segment.getLength();
+    }
+
+    @CheckForNull
+    @Override
+    public String getReference() {
+        return null;
+    }
+
+    @CheckForNull
+    @Override
+    public String getContentIdentity() {
+        return null;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentBlob.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentEntry.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentEntry.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentEntry.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,51 @@
+/*
+ * 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.file.proc;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class SegmentEntry implements ChildNodeEntry {
+
+    private final Backend backend;
+
+    private final String segmentId;
+
+    SegmentEntry(Backend backend, String segmentId) {
+        this.backend = backend;
+        this.segmentId = segmentId;
+    }
+
+    @Nonnull
+    @Override
+    public String getName() {
+        return segmentId;
+    }
+
+    @Nonnull
+    @Override
+    public NodeState getNodeState() {
+        return SegmentNode.newSegmentNode(backend, segmentId);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,49 @@
+/*
+ * 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.file.proc;
+
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class SegmentNode {
+
+    private SegmentNode() {
+        // Prevent instantiation.
+    }
+
+    static NodeState newSegmentNode(Backend backend, String segmentId) {
+        return backend.getSegment(segmentId)
+            .map(segment -> newSegmentNode(backend, segmentId, segment))
+            .orElseGet(() -> newMissingSegment(segmentId));
+    }
+
+    private static NodeState newSegmentNode(Backend backend, String segmentId, Segment segment) {
+        if (segment.isDataSegment()) {
+            return new DataSegmentNode(backend, segmentId, segment);
+        }
+        return new BulkSegmentNode(backend, segmentId, segment);
+    }
+
+    private static NodeState newMissingSegment(String segmentId) {
+        return new MissingSegmentNode(segmentId);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/SegmentNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,66 @@
+/*
+ * 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.file.proc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class StoreNode extends AbstractNode {
+
+    private final Backend backend;
+
+    StoreNode(Backend backend) {
+        this.backend = backend;
+    }
+
+    @Override
+    public boolean hasChildNode(@Nonnull String name) {
+        return backend.tarExists(name);
+    }
+
+    @Nonnull
+    @Override
+    public NodeState getChildNode(@Nonnull String name) throws IllegalArgumentException {
+        if (backend.tarExists(name)) {
+            return new TarNode(backend, name);
+        }
+        return EmptyNodeState.MISSING_NODE;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        List<ChildNodeEntry> entries = new ArrayList<>();
+
+        for (String name : backend.getTarNames()) {
+            entries.add(new MemoryChildNodeEntry(name, new TarNode(backend, name)));
+        }
+
+        return entries;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/StoreNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/TarNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/TarNode.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/TarNode.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/TarNode.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,81 @@
+/*
+ * 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.file.proc;
+
+import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
+
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class TarNode extends AbstractNode {
+
+    private final Backend backend;
+
+    private final String name;
+
+    TarNode(Backend backend, String name) {
+        this.backend = backend;
+        this.name = name;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return ImmutableList.of(
+            createProperty("name", name),
+            createProperty("size", backend.getTarSize(name).orElse(-1L))
+        );
+    }
+
+    @Override
+    public boolean hasChildNode(@Nonnull String name) {
+        return backend.segmentExists(this.name, name);
+    }
+
+    @Nonnull
+    @Override
+    public NodeState getChildNode(@Nonnull String name) throws IllegalArgumentException {
+        if (backend.segmentExists(this.name, name)) {
+            return SegmentNode.newSegmentNode(backend, name);
+        }
+        return EmptyNodeState.MISSING_NODE;
+    }
+
+    @Nonnull
+    @Override
+    public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
+        return StreamSupport.stream(backend.getSegmentIds(name).spliterator(), false)
+            .map(this::newSegmentEntry)
+            .collect(Collectors.toList());
+    }
+
+    ChildNodeEntry newSegmentEntry(String segmentId) {
+        return new SegmentEntry(backend, segmentId);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/proc/TarNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java?rev=1829528&r1=1829527&r2=1829528&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/SegmentArchiveReader.java Thu Apr 19 12:05:52 2018
@@ -18,17 +18,19 @@
  */
 package org.apache.jackrabbit.oak.segment.spi.persistence;
 
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import java.io.Closeable;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.List;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 /**
  * This interface represents a read-only segment archive. Since the underlying
  * data structure is immutable, the implementation <b>should be</b> thread safe.
  */
-public interface SegmentArchiveReader {
+public interface SegmentArchiveReader extends Closeable {
 
     /**
      * Read the segment.
@@ -98,6 +100,7 @@ public interface SegmentArchiveReader {
     /**
      * Close the archive.
      */
+    @Override
     void close() throws IOException;
 
     /**

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,86 @@
+/*
+ * 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.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+import org.junit.Test;
+
+public class BulkSegmentNodeTest {
+
+    private static Segment mockSegment() {
+        Segment segment = mock(Segment.class);
+        when(segment.getInfo()).thenReturn(Optional.empty());
+        return segment;
+    }
+
+    private static Backend mockBackend() {
+        return mock(Backend.class);
+    }
+
+    @Test
+    public void shouldHaveLengthProperty() {
+        Segment segment = mockSegment();
+        when(segment.getLength()).thenReturn(1);
+
+        PropertyState property = new BulkSegmentNode(mockBackend(), "s", segment).getProperty("length");
+
+        assertEquals(Type.LONG, property.getType());
+        assertEquals(1, property.getValue(Type.LONG).intValue());
+    }
+
+    @Test
+    public void shouldHaveDataProperty() {
+        PropertyState property = new BulkSegmentNode(mockBackend(), "s", mockSegment()).getProperty("data");
+        assertEquals(Type.BINARY, property.getType());
+    }
+
+    @Test
+    public void shouldHaveIsDataSegmentProperty() {
+        PropertyState property = new BulkSegmentNode(mockBackend(), "s", mockSegment()).getProperty("isDataSegment");
+
+        assertEquals(Type.BOOLEAN, property.getType());
+        assertEquals(false, property.getValue(Type.BOOLEAN));
+    }
+
+    @Test
+    public void shouldHaveIdProperty() {
+        PropertyState property = new BulkSegmentNode(mockBackend(), "s", mockSegment()).getProperty("id");
+
+        assertEquals(Type.STRING, property.getType());
+        assertEquals("s", property.getValue(Type.STRING));
+    }
+
+    @Test
+    public void shouldHveExistsProperty() {
+        PropertyState property = new BulkSegmentNode(mockBackend(), "s", mockSegment()).getProperty("exists");
+
+        assertEquals(Type.BOOLEAN, property.getType());
+        assertEquals(true, property.getValue(Type.BOOLEAN));
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/BulkSegmentNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,83 @@
+/*
+ * 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.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Commit;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+public class CommitNodeTest {
+
+    private Commit mockCommit() {
+        Commit commit = mock(Commit.class);
+        when(commit.getRevision()).thenReturn("");
+        return commit;
+    }
+
+    @Test
+    public void shouldHaveTimestampProperty() {
+        Commit commit = mockCommit();
+        when(commit.getTimestamp()).thenReturn(1L);
+
+        Proc.Backend backend = mock(Proc.Backend.class);
+        when(backend.getCommit("h")).thenReturn(Optional.of(commit));
+
+        PropertyState property = new CommitNode(backend, "h").getProperty("timestamp");
+
+        assertEquals(Type.LONG, property.getType());
+        assertEquals(1L, property.getValue(Type.LONG).longValue());
+    }
+
+    @Test
+    public void shouldExposeRoot() {
+        Commit commit = mockCommit();
+        when(commit.getRoot()).thenReturn(Optional.of(EmptyNodeState.EMPTY_NODE));
+
+        Proc.Backend backend = mock(Proc.Backend.class);
+        when(backend.getCommit("h")).thenReturn(Optional.of(commit));
+
+        assertTrue(new CommitNode(backend, "h").hasChildNode("root"));
+    }
+
+    @Test
+    public void shouldHaveRootChildNode() {
+        NodeState root = EmptyNodeState.EMPTY_NODE;
+
+        Commit commit = mock(Commit.class);
+        when(commit.getRoot()).thenReturn(Optional.of(root));
+
+        Proc.Backend backend = mock(Proc.Backend.class);
+        when(backend.getCommit("h")).thenReturn(Optional.of(commit));
+
+        assertSame(root, new CommitNode(backend, "h").getChildNode("root"));
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/CommitNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNodeTest.java?rev=1829528&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNodeTest.java (added)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNodeTest.java Thu Apr 19 12:05:52 2018
@@ -0,0 +1,171 @@
+/*
+ * 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.file.proc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.InputStream;
+import java.util.Optional;
+
+import com.google.common.collect.Iterables;
+import org.apache.commons.io.input.NullInputStream;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend;
+import org.apache.jackrabbit.oak.segment.file.proc.Proc.Backend.Segment;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+public class DataSegmentNodeTest {
+
+    private static Segment mockSegment() {
+        Segment segment = mock(Segment.class);
+        when(segment.getInfo()).thenReturn(Optional.empty());
+        return segment;
+    }
+
+    private static Backend mockBackend() {
+        return mock(Backend.class);
+    }
+
+    @Test
+    public void shouldHaveGenerationProperty() {
+        Segment segment = mockSegment();
+        when(segment.getGeneration()).thenReturn(1);
+
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", segment).getProperty("generation");
+
+        assertEquals(Type.LONG, property.getType());
+        assertEquals(1, property.getValue(Type.LONG).intValue());
+    }
+
+    @Test
+    public void shouldHaveFullGenerationProperty() {
+        Segment segment = mockSegment();
+        when(segment.getFullGeneration()).thenReturn(1);
+
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", segment).getProperty("fullGeneration");
+
+        assertEquals(Type.LONG, property.getType());
+        assertEquals(1, property.getValue(Type.LONG).intValue());
+    }
+
+    @Test
+    public void shouldHaveCompactedProperty() {
+        Segment segment = mockSegment();
+        when(segment.isCompacted()).thenReturn(true);
+
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", segment).getProperty("compacted");
+
+        assertEquals(Type.BOOLEAN, property.getType());
+        assertTrue(property.getValue(Type.BOOLEAN));
+    }
+
+    @Test
+    public void shouldHaveLengthProperty() {
+        Segment segment = mockSegment();
+        when(segment.getLength()).thenReturn(1);
+
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", segment).getProperty("length");
+
+        assertEquals(Type.LONG, property.getType());
+        assertEquals(1, property.getValue(Type.LONG).intValue());
+    }
+
+    @Test
+    public void shouldHaveDataProperty() {
+        InputStream stream = new NullInputStream(1);
+
+        Segment segment = mockSegment();
+        when(segment.getLength()).thenReturn(1);
+
+        Backend backend = mockBackend();
+        when(backend.getSegmentData("s")).thenReturn(Optional.of(stream));
+
+        PropertyState property = new DataSegmentNode(backend, "s", segment).getProperty("data");
+
+        assertEquals(Type.BINARY, property.getType());
+        assertSame(stream, property.getValue(Type.BINARY).getNewStream());
+        assertEquals(1, property.getValue(Type.BINARY).length());
+    }
+
+    @Test
+    public void shouldHaveIdProperty() {
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", mockSegment()).getProperty("id");
+
+        assertEquals(Type.STRING, property.getType());
+        assertEquals("s", property.getValue(Type.STRING));
+    }
+
+    @Test
+    public void shouldHaveVersionProperty() {
+        Segment segment = mockSegment();
+        when(segment.getVersion()).thenReturn(1);
+
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", segment).getProperty("version");
+
+        assertEquals(Type.LONG, property.getType());
+        assertEquals(1, property.getValue(Type.LONG).longValue());
+    }
+
+    @Test
+    public void shouldHaveIsDataSegmentProperty() {
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", mockSegment()).getProperty("isDataSegment");
+
+        assertEquals(Type.BOOLEAN, property.getType());
+        assertTrue(property.getValue(Type.BOOLEAN));
+    }
+
+    @Test
+    public void shouldHaveInfoProperty() {
+        Segment segment = mockSegment();
+        when(segment.getInfo()).thenReturn(Optional.of("info"));
+
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", segment).getProperty("info");
+
+        assertEquals(Type.STRING, property.getType());
+        assertEquals("info", property.getValue(Type.STRING));
+    }
+
+    @Test
+    public void shouldHaveExistsProperty() {
+        PropertyState property = new DataSegmentNode(mockBackend(), "s", mockSegment()).getProperty("exists");
+
+        assertEquals(Type.BOOLEAN, property.getType());
+        assertEquals(true, property.getValue(Type.BOOLEAN));
+    }
+
+    @Test
+    public void shouldExposeReferences() {
+        NodeState n = new DataSegmentNode(mockBackend(), "s", mockSegment());
+        assertTrue(Iterables.contains(n.getChildNodeNames(), "references"));
+    }
+
+    @Test
+    public void shouldExposeRecordsNode() {
+        NodeState n = new DataSegmentNode(mockBackend(), "s", mockSegment());
+        assertTrue(Iterables.contains(n.getChildNodeNames(), "records"));
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/file/proc/DataSegmentNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native