mikewalch commented on a change in pull request #953: fixes #917 Added read
locks
URL: https://github.com/apache/fluo/pull/953#discussion_r146957600
##########
File path:
modules/core/src/main/java/org/apache/fluo/core/impl/LockResolver.java
##########
@@ -52,38 +61,61 @@
public class LockResolver {
- private static Map<PrimaryRowColumn, List<Entry<Key, Value>>>
groupLocksByPrimary(
- List<Entry<Key, Value>> locks) {
- Map<PrimaryRowColumn, List<Entry<Key, Value>>> groupedLocks = new
HashMap<>();
+ private static Map<PrimaryRowColumn, List<LockInfo>>
groupLocksByPrimary(List<LockInfo> locks) {
+ Map<PrimaryRowColumn, List<LockInfo>> groupedLocks = new HashMap<>();
Map<PrimaryRowColumn, Long> transactorIds = new HashMap<>();
- for (Entry<Key, Value> lock : locks) {
- LockValue lockVal = new LockValue(lock.getValue().get());
- PrimaryRowColumn prc =
- new PrimaryRowColumn(lockVal.getPrimaryRow(),
lockVal.getPrimaryColumn(),
- lock.getKey().getTimestamp() & ColumnConstants.TIMESTAMP_MASK);
+ for (LockInfo lockInfo : locks) {
- List<Entry<Key, Value>> lockList = groupedLocks.get(prc);
- if (lockList == null) {
- lockList = new ArrayList<>();
- groupedLocks.put(prc, lockList);
- }
+ PrimaryRowColumn prc = new PrimaryRowColumn(lockInfo.prow,
lockInfo.pcol, lockInfo.lockTs);
+
+ List<LockInfo> lockList = groupedLocks.computeIfAbsent(prc, k -> new
ArrayList<>());
Long trid = transactorIds.get(prc);
if (trid == null) {
- transactorIds.put(prc, lockVal.getTransactor());
- } else if (!trid.equals(lockVal.getTransactor())) {
+ transactorIds.put(prc, lockInfo.transactorId);
+ } else if (!trid.equals(lockInfo.transactorId)) {
// sanity check.. its assumed that all locks w/ the same
PrimaryRowColumn should have the
// same transactor id as well
- throw new IllegalStateException("transactor ids not equals " + prc + "
" + lock.getKey()
- + " " + trid + " " + lockVal.getTransactor());
+ throw new IllegalStateException("transactor ids not equals " + prc + "
"
+ + lockInfo.entry.getKey() + " " + trid + " " +
lockInfo.transactorId);
}
- lockList.add(lock);
+ lockList.add(lockInfo);
}
return groupedLocks;
+ }
+
+ private static class LockInfo {
Review comment:
This is nice. Makes the code more readable.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services