You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xu...@apache.org on 2021/12/06 02:02:42 UTC

[iotdb] branch xkf_id_table created (now 9c7fff6)

This is an automated email from the ASF dual-hosted git repository.

xuekaifeng pushed a change to branch xkf_id_table
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 9c7fff6  init framework

This branch includes the following new commits:

     new 9c7fff6  init framework

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[iotdb] 01/01: init framework

Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xuekaifeng pushed a commit to branch xkf_id_table
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 9c7fff6e67c73914e13f466f4c4eea4fb689c49e
Author: 151250176 <15...@smail.nju.edu.cn>
AuthorDate: Mon Dec 6 10:00:23 2021 +0800

    init framework
---
 .../db/metadata/id_table/DiskSchemaManager.java    | 40 +++++++++++
 .../iotdb/db/metadata/id_table/IDManager.java      | 66 +++++++++++++++++
 .../iotdb/db/metadata/id_table/IDManagerImpl.java  | 83 ++++++++++++++++++++++
 .../apache/iotdb/db/metadata/id_table/IDTable.java | 66 +++++++++++++++++
 .../db/metadata/id_table/entry/DeviceEntry.java    | 31 ++++++++
 .../metadata/id_table/entry/DiskSchemaEntry.java   | 35 +++++++++
 .../db/metadata/id_table/entry/IDeviceID.java      | 22 ++++++
 .../db/metadata/id_table/entry/PlainDeviceID.java  | 48 +++++++++++++
 .../db/metadata/id_table/entry/SHA256DeviceID.java | 44 ++++++++++++
 .../db/metadata/id_table/entry/SchemaEntry.java    | 44 ++++++++++++
 .../db/metadata/id_table/entry/TimeseriesID.java   | 25 +++++++
 11 files changed, 504 insertions(+)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/DiskSchemaManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/DiskSchemaManager.java
new file mode 100644
index 0000000..9998e75
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/DiskSchemaManager.java
@@ -0,0 +1,40 @@
+/*
+ * 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.id_table;
+
+import org.apache.iotdb.db.metadata.id_table.entry.DiskSchemaEntry;
+
+public interface DiskSchemaManager {
+
+  /**
+   * serialize a disk schema entry
+   *
+   * @param diskSchemaEntry disk schema entry
+   * @return disk position of that entry
+   */
+  public long serialize(DiskSchemaEntry diskSchemaEntry);
+
+  /**
+   * deserialize a disk schema entry
+   *
+   * @param pos disk position
+   * @return disk schema entry
+   */
+  public DiskSchemaEntry deserialize(long pos);
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDManager.java
new file mode 100644
index 0000000..3bef50a
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDManager.java
@@ -0,0 +1,66 @@
+/*
+ * 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.id_table;
+
+import com.sun.tools.javac.util.Pair;
+import org.apache.iotdb.db.metadata.id_table.entry.TimeseriesID;
+
+public interface IDManager {
+
+  /**
+   * check whether a time series is exist if exist, check the type consistency if not exist, call
+   * MManager to create it
+   *
+   * @param seriesKey full path of the time series
+   * @return timeseries ID of this time series
+   */
+  public TimeseriesID checkOrCreateIfNotExist(String seriesKey);
+
+  /**
+   * upatde latest flushed time of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @param flushedTime latest flushed time
+   */
+  public void updateLatestFlushedTime(TimeseriesID timeseriesID, long flushedTime);
+
+  /**
+   * upatde latest flushed time of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @return latest flushed time of one timeseries
+   */
+  public long getLatestFlushedTime(TimeseriesID timeseriesID);
+
+  /**
+   * get latest time value pair of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @return latest time value pair of one timeseries
+   */
+  public Pair<Long, Object> getLastTimeValuePair(TimeseriesID timeseriesID);
+
+  /**
+   * update latest time value pair of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @param lastTimeValue latest time value pair of one timeseries
+   */
+  public void updateLastTimeValuePair(TimeseriesID timeseriesID, Pair<Long, Object> lastTimeValue);
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDManagerImpl.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDManagerImpl.java
new file mode 100644
index 0000000..68b537e
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDManagerImpl.java
@@ -0,0 +1,83 @@
+/*
+ * 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.id_table;
+
+import com.sun.tools.javac.util.Pair;
+import java.util.Map;
+import org.apache.iotdb.db.metadata.id_table.entry.TimeseriesID;
+
+public class IDManagerImpl implements IDManager {
+
+  /** storage group name -> ID table */
+  private Map<String, IDTable> storageGroupIDTableMap;
+
+  /**
+   * check whether a time series is exist if exist, check the type consistency if not exist, call
+   * MManager to create it
+   *
+   * @param seriesKey full path of the time series
+   * @return timeseries ID of this time series
+   */
+  @Override
+  public TimeseriesID checkOrCreateIfNotExist(String seriesKey) {
+    return null;
+  }
+
+  /**
+   * upatde latest flushed time of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @param flushedTime latest flushed time
+   */
+  @Override
+  public void updateLatestFlushedTime(TimeseriesID timeseriesID, long flushedTime) {}
+
+  /**
+   * upatde latest flushed time of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @return latest flushed time of one timeseries
+   */
+  @Override
+  public long getLatestFlushedTime(TimeseriesID timeseriesID) {
+    return 0;
+  }
+
+  /**
+   * get latest time value pair of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @return latest time value pair of one timeseries
+   */
+  @Override
+  public Pair<Long, Object> getLastTimeValuePair(TimeseriesID timeseriesID) {
+    return null;
+  }
+
+  /**
+   * update latest time value pair of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @param lastTimeValue latest time value pair of one timeseries
+   */
+  @Override
+  public void updateLastTimeValuePair(
+      TimeseriesID timeseriesID, Pair<Long, Object> lastTimeValue) {}
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDTable.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDTable.java
new file mode 100644
index 0000000..60ecf30
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/IDTable.java
@@ -0,0 +1,66 @@
+/*
+ * 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.id_table;
+
+import java.util.Map;
+import org.apache.iotdb.db.metadata.id_table.entry.DeviceEntry;
+import org.apache.iotdb.db.metadata.id_table.entry.IDeviceID;
+import org.apache.iotdb.db.metadata.id_table.entry.TimeseriesID;
+
+public class IDTable {
+
+  /**
+   * 256 hashmap for avoiding rehash performance issue and lock competition device ID ->
+   * (measurement name -> schema entry)
+   */
+  private Map<IDeviceID, DeviceEntry>[] idTables;
+
+  /** disk schema manager to manage disk schema entry */
+  private DiskSchemaManager diskSchemaManager;
+
+  /**
+   * check whether a time series is exist if exist, check the type consistency if not exist, call
+   * MManager to create it
+   *
+   * @param timeseriesID ID of the time series
+   * @return type consistency
+   */
+  public boolean checkOrCreateIfNotExist(TimeseriesID timeseriesID) {
+    return false;
+  }
+
+  /**
+   * upatde latest flushed time of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @param flushedTime latest flushed time
+   */
+  public void updateLatestFlushedTime(TimeseriesID timeseriesID, long flushedTime) {}
+
+  /**
+   * upatde latest flushed time of one timeseries
+   *
+   * @param timeseriesID timeseries id
+   * @return latest flushed time of one timeseries
+   */
+  public long getLatestFlushedTime(TimeseriesID timeseriesID) {
+    return 0;
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/DeviceEntry.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/DeviceEntry.java
new file mode 100644
index 0000000..127581a
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/DeviceEntry.java
@@ -0,0 +1,31 @@
+/*
+ * 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.id_table.entry;
+
+import java.util.Map;
+
+public class DeviceEntry {
+
+  /** for device ID reuse in memtable */
+  IDeviceID deviceID;
+
+  /** measurement schema map */
+  Map<String, SchemaEntry> measurementMap;
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/DiskSchemaEntry.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/DiskSchemaEntry.java
new file mode 100644
index 0000000..702586b
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/DiskSchemaEntry.java
@@ -0,0 +1,35 @@
+/*
+ * 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.id_table.entry;
+
+public class DiskSchemaEntry {
+
+  private byte[] deviceID;
+
+  String seriesKey;
+
+  String measurementName;
+
+  byte type;
+
+  byte encoding;
+
+  byte compressor;
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/IDeviceID.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/IDeviceID.java
new file mode 100644
index 0000000..1bfc4d6
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/IDeviceID.java
@@ -0,0 +1,22 @@
+/*
+ * 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.id_table.entry;
+
+public interface IDeviceID {}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/PlainDeviceID.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/PlainDeviceID.java
new file mode 100644
index 0000000..d1572e6
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/PlainDeviceID.java
@@ -0,0 +1,48 @@
+/*
+ * 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.id_table.entry;
+
+import java.util.Objects;
+
+/** Using device id path as id */
+public class PlainDeviceID implements IDeviceID {
+  String deviceID;
+
+  public PlainDeviceID(String deviceID) {
+    this.deviceID = deviceID;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (!(o instanceof PlainDeviceID)) {
+      return false;
+    }
+    PlainDeviceID that = (PlainDeviceID) o;
+    return Objects.equals(deviceID, that.deviceID);
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(deviceID);
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/SHA256DeviceID.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/SHA256DeviceID.java
new file mode 100644
index 0000000..46362d7
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/SHA256DeviceID.java
@@ -0,0 +1,44 @@
+/*
+ * 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.id_table.entry;
+
+/** Using sha 256 hash value of device path as device ID */
+public class SHA256DeviceID implements IDeviceID {
+  long l1;
+  long l2;
+  long l3;
+  long l4;
+
+  /** The probability that each bit of sha 256 is 0 or 1 is equal */
+  public int hashCode() {
+    return (int) l1;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (!(o instanceof SHA256DeviceID)) {
+      return false;
+    }
+    SHA256DeviceID that = (SHA256DeviceID) o;
+    return l1 == that.l1 && l2 == that.l2 && l3 == that.l3 && l4 == that.l4;
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/SchemaEntry.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/SchemaEntry.java
new file mode 100644
index 0000000..f635afe
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/SchemaEntry.java
@@ -0,0 +1,44 @@
+/*
+ * 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.id_table.entry;
+
+import java.io.Serializable;
+
+public class SchemaEntry implements Serializable {
+
+  /*    1 byte of type      */
+  /*   1 byte of encoding   */
+  /*  1 byte of compressor  */
+  /* 5 byte of disk pointer */
+  long schema;
+
+  long lastTime;
+
+  Object lastValue;
+
+  long flushTime;
+
+  public SchemaEntry(long schema, long lastTime, Object lastValue, long flushTime) {
+    this.schema = schema;
+    this.lastTime = lastTime;
+    this.lastValue = lastValue;
+    this.flushTime = flushTime;
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/TimeseriesID.java b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/TimeseriesID.java
new file mode 100644
index 0000000..ed2386a
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/id_table/entry/TimeseriesID.java
@@ -0,0 +1,25 @@
+/*
+ * 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.id_table.entry;
+
+public class TimeseriesID {
+  private IDeviceID deviceID;
+
+  private String measurement;
+}