Phillippko commented on code in PR #6636: URL: https://github.com/apache/ignite-3/pull/6636#discussion_r2375696393
########## modules/raft/src/main/java/org/apache/ignite/internal/raft/storage/segstore/IndexFileManager.java: ########## @@ -0,0 +1,179 @@ +/* + * 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 java.nio.file.StandardOpenOption.CREATE_NEW; +import static java.nio.file.StandardOpenOption.WRITE; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Iterator; +import java.util.Map.Entry; + +/** + * File manager responsible for persisting {@link IndexMemTable}s to index files. + * + * <p>When a checkpoint is triggered on segment file rollover, the current index memtable is scheduled for being saved to a file. The + * format of this file is as follows: + * <pre> + * +--------+---------------------+-----+---------------------+ + * | Header | Payload for group 1 | ... | Payload for group N | + * +--------+---------------------+-----+---------------------+ + * </pre> + * + * <p>Header structure consists of a common meta and a meta for each Raft group present in the memtable. The common meta is as follows: + * <pre> + * +------------------------------------------------------------------+ + * | Common meta | + * +------------------------------------------------------------------+ + * | Magic (4 bytes) | Version (4 bytes) | Number of groups (4 bytes) | + * +------------------------------------------------------------------+ + * </pre> + * + * <p>Raft group meta is as follows: + * <pre> + * +----------------------------------------------------------------------------------------------------------------+-----+ + * | Raft group 1 meta | ... | + * +----------------------------------------------------------------------------------------------------------------+-----+ + * | Group ID (8 bytes) | Flags (4 bytes) | Offset (4 bytes) | First Log Index (8 bytes) | Last Log Index (8 bytes) | ... | + * +----------------------------------------------------------------------------------------------------------------+-----+ + * </pre> + * + * <p>Payload of the index files has the following structure: + * <pre> + * +-------------------------------------------------------------------------+-----+ + * | Payload for group 1 | ... | + * +-------------------------------------------------------------------------+-----+ + * | Segment file offset 1 (4 bytes) | ... | Segment file offset N (4 bytes) | ... | + * +-------------------------------------------------------------------------+-----+ + * </pre> + * + * @see IndexMemTable + * @see SegmentFileManager + */ +class IndexFileManager { + static final int MAGIC_NUMBER = 0xCAFEBABE; Review Comment: Magic number ideally should be unique and identify files, yes? This one is already used by .class files, and as it is so well-known we might accidentally use it in other parts of ignite So now it doesn't serve one of it's purposes, identifying that we work with a segstorage index file -- 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]
