All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.jackrabbit.oak.checkpoint.Checkpoints Maven / Gradle / Ivy

There is a newer version: 1.9.9
Show newest version
/*
 * 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.checkpoint;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.annotation.CheckForNull;

import com.google.common.io.Closer;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.spi.state.NodeState;

/**
 * A helper class to manage checkpoints on TarMK and DocumentMK.
 */
public abstract class Checkpoints {

    public static Checkpoints onSegment(File path, Closer closer) throws IOException {
        return SegmentCheckpoints.create(path, closer);
    }

    public static Checkpoints onSegmentTar(File path, Closer closer) throws IOException {
        return SegmentTarCheckpoints.create(path, closer);
    }

    public static Checkpoints onDocumentMK(DocumentNodeStore store) {
        return new DocumentCheckpoints(store);
    }

    /**
     * @return a list of all checkpoints.
     */
    public abstract List list();

    /**
     * Remove all checkpoints.
     *
     * @return the number of removed checkpoints or {@code -1} if the operation
     *          did not succeed.
     */
    public abstract long removeAll();

    /**
     * Remove all unreferenced checkpoints.
     *
     * @return the number of removed checkpoints or {@code -1} if the operation
     *          did not succeed.
     */
    public abstract long removeUnreferenced();

    /**
     * Removes the given checkpoint.
     *
     * @param cp a checkpoint string.
     * @return {@code 1} if the checkpoint was successfully remove, {@code 0} if
     *          there is no such checkpoint or {@code -1} if the operation did
     *          not succeed.
     */
    public abstract int remove(String cp);

    @CheckForNull
    static String getReferenceCheckpoint(NodeState root) {
        String ref = null;
        PropertyState refPS = root.getChildNode(":async").getProperty("async");
        if (refPS != null) {
            ref = refPS.getValue(Type.STRING);
        }
        if (ref != null) {
            System.out.println(
                    "Referenced checkpoint from /:async@async is " + ref);
        }
        return ref;
    }

    public static final class CP {

        public final String id;
        public final long created;
        public final long expires;

        CP(String id, long created, long expires) {
            this.id = id;
            this.created = created;
            this.expires = expires;
        }

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy