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: Moved cache list change logic from IO thread to CacheManger thread. #649

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/net/spy/memcached/CacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,17 @@ public void run() {
waitBeforeRetryMonitorCheck(1000L - elapsed);
oliviarla marked this conversation as resolved.
Show resolved Hide resolved
}
}
brido4125 marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Collaborator

Choose a reason for hiding this comment

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

@brido4125 @uhm0311

아래 코멘트가 hide된 곳에 들어가서, 다시 코멘트합니다.


wait() 중에 notifyAll()에 의해 깨어나더라도 다시 wait() 하는 코드가 있습니다.
동작의 의미는 유지하면서 wait()는 한 곳에만 수행되게 해 주세요.

즉, waitBeforeRetryMonitorCheck() 메소드를 2회 호출하지 않아야 합니다.

// Handling cacheList changes to a MemcachedConnection resulting
// from the processing of a CacheMonitor's Watch event.
for (ArcusClient ac : getAC()) {
uhm0311 marked this conversation as resolved.
Show resolved Hide resolved
try {
ac.getMemcachedConnection().handleCacheNodesChange();
} catch (IOException e) {
getLogger().error("Cache List update error in ArcusClient {}, exception = {}",
ac.getName(), e.getCause());
}
}
brido4125 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

@brido4125 @uhm0311

중요한 논의가 필요한 부분입니다.

기존엔 각 client의 io thread가 동시에 hash ring update 진행하였지만
현재는 cache manager thread 혼자서 모든 client의 hash ring update 진행합니다. 따라서, update가 반영되는 데 있어 지연이 생길 수 있습니다.

Cache Manager에 locator 하나만을 두고 이용하는 방안을 강구할 수 있나요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

이는 제가 예전에 리뷰했던 내용과 일치하며, 변경 사항이 아주 많아질 예정이기 때문에 별도의 PR로 반영한다는 대답을 들었습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

언급되었던 사항이군요.

현재 PR이 기존 동작보다 hashring update 지연을 발생시킬 수 있어,
Single hashring 유지하는 방안이 현재 PR 범위에 포함되어야 할 것 같습니다.

Single hahsring 유지 방안을 PoC로 진행해 보는 것이 좋겠습니다.

}
}
getLogger().info("Close cache manager.");
Expand Down Expand Up @@ -482,6 +493,10 @@ public void commandCacheListChange(List<String> children) {
MemcachedConnection conn = ac.getMemcachedConnection();
conn.setCacheNodesChange(addrs);
}

synchronized (this) {
notifyAll(); // awake CacheManager Thread.
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

closing() 메소드가 같은 일을 합니다.
wakeup() 으로 용어를 변경하고, wakeup() 호출합시다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

alter_list 변경 시에는 wakeup 시키지 않나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

alter_list 변경 시에는 wakeup 시키지 않나요?

processAlterListResult 콜백에 의해 commandAlterListChange가 호출되면
MemcachedConnection.setAlterNodesChange에 의해 wakeup 됩니다.

cacheList와 alterList의 변경을 감지하는 콜백 메서드가 별도로 구성됩니다.

alterList 변경 반영의 경우 주키퍼 클라이언트의 스레드에 의해 로직이 수행됩니다.

}

/* ENABLE_MIGRATION if */
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -142,7 +143,7 @@ public MemcachedConnection(String name, ConnectionFactory f,
timeoutRatioThreshold = f.getTimeoutRatioThreshold();
timeoutDurationThreshold = f.getTimeoutDurationThreshold();
selector = Selector.open();
List<MemcachedNode> connections = new ArrayList<MemcachedNode>(a.size());
List<MemcachedNode> connections = new CopyOnWriteArrayList<MemcachedNode>();
for (SocketAddress sa : a) {
connections.add(makeMemcachedNode(connName, sa));
}
Expand Down Expand Up @@ -304,9 +305,6 @@ public void handleIO() throws IOException {
}
/* ENABLE_REPLICATION end */

// Deal with the memcached server group that's been added by CacheManager.
handleCacheNodesChange();

if (!reconnectQueue.isEmpty()) {
attemptReconnects();
}
Expand Down
Loading