You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2023/06/01 16:01:30 UTC
[iotdb] branch opt_wal_serialize created (now 686c48450ff)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a change to branch opt_wal_serialize
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at 686c48450ff add a String Bytes Cache for wal
This branch includes the following new commits:
new 686c48450ff add a String Bytes Cache for wal
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: add a String Bytes Cache for wal
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch opt_wal_serialize
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 686c48450ffe3a4b9a9d8ed46a7462958bf6fcec
Author: HTHou <hh...@outlook.com>
AuthorDate: Fri Jun 2 00:01:12 2023 +0800
add a String Bytes Cache for wal
---
.../db/metadata/cache/WalStringBytesCache.java | 55 ++++++++++++++++++++++
.../apache/iotdb/db/wal/utils/WALWriteUtils.java | 3 +-
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/cache/WalStringBytesCache.java b/server/src/main/java/org/apache/iotdb/db/metadata/cache/WalStringBytesCache.java
new file mode 100644
index 00000000000..4d18883e339
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/cache/WalStringBytesCache.java
@@ -0,0 +1,55 @@
+/*
+ * 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.cache;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
+/** This cache is for reducing duplicated DeviceId PartialPath initialization in write process. */
+public class WalStringBytesCache {
+
+ private static final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
+
+ private final Cache<String, byte[]> stringBytesCache;
+
+ private WalStringBytesCache() {
+ stringBytesCache = Caffeine.newBuilder().maximumSize(config.getDevicePathCacheSize()).build();
+ }
+
+ public static WalStringBytesCache getInstance() {
+ return WalStringBytesCache.WalStringBytesCacheHolder.INSTANCE;
+ }
+
+ /** singleton pattern. */
+ private static class WalStringBytesCacheHolder {
+ private static final WalStringBytesCache INSTANCE = new WalStringBytesCache();
+ }
+
+ public byte[] getBytes(String s) {
+ return stringBytesCache.get(s, String::getBytes);
+ }
+
+ public void cleanUp() {
+ stringBytesCache.cleanUp();
+ }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/wal/utils/WALWriteUtils.java b/server/src/main/java/org/apache/iotdb/db/wal/utils/WALWriteUtils.java
index 5eb016ced79..df7893944a6 100644
--- a/server/src/main/java/org/apache/iotdb/db/wal/utils/WALWriteUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/wal/utils/WALWriteUtils.java
@@ -18,6 +18,7 @@
*/
package org.apache.iotdb.db.wal.utils;
+import org.apache.iotdb.db.metadata.cache.WalStringBytesCache;
import org.apache.iotdb.db.wal.buffer.IWALByteBufferView;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -124,7 +125,7 @@ public class WALWriteUtils {
return write(NO_BYTE_TO_READ, buffer);
}
int len = 0;
- byte[] bytes = s.getBytes();
+ byte[] bytes = WalStringBytesCache.getInstance().getBytes(s);
len += write(bytes.length, buffer);
buffer.put(bytes);
len += bytes.length;