Skip to content

FEATURE: Add pluggable compression codec support with Snappy algorithm#1074

Merged
jhpark816 merged 1 commit intonaver:developfrom
f1v3-dev:feat/compression
Apr 21, 2026
Merged

FEATURE: Add pluggable compression codec support with Snappy algorithm#1074
jhpark816 merged 1 commit intonaver:developfrom
f1v3-dev:feat/compression

Conversation

@f1v3-dev
Copy link
Copy Markdown
Collaborator

@f1v3-dev f1v3-dev commented Apr 2, 2026

🔗 Related Issue

⌨️ What I did

압축 인터페이스 도입 및 Snappy 알고리즘을 추가합니다.

  • 기존 CompressionUtils.java 에 하드코딩된 GZIP 압축 방식을 CompressionCodecIF 인터페이스 기반으로 변경합니다.
    • GZIPCompressionCodec: 기존 GZIP 로직을 구현체로 분리 (기본값)
    • SnappyCompressionCodec: snappy-java 기반의 구현체 추가
  • BaseSerializingTranscoder, GenericJsonSerializingTranscoder, JsonSerializingTranscoder 에서 생성자(Builder)를 통해 압축 코덱을 주입받도록 변경합니다.
  • 기존 클라이언트에서 별도 설정 없이도 기본값인 GZIP을 사용하도록 하위 호환성을 보장합니다.

@f1v3-dev f1v3-dev requested a review from oliviarla April 2, 2026 09:02
@f1v3-dev f1v3-dev self-assigned this Apr 2, 2026
Copy link
Copy Markdown
Collaborator

@oliviarla oliviarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료입니다.

Comment thread src/main/java/net/spy/memcached/transcoders/compression/GZIPCompressionCodec.java Outdated
Comment on lines +31 to +33
byte[] result = bos.toByteArray();
getLogger().debug("Compressed %d bytes to %d", in.length, result.length);
return result;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기를 try 문 안으로 이동할 수 있나요?

Copy link
Copy Markdown
Collaborator Author

@f1v3-dev f1v3-dev Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 말씀해주신대로 try-catch 블록 안에 bos.toByteArray() 를 옮기고싶었는데, 그렇게 하게 되었을 때 정상적인 결과를 얻을 수 없습니다.

원인을 찾아보니 GZIPOutputStream(gz) 에서 close가 정상적으로 되어야만 ByteArrayOutputStream(bos) 에서 bos.toByteArray() 가 호출이 가능해집니다.

따라서, try-catch 블록 안으로 옮기기 위해서는 아래와 같은 코드로 변경해야하는데 어떤 방식이 더 적합할까요?

@Override
  public byte[] compress(byte[] in) {
    if (in == null) {
      throw new NullPointerException("Can't compress null");
    }

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (GZIPOutputStream gz = new GZIPOutputStream(bos)) {
      gz.write(in);
      gz.finish(); // or gz.close();

      byte[] result = bos.toByteArray();
      getLogger().debug("Compressed %d bytes to %d", in.length, result.length);
      return result;
    } catch (IOException e) {
      throw new RuntimeException("IO exception compressing data", e);
    }
  }

저는 try-with-resources를 통해서 자원을 자동으로 반납한 후에 데이터를 가져오는 방향으로 구현했던 것이었습니다.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snappy codec과 일관성이 맞지 않아 코멘트한 것이었으나, 로직이 부가적으로 필요하다면 지금대로 두는게 낫습니다.

Comment thread src/main/java/net/spy/memcached/transcoders/SerializingTranscoder.java Outdated
@f1v3-dev f1v3-dev force-pushed the feat/compression branch 3 times, most recently from 971c452 to f83da33 Compare April 20, 2026 06:54
oliviarla
oliviarla previously approved these changes Apr 20, 2026
oliviarla
oliviarla previously approved these changes Apr 20, 2026
@jhpark816 jhpark816 requested a review from uhm0311 April 20, 2026 10:32
Copy link
Copy Markdown
Collaborator

@jhpark816 jhpark816 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 완료

@@ -0,0 +1,12 @@
package net.spy.memcached.transcoders.compression;

public interface CompressionCodecIF {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

막상 코드를 보니, "IF" 문자를 제거하는 것이 자연스러울 것 같습니다.
예전에 넣자고 했는 데, 지금은 다시 제외하는 것이 나을 것 같습니다.
어떤가요?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구현체(GZIPCompressionCodec, SnappyCompressionCodec)가 명확하게 분리되어 있어서 IF 문자를 없애는 방향도 좋아보입니다.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviarla @f1v3-dev
여기서는 IF 문자를 제거하는 것이 좋겠습니다.

@jhpark816 jhpark816 merged commit 97f9790 into naver:develop Apr 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants