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

io.atomix.copycat.server.storage.compaction.MinorCompactionTask Maven / Gradle / Ivy

/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed 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 io.atomix.copycat.server.storage.compaction;

import io.atomix.catalyst.util.Assert;
import io.atomix.copycat.server.storage.Segment;
import io.atomix.copycat.server.storage.SegmentDescriptor;
import io.atomix.copycat.server.storage.SegmentManager;
import io.atomix.copycat.server.storage.entry.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;

/**
 * Removes {@link io.atomix.copycat.server.storage.Log#clean(long) cleaned} entries from an individual
 * log {@link Segment} to reclaim disk space.
 * 

* The minor compaction task is a lightweight process that rewrites an individual segment to remove entries for * which {@link Entry#isTombstone()} is {@code false}. Tombstones are entries that represent the deletion of * state from the application, and tombstones are not removed during minor compaction since the safety of removing * tombstones relies on expensive context. For more information on the implementation for removing tombstones, * see the {@link MajorCompactionTask}. *

* When a segment is rewritten by the minor compaction task, a new compact segment is created with the same starting * index as the segment being compacted and the next greatest version number. The version number allows the * {@link SegmentManager} to account for failures during log compaction when recovering the log from disk. If a failure * occurs during minor compaction, the segment manager will attempt to load the segment with the greatest version * for a given range of entries from disk. If the segment with the greatest version did not finish compaction, it * will be discarded and the old segment will be used. Once the minor compaction task is done rewriting a segment, * it will {@link SegmentDescriptor#lock()} the segment to indicate that the segment has completed compaction and * is safe to read, and the compacted segment will be made available to the {@link io.atomix.copycat.server.storage.Log}. * * @author





© 2015 - 2025 Weber Informatics LLC | Privacy Policy