Search in sources :

Example 21 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class TarRevisions method doFlush.

private void doFlush(Callable<Void> persisted) throws IOException {
    try {
        RecordId before = persistedHead.get();
        RecordId after = getHead();
        if (!after.equals(before)) {
            persisted.call();
            LOG.debug("TarMK journal update {} -> {}", before, after);
            journalFile.writeBytes(after.toString10() + " root " + System.currentTimeMillis() + "\n");
            journalFile.getChannel().force(false);
            persistedHead.set(after);
        }
    } catch (Exception e) {
        propagateIfInstanceOf(e, IOException.class);
        propagate(e);
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) FileStoreUtil.findPersistedRecordId(org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId) IOException(java.io.IOException) IOException(java.io.IOException)

Example 22 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class DebugStore method analyseSegment.

private static void analyseSegment(final Segment segment, final RecordUsageAnalyser analyser) {
    final List<RecordId> ids = newArrayList();
    segment.forEachRecord((number, type, offset) -> {
        if (type == NODE) {
            ids.add(new RecordId(segment.getSegmentId(), number));
        }
    });
    for (RecordId id : ids) {
        try {
            analyser.analyseNode(id);
        } catch (Exception e) {
            System.err.format("Error while processing node at %s", id);
            e.printStackTrace(System.err);
        }
    }
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId)

Example 23 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class CheckRepositoryTestBase method addInvalidRevision.

protected void addInvalidRevision() throws InvalidFileStoreVersionException, IOException, CommitFailedException {
    FileStore fileStore = FileStoreBuilder.fileStoreBuilder(temporaryFolder.getRoot()).withMaxFileSize(256).withSegmentCacheSize(64).build();
    SegmentNodeStore nodeStore = SegmentNodeStoreBuilders.builder(fileStore).build();
    NodeBuilder builder = nodeStore.getRoot().builder();
    // add a new child "z"
    addChildWithBlobProperties(nodeStore, builder, "z", 5);
    // add a new property value to existing child "a"
    addChildWithBlobProperties(nodeStore, builder, "a", 1);
    NodeState after = nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    // get record number to corrupt (NODE record for "z")
    SegmentNodeState child = (SegmentNodeState) after.getChildNode("z");
    RecordId zRecordId = child.getRecordId();
    // get record number to corrupt (NODE record for "a")
    child = (SegmentNodeState) after.getChildNode("a");
    RecordId aRecordId = child.getRecordId();
    fileStore.close();
    corruptRecord(zRecordId, "data00001a.tar");
    corruptRecord(aRecordId, "data00001a.tar");
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState) RecordId(org.apache.jackrabbit.oak.segment.RecordId) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SegmentNodeState(org.apache.jackrabbit.oak.segment.SegmentNodeState)

Example 24 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class DefaultStandbyReferenceReaderTest method shouldReturnReferences.

@Test
public void shouldReturnReferences() throws Exception {
    try (FileStore store = newFileStore()) {
        SegmentWriter writer = defaultSegmentWriterBuilder("test").build(store);
        RecordId a = writer.writeNode(EmptyNodeState.EMPTY_NODE);
        writer.flush();
        NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
        builder.setChildNode("reference", store.getReader().readNode(a));
        RecordId b = writer.writeNode(builder.getNodeState());
        writer.flush();
        DefaultStandbyReferencesReader reader = new DefaultStandbyReferencesReader(store);
        Iterator<String> i = reader.readReferences(b.getSegmentId().asUUID().toString()).iterator();
        assertTrue(i.hasNext());
        assertEquals(a.getSegmentId().asUUID().toString(), i.next());
        assertFalse(i.hasNext());
    }
}
Also used : FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) RecordId(org.apache.jackrabbit.oak.segment.RecordId) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SegmentWriter(org.apache.jackrabbit.oak.segment.SegmentWriter) Test(org.junit.Test)

Example 25 with RecordId

use of org.apache.jackrabbit.oak.segment.RecordId in project jackrabbit-oak by apache.

the class TarRevisions method doFlush.

private void doFlush(Flusher flusher) throws IOException {
    if (journalFileWriter == null) {
        LOG.debug("No journal file available, skipping flush");
        return;
    }
    RecordId before = persistedHead.get();
    RecordId after = getHead();
    if (after.equals(before)) {
        LOG.debug("Head state did not change, skipping flush");
        return;
    }
    flusher.flush();
    LOG.debug("TarMK journal update {} -> {}", before, after);
    journalFileWriter.writeLine(after.toString10() + " root " + System.currentTimeMillis());
    persistedHead.set(after);
}
Also used : RecordId(org.apache.jackrabbit.oak.segment.RecordId) FileStoreUtil.findPersistedRecordId(org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId)

Aggregations

RecordId (org.apache.jackrabbit.oak.segment.RecordId)28 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)14 Test (org.junit.Test)9 FileStoreUtil.findPersistedRecordId (org.apache.jackrabbit.oak.segment.file.FileStoreUtil.findPersistedRecordId)7 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 SegmentNodeBuilder (org.apache.jackrabbit.oak.segment.SegmentNodeBuilder)3 SegmentWriter (org.apache.jackrabbit.oak.segment.SegmentWriter)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 RecordId.fromString (org.apache.jackrabbit.oak.segment.RecordId.fromString)2 SegmentId (org.apache.jackrabbit.oak.segment.SegmentId)2 SegmentNodeStore (org.apache.jackrabbit.oak.segment.SegmentNodeStore)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Function (com.google.common.base.Function)1 Stopwatch (com.google.common.base.Stopwatch)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 PrintWriter (java.io.PrintWriter)1 Random (java.util.Random)1