-
Notifications
You must be signed in to change notification settings - Fork 47
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: make lop piped operations process synchronously #795
Open
oliviarla
wants to merge
1
commit into
naver:develop
Choose a base branch
from
oliviarla:pipe2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
|
@@ -38,6 +39,7 @@ | |
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.IntFunction; | ||
import java.util.jar.JarFile; | ||
import java.util.jar.Manifest; | ||
|
||
|
@@ -1852,11 +1854,16 @@ public <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> asyncLopPip | |
insertList.add(new ListPipedInsert<>(key, index, valueList, attributesForCreate, tc)); | ||
} else { | ||
PartitionedList<T> list = new PartitionedList<>(valueList, MAX_PIPED_ITEM_COUNT); | ||
|
||
for (List<T> elementList : list) { | ||
insertList.add(new ListPipedInsert<>(key, index, elementList, attributesForCreate, tc)); | ||
if (index >= 0) { | ||
index += elementList.size(); | ||
} | ||
} | ||
} | ||
return asyncCollectionPipedInsert(key, insertList); | ||
|
||
return syncCollectionPipedInsert(key, Collections.unmodifiableList(insertList)); | ||
} | ||
|
||
@Override | ||
|
@@ -3114,6 +3121,74 @@ public void gotStatus(Integer index, OperationStatus status) { | |
return rv; | ||
} | ||
|
||
/** | ||
* Pipe insert method for collection items. | ||
* | ||
* @param key arcus cache key | ||
* @param insertList must not be empty. | ||
* @return future holding the map of element index and the reason why insert operation failed | ||
*/ | ||
private <T> CollectionFuture<Map<Integer, CollectionOperationStatus>> syncCollectionPipedInsert( | ||
final String key, final List<CollectionPipedInsert<T>> insertList) { | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
final PipedCollectionFuture<Integer, CollectionOperationStatus> rv = | ||
new PipedCollectionFuture<>(latch, operationTimeout); | ||
|
||
final List<Operation> ops = new ArrayList<>(insertList.size()); | ||
IntFunction<OperationCallback> makeCallback = opIdx -> new CollectionPipedInsertOperation.Callback() { | ||
// each result status | ||
public void receivedStatus(OperationStatus status) { | ||
CollectionOperationStatus cstatus; | ||
|
||
if (status instanceof CollectionOperationStatus) { | ||
cstatus = (CollectionOperationStatus) status; | ||
} else { | ||
getLogger().warn("Unhandled state: " + status); | ||
cstatus = new CollectionOperationStatus(status); | ||
} | ||
rv.setOperationStatus(cstatus); | ||
} | ||
|
||
// complete | ||
public void complete() { | ||
if (opIdx == insertList.size() - 1 || rv.hasErrored() || rv.isCancelled()) { | ||
latch.countDown(); | ||
} else if (!rv.getOperationStatus().isSuccess()) { | ||
// If this operation failed, remaining subsequent operation | ||
// should not be added and should be marked as cancelled. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. complete() ๋ก์ง์ ์๋ฒฝํ๊ฒ ๋ง๋ค๋ ค๋ฉด, |
||
rv.addEachResult((opIdx + 1) * MAX_PIPED_ITEM_COUNT, | ||
new CollectionOperationStatus(false, "CANCELED", CollectionResponse.CANCELED)); | ||
latch.countDown(); | ||
} else { | ||
// add next operation if this is not last op | ||
Operation nextOp = ops.get(opIdx + 1); | ||
rv.addOperation(nextOp); | ||
addOp(key, nextOp); | ||
} | ||
} | ||
|
||
// got status | ||
public void gotStatus(Integer index, OperationStatus status) { | ||
if (status instanceof CollectionOperationStatus) { | ||
rv.addEachResult(index + (opIdx * MAX_PIPED_ITEM_COUNT), | ||
(CollectionOperationStatus) status); | ||
} else { | ||
rv.addEachResult(index + (opIdx * MAX_PIPED_ITEM_COUNT), | ||
new CollectionOperationStatus(status)); | ||
} | ||
} | ||
}; | ||
|
||
for (int i = 0; i < insertList.size(); i++) { | ||
final CollectionPipedInsert<T> insert = insertList.get(i); | ||
Operation op = opFact.collectionPipedInsert(key, insert, makeCallback.apply(i)); | ||
ops.add(op); | ||
} | ||
rv.addOperation(ops.get(0)); | ||
addOp(key, ops.get(0)); | ||
return rv; | ||
} | ||
|
||
@Override | ||
public Future<Map<String, CollectionOperationStatus>> asyncBopInsertBulk( | ||
List<String> keyList, long bkey, byte[] eFlag, Object value, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rv.getOperationStatus().isSuccess()
์กฐ๊ฑด์ผ๋ก next ์ฐ์ฐ ์ํ ์ฌ๋ถ๋ฅผ ํ๋จํ๊ธฐ ์ด๋ ต์ต๋๋ค.์ด ๋ถ๋ถ์ ๋ํด offline ๋ ผ์ํด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ด๋ จ ์ฌํญ์ ์ข ๋ ์์ธํ๊ฒ ์ ์ผ๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
END ์๋ต์ด ์๊ณ btree์ผ ๋ BKEY_MISMATCH, map, set์ผ ๋ ELEMENT_EXISTS๋ง ๋ฐ์ํ๋ค๋ฉด ๋ค์ Operation ๋ณด๋ด๋ ๊ฒ์๋ ๋์ํฉ๋๋ค.
PIPE_ERROR๊ฐ CLIENT_ERROR, SERVER_ERROR ๋ก ์ธํด ๋ฐ์ํ๋ค๋ฉด ์์ธ๊ฐ ๋ฐ์ํด failed result๋ฅผ ์กฐํํ ์ ์์ต๋๋ค. PIPE_ERROR๊ฐ command/memory overflow ๋ก ์ธํด ๋ฐ์ํ๋ค๋ฉด ์๋ฌ๋ฅผ ๋ฌด์ํ๊ณ ๋ชจ๋ ์๋ต์ ๊ธฐ์ค์ผ๋ก ์ ์ฒด ์ฑ๊ณต/์คํจ ์ฌ๋ถ๋ง ํ๋ณํฉ๋๋ค. ๋ฐ๋ผ์ "PIPE_ERROR" ๋ผ๋ ์๋ต์ด ์๋์ง future์์๋ ํ์ธํ ์ ์์ผ๋ฉฐ, failed result์ ๊ฒฐ๊ณผ๋ฅผ ๋ฃ์ ํ์๋ ์์ต๋๋ค.
arcus-java-client/src/main/java/net/spy/memcached/protocol/ascii/CollectionPipedInsertOperationImpl.java
Lines 139 to 148 in f60ed48
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviarla
๊ธฐ์กด pipe ์ฒ๋ฆฌ์๋ ์ผ๋ถ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๊ทธ๋ฌ๋ฉด, ๋ค์ ์ฐ์ฐ์์ ์๋ต์ ์ฝ์ ์์ PIPE_ERROR ์๋ต์ ๋ณด๊ฒ ๋๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค.
๋๋ต ํ์ธํ ์ฌํญ์ด๋ผ, ์ด ๋ถ๋ถ์ ๊ดํ ์ฝ๋๋ ์ง์ ํ์ธํด ๋ณด๊ธฐ ๋ฐ๋๋๋ค.
์ฆ, ์ฒ๋ฆฌํ์ง ๋ชปํ ์ฐ์ฐ์ด ์กด์ฌํ๋๋ผ๋ ์ฒ๋ฆฌ๊ฐ ์๋ฃ๋ ๊ฒ์ผ๋ก ํ๋จํ๊ณ ์์ต๋๋ค.
์ด๋ฌํ pipe ์ฒ๋ฆฌ ์ค๋ฅ๋ ๋ณธ PR๊ณผ๋ ๋ณ๋๋ก ์ฒ๋ฆฌํด์ผ ํ์ฃ ?
๊ฒํ ๋ฐ๋๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLIENT_ERROR, SERVER_ERROR ๋ฑ์ ์ค๋ฅ๊ฐ ์๋ ๊ฒฝ์ฐ, ๋ฐ๋ก OperationException์ด throw ๋ฉ๋๋ค.
์ด ์์ธ๋ฅผ MemcachedConnection์์ catchํ์ฌ ์ฐ๊ฒฐ์ ๋๊ธฐ ๋๋ฌธ์ ๋ค์ ์ฐ์ฐ์ด ์๋ต์ ์ฝ์ ์ ์์ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค.
arcus-java-client/src/main/java/net/spy/memcached/MemcachedConnection.java
Lines 948 to 952 in 45720de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PIPE_ERROR command/memory overflow ์ค๋ฅ ์, ์ฒ๋ฆฌ๋์ง ๋ชปํ ์ฐ์ฐ์ ๋ํด
๋ณธ PR ์ฒ๋ผ CANCELED CollectionOperationStatus ์ค์ ํ๋ ๊ฒ์ด ์ข๊ฒ ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์ฌํญ์ ๊ตฌํํ๊ธฐ ์ํด
์๋ ๋ก์ง์์
cb.receivedStatus()
ํธ์ถ ์์ ์ธ์ ๊ฐ์ด ์์ ๋์ด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค.์๋์ ๊ฐ์ด ํธ์ถํด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค.
๋ํ, ์๋ ๊ฒฝ์ฐ์ CENCEL ์ํ๋ฅผ ์ถ๊ฐํ๋ ๋ก์ง๋ ์์ ๋์ด์ผ ํฉ๋๋ค.
์์ ๊ฐ์ด ๋ณ๊ฒฝ๋๋ฉด,
complete() ๋ก์ง์์์ ๊ฒ์ฌ ์์๋ ๋ณ๊ฒฝ๋์ด์ผ ํฉ๋๋ค.
์๋ ์กฐ๊ฑด์ด ๊ฐ์ฅ ๋จผ์ ๊ฒ์ฌ๋์ด์ผ ํ ๊ฒ์ ๋๋ค.