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: Change CacheManager class to interface named ServerManager. #781

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
4 changes: 2 additions & 2 deletions docs/user_guide/02-arcus-java-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ ArcusClientPool pool = ArcusClient.createArcusClientPool(ARCUS_ADMIN, SERVICE_CO
ARCUS client 객체를 정상적으로 생성하면, 아래의 로그와 같이 cache cloud와 정상 연결됨을 볼 수 있다.

```
WARN net.spy.memcached.CacheManager: All arcus connections are established.
WARN net.spy.memcached.ElasticCacheManager: All arcus connections are established.
```

ARCUS cache cloud로 정상 연결되지 않으면, 다음과 같은 로그가 보인다.
예를 들어 5대의 Cache server에 접속을 해야 하는데 이들 중 일부 서버에 접속하지 못했다면 아래 로그가 남게 된다.
접속 실패한 cache server에 대해서는 ARCUS client가 1초에 한 번씩 자동으로 재연결을 시도한다.

```
WARN net.spy.memcached.CacheManager: Some arcus connections are not established.
WARN net.spy.memcached.ElasticCacheManager: Some arcus connections are not established.
```

### ARCUS Client 소멸
Expand Down
12 changes: 6 additions & 6 deletions docs/user_guide/10-log-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Java client에서 남기는 로그들과 그것들이 의미하는 바는 아래
ARCUS client가 정상적으로 초기화 되면 다음과 같은 로그를 남긴다.

```java
INFO net.spy.memcached.CacheManager: CacheManager started. ([mailto:[email protected]:17288 [email protected]:17288])
INFO net.spy.memcached.ElasticCacheManager: CacheManager started. ([mailto:[email protected]:17288 [email protected]:17288])

WARN net.spy.memcached.CacheMonitor: Cache list has been changed : From=null, To=[127.0.0.1:11211-hostname, xxx.xxx.xxx.xxx:xxxx-hostname] : [serviceCode=dev]

Expand All @@ -20,17 +20,17 @@ INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio

INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@2e5bbd6

2011-09-21 10:44:54.055 WARN net.spy.memcached.CacheManager: All arcus connections are established.
2011-09-21 10:44:54.055 WARN net.spy.memcached.ElasticCacheManager: All arcus connections are established.
```

#### ARCUS admin address가 잘못 되었을 때

ARCUS admin address를 잘못 지정했거나 server가 응답이 없을 때 아래와 같은 로그를 남긴다.

```java
FATAL net.spy.memcached.CacheManager: Unexpected exception. contact to arcus administrator
FATAL net.spy.memcached.ElasticCacheManager: Unexpected exception. contact to arcus administrator

INFO net.spy.memcached.CacheManager: Close ZooKeeper client.
INFO net.spy.memcached.ElasticCacheManager: Close ZooKeeper client.
```

#### ARCUS admin과 연결이 단절 되었을 때
Expand All @@ -54,9 +54,9 @@ WARN net.spy.memcached.CacheMonitor: Session expired. Trying to reconnect to the
```java
INFO net.spy.memcached.CacheMonitor: Shutting down the CacheMonitor : [serviceCode=dev]

WARN net.spy.memcached.CacheManager: Unexpected disconnection from Arcus admin. Trying to reconnect to Arcus admin.
WARN net.spy.memcached.ElasticCacheManager: Unexpected disconnection from Arcus admin. Trying to reconnect to Arcus admin.

INFO net.spy.memcached.CacheManager: Close ZooKeeper client.
INFO net.spy.memcached.ElasticCacheManager: Close ZooKeeper client.
```

Reconnect에 성공하면 아래와 같은 로그가 남는다.
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/net/spy/memcached/ArcusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ public class ArcusClient extends FrontCacheMemcachedClient implements ArcusClien

private static final int MAX_DNS_CACHE_TTL = 300;

private CacheManager cacheManager;
private ServerManager serverManager;

public void setCacheManager(CacheManager cacheManager) {
this.cacheManager = cacheManager;
public void setServerManager(ServerManager serverManager) {
this.serverManager = serverManager;
}

/**
Expand Down Expand Up @@ -314,8 +314,8 @@ private static ArcusClientPool createArcusClient(String hostPorts, String servic
throw new IllegalArgumentException("Service code is empty.");
}

CacheManager exe = new CacheManager(hostPorts, serviceCode, cfb, poolSize, waitTimeForConnect);
return new ArcusClientPool(poolSize, exe.getAC());
ServerManager manager = new ElasticCacheManager(hostPorts, serviceCode, cfb, poolSize, waitTimeForConnect);
return new ArcusClientPool(poolSize, manager.getClients());
}

/**
Expand Down Expand Up @@ -426,8 +426,8 @@ private void registerMbean(String name) {
public boolean shutdown(long timeout, TimeUnit unit) {
final boolean result = super.shutdown(timeout, unit);
// Connect to Arcus server directly, cache manager may be null.
if (cacheManager != null) {
cacheManager.shutdown();
if (serverManager != null) {
serverManager.shutdown();
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
* memcached server in the remote machine. It also changes the
* previous ketama node
*/
public class CacheManager extends SpyThread implements Watcher,
public class ElasticCacheManager extends SpyThread implements Watcher, ServerManager,
CacheMonitor.CacheMonitorListener, MigrationMonitor.MigrationMonitorListener {

private static final String ARCUS_BASE_CACHE_LIST_ZPATH = "/arcus/cache_list/";

private static final String ARCUS_BASE_CLIENT_LIST_ZPATH = "/arcus/client_list/";
Expand Down Expand Up @@ -112,8 +113,8 @@ public class CacheManager extends SpyThread implements Watcher,
private boolean readingCacheList = false;
/* ENABLE_MIGRATION end */

public CacheManager(String hostPort, String serviceCode,
ConnectionFactoryBuilder cfb, int poolSize, int waitTimeForConnect) {
public ElasticCacheManager(String hostPort, String serviceCode,
ConnectionFactoryBuilder cfb, int poolSize, int waitTimeForConnect) {
if (cfb.getFailureMode() == FailureMode.Redistribute) {
throw new InitializeClientException(
"Redistribute failure mode is not compatible with ArcusClient. " +
Expand Down Expand Up @@ -146,7 +147,7 @@ public CacheManager(String hostPort, String serviceCode,
setDaemon(true);
start();

getLogger().info("CacheManager started. (" + serviceCode + "@" + hostPort + ")");
getLogger().info("ElasticCacheManager started. (" + serviceCode + "@" + hostPort + ")");

}

Expand Down Expand Up @@ -663,7 +664,7 @@ public void connectionEstablished(SocketAddress sa, int reconnectCount) {
};
cfb.setInitialObservers(Collections.singleton(observer));

int poolId = CacheManager.POOL_ID.getAndIncrement();
int poolId = ElasticCacheManager.POOL_ID.getAndIncrement();
client = new ArcusClient[poolSize];
int i = 0;
try {
Expand All @@ -672,7 +673,7 @@ public void connectionEstablished(SocketAddress sa, int reconnectCount) {
"(" + (i + 1) + "-" + poolSize + ") for " + serviceCode;
client[i] = ArcusClient.getInstance(cfb.build(), clientName, socketList);
client[i].setName("Memcached IO for " + serviceCode);
client[i].setCacheManager(this);
client[i].setServerManager(this);
}
} catch (IOException e) {
getLogger().fatal("Arcus Connection has critical problems. contact arcus manager.", e);
Expand Down Expand Up @@ -724,7 +725,7 @@ private List<InetSocketAddress> getSocketAddressList(String addrs) {
*
* @return current ArcusClient
*/
public ArcusClient[] getAC() {
public ArcusClient[] getClients() {
return client;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void handleIO() throws IOException {
}
/* ENABLE_REPLICATION end */

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

if (!reconnectQueue.isEmpty()) {
Expand Down Expand Up @@ -680,7 +680,7 @@ public void complete() {
addOperation(node, op);
}

// Handle the memcached server group that's been added by CacheManager.
// Handle the memcached server group that's been added by ServerManager.
void handleCacheNodesChange() throws IOException {
/* ENABLE_MIGRATION if */
/*
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/spy/memcached/ServerManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.spy.memcached;

public interface ServerManager {
ArcusClient[] getClients();

void shutdown();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testCreateClientPool() throws NoSuchFieldException, IllegalAccessExc
}

private int getPoolId() throws NoSuchFieldException, IllegalAccessException {
Class<CacheManager> clazz = CacheManager.class;
Class<ElasticCacheManager> clazz = ElasticCacheManager.class;
Field poolId = clazz.getDeclaredField("POOL_ID");
poolId.setAccessible(true);
AtomicInteger atomicInteger = (AtomicInteger) poolId.get(null);
Expand Down