sashapolo commented on code in PR #6577: URL: https://github.com/apache/ignite-3/pull/6577#discussion_r2341840279
########## modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/SegmentFileManager.java: ########## @@ -0,0 +1,242 @@ +/* + * 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.ignite.internal.raft.storage.segstore; + +import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR; +import static org.apache.ignite.lang.ErrorGroups.Common.NODE_STOPPING_ERR; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.file.Path; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.ignite.internal.close.ManuallyCloseable; +import org.apache.ignite.internal.lang.IgniteInternalException; +import org.apache.ignite.internal.raft.storage.segstore.SegmentFile.WriteBuffer; + +/** + * File manager responsible for allocating and maintaining a pointer to the current segment file. + * + * <p>When the current segment file becomes full, that is, it does not contain enough bytes left to satisfy a request by one of the writer + * threads, then a new segment file is allocated and is atomically switched to be the current one. This operation is called rollover. + * + * <p>Every segment file has the following structure: + * <pre> + * +------------------+---------+-----+---------+ + * | Header (8 bytes) | Payload | ... | Payload | + * +------------------+---------+-----+---------+ + * </pre> + * + * <p>Header structure is the following: + * <pre> + * +------------------------+-------------------+ + * | Magic number (4 bytes) | Version (4 bytes) | + * +------------------------+-------------------+ + * </pre> + * + * <p>Payload structure is defined by the outer callers. + * + * <p>When a rollover happens and the segment file being replaced has at least 8 bytes left, a special {@link #SWITCH_SEGMENT_RECORD} is + * written at the end of the file. If there are less than 8 bytes left, no switch records are written. + */ +class SegmentFileManager implements ManuallyCloseable { + private static final int ROLLOVER_WAIT_TIMEOUT_MS = 30_000; + + private static final int MAGIC_NUMBER = 0xFEEDFACE; Review Comment: It's just a sanity check so that we know when reading files that this is the correct file type and not some arbitrary data (not used in this PR) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
