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

ENHANCE: Optimize groupingKeys() logic #602

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

brido4125
Copy link
Collaborator

@brido4125 brido4125 commented May 9, 2023

작업 개요

if (keyList == null) {
      throw new IllegalArgumentException("Key list is null.");
    }
  • 만약 empty 검사를 하지 않으면 groupingKeys() 메서드 내에서 for Loop을 돌지 않아 empty Collection을 반환하게 됩니다.

변경 사항

  • 기존에는 List keyList가 empty로 들어올 경우 예외를 발생 시키지 않고 size 0인 컬렉션을 반환했습니다.
  • 저는 해당 사항 또한 예외를 통해 사용자에게 상황을 알려줘야한다고 생각하여 empty check를 수행했습니다.
  • List 요소가 Duplication인 경우는 기존에는 예외를 발생시켰는데 저는 자동으로 중복 요소를 걸러서 연산을 진행하도록 변경했습니다.
  • 위 두 사항으로 인해 일부 테스트 코드에 변경이 있었습니다.
  • 위 두 가지 부분에 대해서 의견 부탁드립니다.

@brido4125 brido4125 requested review from jhpark816 and namsic May 9, 2023 08:45
@brido4125 brido4125 changed the title Refactor/validate keys INTERAL:Refactor validate keys May 9, 2023
@brido4125 brido4125 changed the title INTERAL:Refactor validate keys INTERNAL:Refactor validate keys May 9, 2023
@brido4125 brido4125 self-assigned this May 9, 2023
@namsic namsic marked this pull request as draft May 9, 2023 08:56
@brido4125 brido4125 force-pushed the refactor/validateKeys branch 2 times, most recently from 0891972 to c5d4c62 Compare May 9, 2023 11:22
@brido4125 brido4125 marked this pull request as ready for review May 9, 2023 11:30
Comment on lines 348 to 356
/*
* Dup Check -> insure elements sequentially added to keyList
* */
HashSet<String> keySet = new HashSet<String>(keyList);
if (keySet.size() != keyList.size()) {
getLogger().info("Duplicate keys provided, deduping.");
keyList.clear();
keyList.addAll(keySet);
}
Copy link
Collaborator

@namsic namsic May 10, 2023

Choose a reason for hiding this comment

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

서버에서는 multiple keys pipe 명령 처리 시 duplicate key가 존재하지 않는다는 가정 하에 동작합니다.

기존 예외 발생 대신 위와 같이 변경 시 서버로 전송되는 명령에 duplicate key가 존재할 수 있는지 || 동작 정확성에 문제가 없는지 확인이 필요합니다.

@jhpark816
Copy link
Collaborator

  • duplicate key 존재하면, 기존처럼 exception throw 하여 응용에서 알게 하는 것이 좋겠습니다.
  • empty key list 경우도 exception throw 하는 것이 맞을 것입니다.

@brido4125
Copy link
Collaborator Author

  • 기존 사항대로 dup인 경우 예외 처리 로직 발생시키도록 변경했습니다

@jhpark816
Copy link
Collaborator

@brido4125 본 PR도 수정 바랍니다.

@@ -237,16 +237,31 @@ public void testGetBulkNotFoundMixed() {
}
}

public void testErrorArguments() {
public void testEmptyKeyList() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존 테스트는 empty key list와 max count list를 함께 진행하였고,
empty key list가 인자로 들어가는 경우
exception이 발생하지 않았습니다.

변경된 로직에서는 예외를 발생 시키기에
empty key list와 max count list 테스트 코드를
별도의 메서드로 나누었습니다.

@@ -265,12 +265,6 @@ public void testErrorArguments() {
Map<String, BTreeGetResult<ByteArrayBKey, Object>> results = null;
CollectionGetBulkFuture<Map<String, BTreeGetResult<ByteArrayBKey, Object>>> f = null;

// empty key list
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

위 테스트와 중복되는 테스트 로직이라서 제거 하였습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

어떤 이유로 BopGetBulk 테스트가 2군데 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

longBkey인 경우가 패키지를 따로 두어 구현되어있습니다

@@ -457,7 +457,7 @@ public void testInvalidArgumentException() {
mc.asyncBopSortMergeGet(null, 10, 0, ElementFlagFilter.DO_NOT_FILTER, -1, 10);
fail("This should be an exception");
} catch (Exception e) {
assertEquals("Key list is empty.", e.getMessage());
assertEquals("Key list is null.", e.getMessage());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존 로직은 null이 들어가도
"Key list is empty."라는
로그가 발생하였고, 이를 "Key list is 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.

리뷰 완료

throw new IllegalArgumentException("Duplicate keys exist in key list.");
}
validateKey(key);
}
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

Choose a reason for hiding this comment

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

그리고, 이 메소드를 ArcusClient에서만 호출한다면, ArcusClient 코드로 옮깁시다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존 로직에서 groupingKeys()를 호출하는 경우 중복 키를 검사하니
해당 함수를 호출하는 api들에 대해서만 키 중복 검사를 하는 메서드를 호출하도록 변경하겠습니다.

f = mc.asyncBopGetBulk(new ArrayList<String>(), new byte[]{0},
new byte[]{10}, ElementFlagFilter.DO_NOT_FILTER, 0, 10);
results = f.get(1000L, TimeUnit.MILLISECONDS);
Assert.assertEquals(0, results.size());
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.

코멘트 남겨두었습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 try catch 문으로 수행하도록 합시다.

향후에 두 형태의 test 파일을 하나로 합치는 작업을 진행하는 것이 좋겠습니다.

ElementFlagFilter.DO_NOT_FILTER, 0, 10);
results = f.get(1000L, TimeUnit.MILLISECONDS);
Assert.assertEquals(0, results.size());
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

외부에 try 문이 있으므로, 내부에 try 문을 넣지 않도록 하죠.

Copy link
Collaborator

Choose a reason for hiding this comment

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

테스트 코드의 의미를 보니, 내부 try 문이 있어야 하겠네요.
empty key list 코드를 try catch 문으로 수행하도록 하고,
메소드는 나누지 말고 그대로 두시죠.

@jhpark816
Copy link
Collaborator

commit message 형식도 수정 바랍니다.

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.

리뷰 완료

ElementFlagFilter.DO_NOT_FILTER, 0, 10);
results = f.get(1000L, TimeUnit.MILLISECONDS);
Assert.assertEquals(0, results.size());
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

테스트 코드의 의미를 보니, 내부 try 문이 있어야 하겠네요.
empty key list 코드를 try catch 문으로 수행하도록 하고,
메소드는 나누지 말고 그대로 두시죠.

f = mc.asyncBopGetBulk(new ArrayList<String>(), new byte[]{0},
new byte[]{10}, ElementFlagFilter.DO_NOT_FILTER, 0, 10);
results = f.get(1000L, TimeUnit.MILLISECONDS);
Assert.assertEquals(0, results.size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 try catch 문으로 수행하도록 합시다.

향후에 두 형태의 test 파일을 하나로 합치는 작업을 진행하는 것이 좋겠습니다.

@brido4125 brido4125 force-pushed the refactor/validateKeys branch 2 times, most recently from d0fb997 to 286585a Compare June 14, 2023 08:05
@brido4125 brido4125 changed the title INTERNAL:Refactor validate keys ENHANCE: Optimize groupingKeys() logic Jun 14, 2023
@@ -237,16 +237,20 @@ public void testGetBulkNotFoundMixed() {
}
}

public void testErrorArguments() {
public void testErrorArgument() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

기존대로 testErrorArguments 로 합시다.

@@ -260,6 +264,7 @@ public void testErrorArguments() {
e.printStackTrace();
Assert.fail(e.getMessage());
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

empty 라인을 추가하지 않아도 됩니다.

@jhpark816 jhpark816 merged commit 417bee8 into naver:develop Jun 14, 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.

None yet

3 participants