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: add PipeOperationImpl to reduce duplicate code #872

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

oliviarla
Copy link
Collaborator

@oliviarla oliviarla commented Jan 22, 2025

๐Ÿ”— Related Issue

  • ์•ž์œผ๋กœ pipe operation implementation ๋ณ€๊ฒฝ ์ง€์ ์ด ๋งŽ์•„์งˆ ๊ฒƒ์„ ๊ณ ๋ คํ•˜์—ฌ PipeOperationImpl ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์ด๋ฅผ ๊ฐ๊ฐ์˜ ํด๋ž˜์Šค๊ฐ€ ์ƒ์†๋ฐ›๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
  • ๋˜ํ•œ, ์ด์ „์— pipe_error๊นŒ์ง€ ์ฝ๋Š” ๋กœ์ง์„ CollectionPipedInsertOperationImpl์—๋งŒ ์ ์šฉํ–ˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์—, ํ•˜๋‚˜์˜ ์ถ”์ƒ ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›๋„๋ก ํ•˜์—ฌ CollectionPipedUpdateOperationImpl, CollectionPipedExistOperationImpl, CollectionBulkInsertOperationImpl์—๋„ ์ ์šฉํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

โŒจ๏ธ What I did

  • handleLine, initialize ๋“ฑ์˜ ๋ฉ”์„œ๋“œ ์ค‘๋ณต๊ณผ static ํ•„๋“œ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • handleLine์—์„œ ๊ฐ ์—ฐ์‚ฐ(insert/exist/update/bulk insert)๋งˆ๋‹ค ๋‹ค๋ฅด๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š” ๋ถ€๋ถ„์€ ์ถ”์ƒ ๋ฉ”์„œ๋“œ๋กœ ๋นผ ๊ฐ ํด๋ž˜์Šค์—์„œ ๊ตฌํ˜„ํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • wasCancelled ๋ฉ”์„œ๋“œ๋Š” ์—ฐ์‚ฐ๋งˆ๋‹ค ๋‹ค๋ฃฐ CANCELLED ์ƒํƒœ๊ฐ€ ๋‹ฌ๋ผ ๊ฐ ํด๋ž˜์Šค์—์„œ ๊ตฌํ˜„ํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • getInsert/ getExist / getUpdate ๋ฉ”์„œ๋“œ๋Š” ํ˜•๋ณ€ํ™˜์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ ํด๋ž˜์Šค์—์„œ ๊ตฌํ˜„ํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

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.

๋ฆฌ๋ทฐ ์™„๋ฃŒ

@oliviarla
Copy link
Collaborator Author

@uhm0311 @jhpark816 ๋‹ค์‹œ ๋ฆฌ๋ทฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

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.

์ผ๋ถ€ ๋ฆฌ๋ทฐ

false, "EFLAG_MISMATCH", CollectionResponse.EFLAG_MISMATCH);

protected static final OperationStatus EXIST_CANCELED = new CollectionOperationStatus(
false, "collection canceled", CollectionResponse.CANCELED);
Copy link
Collaborator

Choose a reason for hiding this comment

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

STORE_CANCELED์™€ EXIST_CANCELED๋Š” ์‚ฌ์‹ค์ƒ ๊ฐ™์€ ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค.
CANCELED ๊ฐ์ฒด ํ•˜๋‚˜๋กœ ํ†ต์ผํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator

Choose a reason for hiding this comment

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

์•„๋ž˜ ํ˜•ํƒœ์˜ wasCancelled() ๋ฉ”์†Œ๋“œ๋ฅผ ์—ฌ๊ธฐ ํด๋ž˜์Šค์— ๋‘๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  protected void wasCancelled() {
    OperationStatus status = new CollectionOperationStatus(
          false, "collection canceled", CollectionResponse.CANCELED);
    getCallback().receivedStatus(status);
  }

if (isSingleKey) {
// Only one NOT_MY_KEY is provided in response of
// single key piped operation when redirection.
addRedirectSingleKeyOperation(line, keys.get(0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bulk ์—ฐ์‚ฐ์ธ ๊ฒฝ์šฐ์—๋„ isNotPiped()์ด๋ฉด singleKey์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด ๊ฒฝ์šฐ, addRedirectSingleKeyOperation() ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

Bulk ์—ฐ์‚ฐ์˜ ๊ธฐ์กด ์ฝ”๋“œ๋Š” isNotPiped() ์—ฌ๋ถ€์— ๊ด€๊ณ„ ์—†์ด
addRedirectMultiKeyOperation() ํ˜ธ์ถœํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ์ง€ ํ™•์ธ ๋ฐ”๋ž๋‹ˆ๋‹ค.

Copy link
Collaborator

Choose a reason for hiding this comment

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

๋ฉ€ํ‹ฐํ‚ค ์—ฐ์‚ฐ์˜ ๊ฒฝ์šฐ Redirect๊ฐ€ ํ•„์š”ํ•œ ํ‚ค๋งŒ์„ ์ƒˆ๋กœ์šด ์—ฐ์‚ฐ ๊ฐ์ฒด์— ๋ณต์ œํ•˜๋Š” ๋กœ์ง์ด ์žˆ์Šต๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ํ˜„์žฌ ์ƒํƒœ๋กœ๋Š” ์•„๋งˆ ์ด๋ฏธ ์ฒ˜๋ฆฌ๊ฐ€ ์™„๋ฃŒ๋œ ํ‚ค๋„ ๊ทธ๋Œ€๋กœ Redirect ๋˜์–ด ์ค‘๋ณต ์ ์šฉ๋  ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

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.

์ถ”๊ฐ€ ๋ฆฌ๋ทฐ

private int index = 0;
private boolean readUntilLastLine = false;

protected PipeOperationImpl(List<String> keys, CollectionPipe collectionPipe,
Copy link
Collaborator

Choose a reason for hiding this comment

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

keys ์ธ์ž๋งŒ์œผ๋กœ๋Š” ์•„๋ž˜ ๊ฒฝ์šฐ๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

  • single key pipe
  • multiple key pipe, but key count == 1

์ด๋ฅผ ๊ตฌ๋ถ„ํ•˜๋ ค๋ฉด, boolean isBulk ์ธ์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜
collectionPipe ์ธ์ž๋ฅผ ํ†ตํ•ด isBulk ์ธ์ง€๋ฅผ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

throw new IllegalArgumentException("No keys provided");
}
this.keys = keys;
this.isSingleKey = keys.size() == 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

isSingleKey ์‚ฌ์šฉ๋˜๋Š” ๊ณณ์„ ๋ณด๋‹ˆ,
multiple key pipe์ธ bulk ์—ฐ์‚ฐ์ด ์•„๋‹˜์„ ํ™•์ธํ•˜๊ณ  ๊ทธ์— ๋”ฐ๋ผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•จ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ, ๋‹จ์ˆœํžˆ keys.size()๋กœ ๋น„๊ตํ•˜๋Š” ๊ฒƒ์€ ๋งž์ง€ ์•Š๊ณ ,
collectionPipe๊ฐ€ CollectionBulkInsert ํƒ€์ž…์ด ์•„๋‹Œ ์ง€๋ฅผ ํ™•์ธํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

} else {
index++;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

์งˆ๋ฌธ์ž…๋‹ˆ๋‹ค.
isNotPiped() ๊ฒฝ์šฐ์—์„œ NOT_MY_KEY ์‘๋‹ต์„ ๋ฐ›์œผ๋ฉด,
single key pipe์ด๋“  multi key pipe์ด๋“  ๊ด€๊ณ„์—†์ด ์•„๋ž˜ ๋กœ์ง์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‚˜์š”?

       addRedirectSingleKeyOperation(line, keys.get(index));
       transitionState(OperationState.REDIRECT);

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.

4 participants