tkalkirill commented on code in PR #947: URL: https://github.com/apache/ignite-3/pull/947#discussion_r928600390
########## modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/store/AbstractFilePageStoreIo.java: ########## @@ -0,0 +1,611 @@ +/* + * 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.pagememory.persistence.store; + +import static java.nio.ByteOrder.nativeOrder; +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.READ; +import static java.nio.file.StandardOpenOption.WRITE; +import static org.apache.ignite.internal.util.IgniteUtils.atomicMoveFile; +import static org.apache.ignite.internal.util.IgniteUtils.hexInt; +import static org.apache.ignite.internal.util.IgniteUtils.hexLong; +import static org.apache.ignite.internal.util.IgniteUtils.toHexString; +import static org.apache.ignite.lang.IgniteSystemProperties.getBoolean; + +import java.io.Closeable; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedByInterruptException; +import java.nio.channels.ClosedChannelException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.ignite.internal.fileio.FileIo; +import org.apache.ignite.internal.fileio.FileIoFactory; +import org.apache.ignite.internal.pagememory.io.PageIo; +import org.apache.ignite.internal.pagememory.persistence.FastCrc; +import org.apache.ignite.internal.pagememory.persistence.IgniteInternalDataIntegrityViolationException; +import org.apache.ignite.lang.IgniteInternalCheckedException; +import org.jetbrains.annotations.Nullable; + +/** + * Abstract class for performing IO operations on file page storage. + */ +public abstract class AbstractFilePageStoreIo implements Closeable { + private final FileIoFactory ioFactory; + + private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); + + /** Skip CRC calculation flag. */ + // TODO: IGNITE-17011 Move to config + private final boolean skipCrc = getBoolean("IGNITE_PDS_SKIP_CRC"); + + private volatile Path filePath; + + private volatile @Nullable FileIo fileIo; + + /** Initialized file page store IO. */ + private volatile boolean initialized; + + /** Caches the existence state of file. After it is initialized, it will be not {@code null} during lifecycle. */ + private volatile @Nullable Boolean fileExists; + + /** + * Constructor. + * + * @param ioFactory {@link FileIo} factory. + * @param filePath File page store path. + */ + AbstractFilePageStoreIo(FileIoFactory ioFactory, Path filePath) { + this.ioFactory = ioFactory; + this.filePath = filePath; + } + + /** + * Returns the page size in bytes. + */ + public abstract int pageSize(); + + /** + * Returns the size of the header in bytes. + */ + public abstract int headerSize(); + + /** + * Returns a buffer with a file page storage header. + */ + public abstract ByteBuffer headerBuffer(); + + /** + * Checks the file page storage header. + * + * @param fileIo File page store IO to read the header. + * @throws IOException If there is an error reading the header or the header did not pass the check. + */ + public abstract void checkHeader(FileIo fileIo) throws IOException; + + /** + * Returns page offset within the store file. + * + * @param pageId Page ID. + */ + public abstract long pageOffset(long pageId); + + /** + * Stops the file page store IO. + * + * @param clean {@code True} to clean file page store. + * @throws IgniteInternalCheckedException If failed. + */ + public void stop(boolean clean) throws IgniteInternalCheckedException { + try { + stop0(clean); + } catch (IOException e) { + throw new IgniteInternalCheckedException( + "Failed to stop serving file [file=" + filePath + ", delete=" + clean + "]", + e + ); + } + } + + /** {@inheritDoc} */ + @Override + public void close() throws IOException { + stop0(false); + } + + /** + * Reads a page. + * + * @param pageId Page ID. + * @param pageOff Page offset in the file. + * @param pageBuf Page buffer to read into. + * @param keepCrc By default, reading zeroes CRC which was on page store, but you can keep it in {@code pageBuf} if set {@code Review Comment: fix it -- 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]
