cxzl25 commented on code in PR #1743:
URL: https://github.com/apache/orc/pull/1743#discussion_r1449856295


##########
java/core/src/java/org/apache/orc/impl/ZstdCodec.java:
##########
@@ -0,0 +1,307 @@
+/*
+ * 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.orc.impl;
+
+import com.github.luben.zstd.Zstd;
+import com.github.luben.zstd.ZstdCompressCtx;
+import org.apache.orc.CompressionCodec;
+import org.apache.orc.CompressionKind;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+public class ZstdCodec implements CompressionCodec {
+  private ZstdOptions zstdOptions = null;
+  private ZstdCompressCtx zstdCompressCtx = null;
+
+  public ZstdCodec(int level, int windowLog, boolean longMode, boolean fixed) {
+    this.zstdOptions = new ZstdOptions(level, windowLog, longMode, fixed);
+  }
+
+  public ZstdCodec(int level, int windowLog) {
+    this(level, windowLog, false, false);
+  }
+
+  public ZstdCodec() {
+    this(3, 0);
+  }
+
+  public ZstdOptions getZstdOptions() {
+    return zstdOptions;
+  }
+
+  // Thread local buffer
+  private static final ThreadLocal<byte[]> threadBuffer =
+          ThreadLocal.withInitial(() -> null);
+
+  protected static byte[] getBuffer(int size) {
+    byte[] result = threadBuffer.get();
+    if (result == null || result.length < size || result.length > size * 2) {
+      result = new byte[size];
+      threadBuffer.set(result);

Review Comment:
   Last night I was referring to the implementation of `AircompressorCodec` and 
also noticed the threadlocal implementation of `threadBuffer`.
   
   There should be some leaks here. For example, Spark Task allows long idle 
periods and threads are not recycled.



-- 
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]

Reply via email to