ibessonov commented on a change in pull request #566: URL: https://github.com/apache/ignite-3/pull/566#discussion_r790469503
########## File path: modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/util/PageHandler.java ########## @@ -0,0 +1,478 @@ +/* + * 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.util; + +import static java.lang.Boolean.FALSE; + +import java.nio.ByteBuffer; +import org.apache.ignite.internal.pagememory.PageMemory; +import org.apache.ignite.internal.pagememory.io.PageIo; +import org.apache.ignite.internal.pagememory.metric.IoStatisticsHolder; +import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.lang.IgniteInternalCheckedException; + +/** + * Page handler. + * + * @param <X> Type of the arbitrary parameter. + * @param <R> Type of the result. + */ +public interface PageHandler<X, R> { + /** No-op page handler. */ + public static final PageHandler<Void, Boolean> NO_OP = (groupId, pageId, page, pageAddr, io, arg, intArg, statHolder) -> Boolean.TRUE; + + /** + * Handles the page. + * + * @param groupId Group ID. + * @param pageId Page ID. + * @param page Page pointer. + * @param pageAddr Page address. + * @param io IO. + * @param arg Argument. + * @param intArg Argument of type {@code int}. + * @param statHolder Statistics holder to track IO operations. + * @return Result. + * @throws IgniteInternalCheckedException If failed. + */ + public R run( + int groupId, + long pageId, + long page, + long pageAddr, + PageIo io, + X arg, + int intArg, + IoStatisticsHolder statHolder + ) throws IgniteInternalCheckedException; + + /** + * Checks whether write lock (and acquiring if applicable) should be released after handling. + * + * @param groupId Group ID. + * @param pageId Page ID. + * @param page Page pointer. + * @param pageAddr Page address. + * @param arg Argument. + * @param intArg Argument of type {@code int}. + * @return {@code true} If release. + */ + default boolean releaseAfterWrite( + int groupId, + long pageId, + long page, + long pageAddr, + X arg, + int intArg + ) { + return true; + } + + /** + * Executes handler under the read lock or returns {@code lockFailed} if lock failed. + * + * @param pageMem Page memory. + * @param groupId Group ID. + * @param pageId Page ID. + * @param lsnr Lock listener. + * @param h Handler. + * @param arg Argument. + * @param intArg Argument of type {@code int}. + * @param lockFailed Result in case of lock failure due to page recycling. + * @param statHolder Statistics holder to track IO operations. + * @return Handler result. + * @throws IgniteInternalCheckedException If failed. + */ + public static <X, R> R readPage( Review comment: > This makes it extremely difficult (almost impossible) to apply unit testing to this code. I don't really see right now how it would be hard to write unit tests in this case. Maybe I'm missing something. Lets's restrict ourselves from radical refactoring for now. The task is to port old code, and every change on early stages will make further porting more difficult than it needs to be. We only started. -- 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]
