채팅서버 rdb선행작업 삭제 후 snowflake 구현 #303
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request
Related issue
Resolve #300
Motivation and context
기존에는 채팅 서버에서 카프카를 통해 히스토리 서버로 데이터를 전달하기 전에 RDB를 이용해 고유한 ID를 생성하였습니다. 그러나 분산 환경에서 AUTO_INCREMENT 사용 시 발생할 수 있는 문제와 RDB에 데이터를 쓰는 과정에서의 지연 문제를 파악하였고, 이를 해결하기 위해 Snowflake 알고리즘을 이용한 ID 생성 방식으로 변경하였습니다.
Solution
SnowflakeIdGenerator 클래스를 추가하여 Snowflake 알고리즘을 활용한 고유 ID를 생성하도록 구현하였습니다.
기존 RDB에서 ID를 생성하는 방식에서 SnowflakeIdGenerator.nextId()를 호출하는 방식으로 변경하였습니다.
ChatService의 createCommonData 메서드에서 기존 Thread 객체의 ID를 RDB에서 가져오던 방식에서 Snowflake를 사용하여 생성하는 방식으로 변경하였습니다.
How has this been tested
로컬 환경에서 SnowflakeIdGenerator를 이용한 ID 생성이 정상적으로 동작하는지 확인하였습니다.
채팅 메시지를 전송하고, Kafka를 통해 히스토리 서버로 정상적으로 ID가 포함된 메시지가 전달되는지 테스트하였습니다.
멀티 스레드 환경에서 ID 충돌 없이 고유한 값이 생성되는지 확인하였습니다.
기존 API와의 호환성을 유지하면서 변경 사항이 정상적으로 반영되었는지 테스트하였습니다.
Types of changes
Checklist