tkalkirill commented on code in PR #845: URL: https://github.com/apache/ignite-3/pull/845#discussion_r889933505
########## modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/PersistentPageMemoryTableStorage.java: ########## @@ -0,0 +1,261 @@ +/* + * 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.storage.pagememory; + +import static org.apache.ignite.internal.pagememory.PageIdAllocator.FLAG_AUX; +import static org.apache.ignite.internal.storage.StorageUtils.groupId; + +import java.util.concurrent.atomic.AtomicLong; +import org.apache.ignite.configuration.schemas.table.TableConfiguration; +import org.apache.ignite.configuration.schemas.table.TableView; +import org.apache.ignite.internal.pagememory.FullPageId; +import org.apache.ignite.internal.pagememory.evict.PageEvictionTrackerNoOp; +import org.apache.ignite.internal.pagememory.metric.IoStatisticsHolderNoOp; +import org.apache.ignite.internal.pagememory.persistence.PageMemoryImpl; +import org.apache.ignite.internal.pagememory.persistence.checkpoint.CheckpointTimeoutLock; +import org.apache.ignite.internal.pagememory.persistence.store.FilePageStore; +import org.apache.ignite.internal.pagememory.util.PageLockListenerNoOp; +import org.apache.ignite.internal.storage.StorageException; +import org.apache.ignite.internal.storage.pagememory.io.PartitionMetaIo; +import org.apache.ignite.lang.IgniteInternalCheckedException; + +/** + * Implementation of {@link AbstractPageMemoryTableStorage} for persistent case. + */ +class PersistentPageMemoryTableStorage extends AbstractPageMemoryTableStorage { + /** + * Constructor. + * + * @param tableCfg Table configuration. + * @param dataRegion Data region for the table. + */ + public PersistentPageMemoryTableStorage( + TableConfiguration tableCfg, + PersistentPageMemoryDataRegion dataRegion + ) { + super(tableCfg, dataRegion); + } + + /** {@inheritDoc} */ + @Override + public void start() throws StorageException { + super.start(); + + TableView tableView = tableCfg.value(); + + try { + // TODO: IGNITE-16665 Directory name needs to be corrected to support table renaming + ((PersistentPageMemoryDataRegion) dataRegion) + .filePageStoreManager() + .initialize(tableView.name(), groupId(tableView), tableView.partitions()); + } catch (IgniteInternalCheckedException e) { + throw new StorageException("Error initializing file page stores for table: " + tableView.name(), e); + } + } + + /** {@inheritDoc} */ + @Override + protected VolatilePageMemoryPartitionStorage createPartitionStorage(int partId) throws StorageException { + TableView tableView = tableCfg.value(); + + FilePageStore partitionFilePageStore = ensurePartitionFilePageStore(tableView, partId); + + CheckpointTimeoutLock checkpointTimeoutLock = ((PersistentPageMemoryDataRegion) dataRegion) + .checkpointManager() + .checkpointTimeoutLock(); + + checkpointTimeoutLock.checkpointReadLock(); + + try { + PartitionMeta partitionMeta = getOrCreateTableTreePartitionMetas(tableView, partId, partitionFilePageStore); + + TableFreeList tableFreeList = createTableFreeList(tableView, partId, partitionMeta); + + autoCloseables.add(tableFreeList::close); + + TableTree tableTree = createTableTree(tableView, partId, tableFreeList, partitionMeta); + + return new PersistentPageMemoryPartitionStorage(partId, tableFreeList, tableTree, checkpointTimeoutLock); + } finally { + checkpointTimeoutLock.checkpointReadUnlock(); + } + } + + /** + * Initializes the partition file page store if it hasn't already. + * + * @param tableView Table configuration. + * @param partId Partition ID. + * @return Partition file page store. + * @throws StorageException If failed. + */ + FilePageStore ensurePartitionFilePageStore(TableView tableView, int partId) throws StorageException { + try { + FilePageStore filePageStore = ((PersistentPageMemoryDataRegion) dataRegion) + .filePageStoreManager() + .getStore(groupId(tableView), partId); + + filePageStore.ensure(); + + return filePageStore; + } catch (IgniteInternalCheckedException e) { + throw new StorageException( + String.format("Error initializing file page store [tableName=%s, partitionId=%s]", tableView.name(), partId), + e + ); + } + } + + /** + * Returns the read and created new partition {@link PartitionMeta}. 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]
