KeeProMise commented on code in PR #7137: URL: https://github.com/apache/iotdb/pull/7137#discussion_r958049409
########## server/src/main/java/org/apache/iotdb/db/metadata/idtable/IDTableAutoIncImpl.java: ########## @@ -0,0 +1,253 @@ +/* + * 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.metadata.idtable; + +import org.apache.iotdb.commons.exception.IllegalPathException; +import org.apache.iotdb.commons.exception.MetadataException; +import org.apache.iotdb.commons.path.PartialPath; +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.localconfignode.LocalConfigNode; +import org.apache.iotdb.db.metadata.idtable.deviceID.AutoIncDeviceID; +import org.apache.iotdb.db.metadata.idtable.deviceID.IDeviceID; +import org.apache.iotdb.db.metadata.idtable.deviceID.SHA256DeviceID; +import org.apache.iotdb.db.metadata.idtable.entry.DeviceEntry; +import org.apache.iotdb.db.metadata.idtable.entry.SchemaEntry; +import org.apache.iotdb.db.metadata.idtable.entry.TimeseriesID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class IDTableAutoIncImpl extends IDTableHashmapImpl { + + /** logger */ + private static final Logger logger = LoggerFactory.getLogger(IDTableAutoIncImpl.class); + + protected static IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); + + // if the schemaRegionId==-1 of a StandAloneAutoIncDeviceID instance, it means that the device + // corresponding to the StandAloneAutoIncDeviceID instance does not exist + // return the deviceIdOfNonExistentDevice object for all devicePaths of unmanaged devices in the + // metadata module, which can avoid unnecessary object creation while ensuring correctness + private static AutoIncDeviceID deviceIdOfNonExistentDevice; + + // stand-alone auto-increment id uses LocalConfigNode to obtain schemaRegionId + private static LocalConfigNode configManager; + + // using map to maintain the mapping from schemaRegionId to list<deviceID>, each list<deviceID> + // maintains the auto-increment id of the schemaRegion + private static Map<Integer, List<DeviceEntry>> deviceEntrysMap; + + static { + deviceEntrysMap = new ConcurrentHashMap<>(); + configManager = LocalConfigNode.getInstance(); + deviceIdOfNonExistentDevice = new AutoIncDeviceID(-1, 0); + } + + public static AutoIncDeviceID getDeviceID(String deviceID) { + if (deviceID.startsWith("`") && deviceID.endsWith("`")) { + return fromAutoIncDeviceID(deviceID); + } else { + return fromIdTable(deviceID); + } + } + + public static AutoIncDeviceID fromAutoIncDeviceID(String deviceID) { + AutoIncDeviceID autoIncID = new AutoIncDeviceID(deviceID); + int schemaRegionId = autoIncID.getSchemaRegionId(); + int autoIncrementID = autoIncID.getAutoIncrementID(); + if (autoIncID.getSchemaRegionId() == -1) { + return deviceIdOfNonExistentDevice; + } + List<DeviceEntry> deviceEntries = deviceEntrysMap.get(schemaRegionId); + synchronized (deviceEntries) { + DeviceEntry deviceEntry = deviceEntries.get(autoIncrementID); + return (AutoIncDeviceID) deviceEntry.getDeviceID(); + } + } + + public static AutoIncDeviceID fromIdTable(String devicePath) { Review Comment: renamed -- 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]
