@Test(expected = JedisConnectionException.class) public void initializeWithNotAvailableSentinelsShouldThrowException() { Set<String> wrongSentinels = new HashSet<String>(); wrongSentinels.add(new HostAndPort("localhost", 65432).toString()); wrongSentinels.add(new HostAndPort("localhost", 65431).toString()); JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, wrongSentinels); pool.destroy(); }
@Test(expected = JedisException.class) public void initializeWithNotMonitoredMasterNameShouldThrowException() { final String wrongMasterName = "wrongMasterName"; JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName, sentinels); pool.destroy(); }
@Test public void checkCloseableConnections() throws Exception { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2); Jedis jedis = pool.getResource(); jedis.auth("foobared"); jedis.set("foo", "bar"); assertEquals("bar", jedis.get("foo")); pool.returnResource(jedis); pool.close(); assertTrue(pool.isClosed()); }
@Test public void ensureSafeTwiceFailover() throws InterruptedException { JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, new GenericObjectPoolConfig(), 2000, "foobared", 2); forceFailover(pool); // after failover sentinel needs a bit of time to stabilize before a new // failover Thread.sleep(100); forceFailover(pool); // you can test failover as much as possible }
@Test public void returningBorrowedInstanceBeforeFailoverShouldNotAffectBorrowing() throws InterruptedException { final JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, new GenericObjectPoolConfig(), 2000, "foobared", 2); Jedis borrowed = pool.getResource(); forceFailover(pool); Thread.sleep(1000); // returns instance which was borrowed before failover borrowed.close(); final AtomicBoolean isBorrowed = new AtomicBoolean(false); Thread t = new Thread(new Runnable() { @Override public void run() { pool.getResource(); isBorrowed.set(true); } }); t.start(); // wait for 5 secs t.join(5000); assertTrue(isBorrowed.get()); }
private void waitForJedisSentinelPoolRecognizeNewMaster(JedisSentinelPool pool, HostAndPort newMaster) throws InterruptedException {
while (true) { HostAndPort currentHostMaster = pool.getCurrentHostMaster(); if (newMaster.equals(currentHostMaster)) break; System.out.println("JedisSentinelPool's master is not yet changed, sleep..."); Thread.sleep(100); } }
Elasitcsearch에가 이야기 하는 master node 의 역할 과 주의 사항이랄까요?
아래는 원문에 대한 Snippet 입니다.
One node in the cluster is elected to be the master node, which is in charge of managing cluster-wide changes like creating or deleting an index, or adding or removing a node from the cluster. The master node does not need to be involved in document-level changes or searches, which means that having just one master node will not become a bottleneck as traffic grows. Any node can become the master. Our example cluster has only one node, so it performs the master role.
[마스터 노드가 하는 일?]
인덱스 생성/삭제
노드 추가/제거
[마스터 노드에서 하면 안되는 일?]
문서 레벨의 변경 작업
검색
하면 안될 일은 트래픽 증가 시 병목 현상이 마스터 노드에서 발생 하면 안되기 때문 입니다.
The master node is the same as any other node in the cluster, except that it has been elected to be the master.
It is responsible for coordinating any cluster-wide changes, such as
as the addition or removal of a node, creation, deletion or change of
state (ie open/close) of an index, and the allocation of shards to
nodes. When any of these changes occur, the "cluster state" is updated
by the master and published to all other nodes in the cluster. It is the
only node that may publish a new cluster state.
The tasks that a master performs are lightweight. Any tasks that deal
with data (eg indexing, searching etc) do not need to involve the
master. If you choose to run the master as a non-data node (ie a node
that acts as master and as a router, but doesn't contain any data) then
the master can run happily on a smallish box.
A node is allowed to become a master if it is marked as "master
eligible" (which all nodes are by default). If the current master goes
down, a new master will be elected by the cluster.
An important configuration option in your cluster is minimum_master_nodes.
This specifies the number of "master eligible" nodes that a node must
be able to see in order to be part of a cluster. Its purpose is to
avoid "split brain" ie having the cluster separate into two clusters,
both of which think that they are functioning correctly.
For instance, if you have 3 nodes, all of which are master eligible, and set minimum_master_nodes
to 1, then if the third node is separated from the other two it, it
still sees one master-eligible node (itself) and thinks that it can form
a cluster by itself.
Instead, set minimum_master_nodes to 2 in this case
(number of nodes / 2 + 1), then if the third node separates, it won't
see enough master nodes, and thus won't form a cluster by itself. It
will keep trying to join the original cluster.
While Elasticsearch tries very hard to choose the correct defaults, minimum_master_nodes
is impossible to guess, as it has no way of knowing how many nodes you
intend to run. This is something you must configure yourself.