You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2026/08/25 13:21:00 UTC
[jira] [Updated] (HDDS-16277) Reuse CharsetEncoder/Decoder in StringCodec
[ https://issues.apache.org/jira/browse/HDDS-16277?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
ASF GitHub Bot updated HDDS-16277:
----------------------------------
Labels: pull-request-available (was: )
> Reuse CharsetEncoder/Decoder in StringCodec
> -------------------------------------------
>
> Key: HDDS-16277
> URL: https://issues.apache.org/jira/browse/HDDS-16277
> Project: Apache Ozone
> Issue Type: Sub-task
> Reporter: Huang Kuan Hao
> Assignee: Huang Kuan Hao
> Priority: Major
> Labels: pull-request-available
>
> StringCodec is the key/value codec for many RocksDB tables (used across ~33 files). encode(...) allocates a fresh CharsetEncoder inside the returned lambda, and decodeNoFallback/decodeWithFallback allocate a fresh CharsetDecoder — on every encode/decode, i.e. per record on reads, writes and iteration:
> final CoderResult result = newEncoder().encode(CharBuffer.wrap(string), buffer, true);
> ...
> return newDecoder().decode(buffer.asReadOnlyBuffer()).toString();
> Fix: hold the coders in per-instance ThreadLocals (they are stateful and not thread-safe), configured once, and reset() before each use:
> private final ThreadLocal<CharsetEncoder> encoder = ThreadLocal.withInitial(this::newEncoder);
> private final ThreadLocal<CharsetDecoder> decoder = ThreadLocal.withInitial(this::newDecoder);
> ...
> final CoderResult result = encoder.get().reset().encode(CharBuffer.wrap(string), buffer, true);
> ...
> return decoder.get().reset().decode(buffer.asReadOnlyBuffer()).toString();
> reset() clears only the coding state, not the configured onMalformedInput/onUnmappableCharacter actions, so behavior is unchanged.
> File: hadoop-hdds/common/.../hdds/utils/db/StringCodecBase.java
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org