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

io.atomix.copycat.server.storage.compaction.MajorCompactionManager 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.copycat.server.storage.Segment;
import io.atomix.copycat.server.storage.SegmentManager;
import io.atomix.copycat.server.storage.Storage;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Builds tasks for the {@link Compaction#MAJOR} compaction process.
 * 

* Major compaction works by iterating through all committed {@link Segment}s in the log and rewriting and * combining segments to compact them together. Because of the sequential nature of major compaction, the major * compaction manager builds only a single {@link MajorCompactionTask} which will rewrite the log sequentially. * Segments are provided to the major compaction task in groups that indicate which segments to combine. A set * of segments can be combined if they meet the following criteria: *

    *
  • The entries in the set of segments are sequential; there are no missing segments in the set * such that combining the segments would result in a segment with missing entries
  • *
  • The combined size of all segments in the set is less than the configured {@link Storage#maxSegmentSize()}
  • *
  • The combined number of entries after compaction is less than the configured {@link Storage#maxEntriesPerSegment()}
  • *
* * @author © 2015 - 2025 Weber Informatics LLC | Privacy Policy