INTERNAL: Remove redudant operation type RW.#879
Conversation
|
리뷰 노티 한번 더 드립니다 |
| setOperationType(OperationType.WRITE); | ||
| } else { | ||
| setOperationType(OperationType.READ); | ||
| if (collectionGet.isDelete() || collectionGet.isDropIfEmpty()) { |
There was a problem hiding this comment.
collectionGet.isDropIfEmpty() 조건은 제거합시다.
delete가 false이면 dropIfEmpty가 true이더라도 delete가 수행되지 않습니다.
d73711f to
a209ee6
Compare
|
이 pr에서 버그가 있었습니다. enum 타입은 싱글톤으로 관리되기 때문에 한번 OperationType을 바꾸면 다른 곳에서 객체를 가져올 때 바뀌어진 값을 가져오게 됩니다. 따라서 RW 타입을 그대로 유지하거나 다른 방법을 생각해보아야 합니다. @Test
void test() {
ListGet listGet = new ListGet(0, true, true);
CollectionGetOperationImpl op = new CollectionGetOperationImpl("key", listGet, null);
APIType type1 = op.getAPIType();
assertEquals(OperationType.WRITE, type1.getAPIOpType());
ListGet listGet2 = new ListGet(0, false, false);
CollectionGetOperationImpl op2 = new CollectionGetOperationImpl("key", listGet2, null);
APIType type2 = op2.getAPIType();
assertEquals(OperationType.READ, type2.getAPIOpType()); // OperationType.WRITE가 반환되어 테스트가 실패한다.
} |
|
@brido4125 |
현재 구현 상으로는 API Read Priority를 설정하고 아래 PR이 반영될 경우에는 api type을 통해서 @oliviarla LOP_GET(OperationType.READ),
LOP_GET_DELETE(OperationType.WRITE), |
|
@brido4125 @oliviarla |
|
그러면 API Type에 따라 read Priority를 설정할 수 있는 기능을 제거하나요? |
|
아래 코멘트처럼 이미 APIType Read Priority 기능이 그래서 API Type 이넘은 유지를 하고 앞선 코멘트 처럼 |
|
@brido4125 @oliviarla |
|
살펴보니 APIType이 OperationType을 가지지 않을 경우 아래 문제가 있었네요 이렇게 될 경우 현재 구현대로 서로 결합된 형태를 가지는게 맞는것 같습니다. private ReplicaPick getReplicaPick(APIType apiType) {
ReplicaPick pick = ReplicaPick.MASTER;
if (apiType.getAPIOpType() == OperationType.READ) {
ReadPriority readPriority = connFactory.getAPIReadPriority().get(apiType);
if (readPriority == null) {
readPriority = connFactory.getReadPriority();
}
if (readPriority == ReadPriority.SLAVE) {
pick = ReplicaPick.SLAVE;
} else if (readPriority == ReadPriority.RR) {
pick = ReplicaPick.RR;
}
}
return pick;
}그래서 APIType과 OpType이 결합이 되어야한다면 |
어떤 연산을 생성하는 로직인 지 관련 코드를 제시해 주세요. |
|
XopBulkInsert와 같은 groupingKeys를 사용하는 연산들입니다. |
|
@brido4125 |
|
APIType과 OpType을 분리한다는 가정하에서 private ReplicaPick getReplicaPick(APIType apiType, OperationType opType) {
ReplicaPick pick = ReplicaPick.MASTER;
if (opType == OperationType.READ) {
ReadPriority readPriority = connFactory.getAPIReadPriority().get(apiType);
if (readPriority == null) {
readPriority = connFactory.getReadPriority();
}
if (readPriority == ReadPriority.SLAVE) {
pick = ReplicaPick.SLAVE;
} else if (readPriority == ReadPriority.RR) {
pick = ReplicaPick.RR;
}
}
return pick;
}특히 groupingKeys 구현이 현재보다 좀 지저분해지는 느낌이 있긴한데, |
|
@jhpark816 @brido4125 물론 private 메서드이기 때문에 저희가 신경써서 구현하면 되지만, 혼돈을 막고 강제성을 부여하기 위해 ApiType과 OperationType은 결합된 형태로 두는게 나을 것 같습니다. |
🔗 Related Issue
https://github.com/jam2in/arcus-works/issues/692
⌨️ What I did
CollectionGet 연산의 경우 dropIfEmpty 또는 withDelete 등의
옵션에 의해 write 연산이 될 가능성을 가진 read 연산이다.
이전에는 이를 구별하기 위해 OperationType.RW를 사용했지만
setAPIReadPriority 메서드에서만 해당 타입이 사용된다.
이 타입을 제거하고 디폴트로는 read를 설정하고
CollectionGetOperationImpl 생성자에서
dropIfEmpty와 withDelete 여부를 확인 한 다음
write 타입으로 변경하도록 한다.
(기존 생성자에서는 dropIfEmpty를 확인하지 않았다)
추가적으로 collectionGet이 read 타입이 디폴트이기 때문에
apiReadPriorityList에 readPriority를 설정할 수 있다.
collectionGet 연산은 op가 생성된 후에 replica pick을 설정하는 api 이기 때문에
write 연산임에도 readPriority가 설정되는 버그가 발생하지는 않는다.