HeimingZ commented on a change in pull request #5320: URL: https://github.com/apache/iotdb/pull/5320#discussion_r834165668
########## File path: server/src/main/java/org/apache/iotdb/db/wal/WALManager.java ########## @@ -0,0 +1,238 @@ +/* + * 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.iotdb.db.wal; + +import org.apache.iotdb.commons.concurrent.IoTDBThreadPoolFactory; +import org.apache.iotdb.commons.concurrent.ThreadName; +import org.apache.iotdb.commons.exception.StartupException; +import org.apache.iotdb.commons.service.IService; +import org.apache.iotdb.commons.service.ServiceType; +import org.apache.iotdb.commons.utils.TestOnly; +import org.apache.iotdb.db.conf.IoTDBConfig; +import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.apache.iotdb.db.conf.directories.FolderManager; +import org.apache.iotdb.db.conf.directories.strategy.DirectoryStrategyType; +import org.apache.iotdb.db.exception.DiskSpaceInsufficientException; +import org.apache.iotdb.db.wal.node.IWALNode; +import org.apache.iotdb.db.wal.node.WALFakeNode; +import org.apache.iotdb.db.wal.node.WALNode; +import org.apache.iotdb.db.wal.utils.WALMode; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** This class is used to manage all wal nodes */ +public class WALManager implements IService { + public static final long FSYNC_CHECKPOINT_FILE_DELAY_IN_MS = 200; + public static final long DELETE_WAL_FILES_DELAY_IN_MS = 10 * 60 * 1000; + + private static final Logger logger = LoggerFactory.getLogger(WALManager.class); + private static final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); + private static final int MAX_WAL_NUM = + config.getMaxWalNum() > 0 ? config.getMaxWalNum() : config.getWalDirs().length * 2; + + /** manage wal folders */ + private FolderManager folderManager; + /** protect concurrent safety of walNodes, nodeCursor and nodeIdCounter */ + private final Lock nodesLock = new ReentrantLock(); + /** wal nodes, the max number of wal nodes is MAX_WAL_NUM */ + private final List<WALNode> walNodes = new ArrayList<>(MAX_WAL_NUM); + /** help allocate node for users */ + private int nodeCursor = -1; + /** each wal node has a unique long value identifier */ + private long nodeIdCounter = -1; Review comment: nodeCursor and nodeIdCounter are both protected by the [nodesLock](https://github.com/apache/iotdb/pull/5320/files#diff-672f4b0027b7b2d89495f695447243e85d264fc61a37ee2dcbbcf01a3f59cf0aR63-R64) of WALManager. -- 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]
