Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: Refactor Future in asyncCollectionInsertBulk2 method. #644

Merged
merged 1 commit into from
Jul 24, 2023

Conversation

brido4125
Copy link
Collaborator

@brido4125 brido4125 commented Jul 21, 2023

관련 이슈

https://github.com/jam2in/arcus-works/issues/403

Motivation

기존의 asyncCollectionInsertBulk2 메서드는
내부적으로 익명 Future 클래스를 구현하여 리턴한다.
이러한 구조를 다른 api들과 동일하게
Future rv 생성 -> 연산 결과를 rv에 전달 -> rv 리턴
구조로 변경한다.

참고로 asyncCollectionInsertBulk2
여러 컬렉션에 동일한 Elem을 삽입하는 api에서 사용된다.

변경된 지점

기존에 존재하는 BulkOperationFuture 를 사용하여 Future를 생성합니다.

@brido4125 brido4125 self-assigned this Jul 21, 2023
@brido4125 brido4125 marked this pull request as draft July 21, 2023 06:49
@brido4125 brido4125 marked this pull request as ready for review July 21, 2023 06:51
import java.util.concurrent.TimeoutException;
import java.util.concurrent.ExecutionException;

public class PipedBulkCollectionFuture<K, V> extends PipedCollectionFuture<K, V> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Java Client에서 Piped와 Bulk는 여러 연산을 처리한다는 점에선 공통점을 갖고 있으나, 다음과 같은 차이점이 있습니다.
Piped : 동일한 키에 여러 번 연산
Bulk : 서로 다른 키에 하나 씩 연산
따라서 두 용어를 함께 쓰는 것보다, Bulk만 붙이는 것이 나을 것 같습니다.

Copy link
Collaborator Author

@brido4125 brido4125 Jul 21, 2023

Choose a reason for hiding this comment

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

해당 코멘트 분석하며 BulkOperationFuture를 확인해본 결과
asyncCollectionInsertBulk2에서
리턴해주는 Type이 Future 인터페이스 타입이기 때문에
내부에서 생성하는 Future Type을 BulkOperationFuture를 사용해도
정상적으로 동작하는것을 확인했습니다.

결론적으로 새로운 Type의 Future가 아닌 기존에 존재하는 Type으로 대체하도록 구현했습니다.

}

@Override
public Map<K, V> get(long duration, TimeUnit units)
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 메소드의 구현이 부모 클래스와 다르지 않은 것 같은데 따로 구현한 이유가 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

대부분 로직이 동일해보이지만 아래로직이 서로 다름을 확인할 수 있습니다.

else {
    // continuous timeout counter will be reset only once in pipe
    MemcachedConnection.opsSucceeded(ops);
}

부모 클래스의 경우 piped 연산의 key 값이 동일해서
opSucceded(ops.iterator().next())로 구현됩니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

부모 클래스에 override 가능한 opSucceeded() 메소드를 만들고, 두 클래스 간에 차이나는 부분만 이 메소드에 구현한 다음 get()에서는 opSucceeded() 메소드를 호출하도록 하면 어떨까요?

@brido4125 brido4125 force-pushed the refactor/bulk2InsertFuture branch 2 times, most recently from c4816a0 to e6a3e97 Compare July 21, 2023 08:24
@brido4125 brido4125 requested a review from uhm0311 July 24, 2023 01:46
Copy link
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.

리뷰 완료


public void addOperation(Operation op) {
ops.add(op);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

addOperation() 메소드를 setOperation() 메소드의 다음 위치로 옮기거나
아니면, setOperation() 메소드를 addOperation() 바로 위로 옮기면 좋겠습니다.

Copy link
Collaborator

@jhpark816 jhpark816 Jul 24, 2023

Choose a reason for hiding this comment

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

그리고 사용되지 않는 메소드이지만, 아래 메소드도 추가해 두면 좋겠습니다.

      public CollectionOperationStatus getOperationStatus() {
        return null;
      }

Copy link
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.

리뷰 완료

}

public CollectionOperationStatus getOperationStatus() {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

지금 보니,
BulkOperationFuture가 외부 interface에 노출된 것이 아니네요.
외부에는 Future interface가 노출된 상태이기 때문에,
getOperationStatus() 메소드는 없어도 될 것 같습니다.

@jhpark816 jhpark816 merged commit 6e2c63b into naver:develop Jul 24, 2023
1 check 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