[
https://issues.apache.org/jira/browse/HDDS-16277?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Huang Kuan Hao reassigned HDDS-16277:
-------------------------------------
Assignee: Huang Kuan Hao
> 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
>
> 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: [email protected]
For additional commands, e-mail: [email protected]