32
32
import java .nio .channels .SocketChannel ;
33
33
import java .util .ArrayList ;
34
34
import java .util .Collection ;
35
- import java .util .Collections ;
36
35
import java .util .HashMap ;
37
36
import java .util .HashSet ;
38
37
import java .util .Iterator ;
@@ -367,38 +366,6 @@ private void updateConnections(List<InetSocketAddress> addrs) throws IOException
367
366
}
368
367
369
368
/* ENABLE_REPLICATION if */
370
- private Set <String > findChangedGroups (List <InetSocketAddress > addrs ,
371
- Collection <MemcachedNode > nodes ) {
372
- Map <String , InetSocketAddress > addrMap = new HashMap <>();
373
- for (InetSocketAddress each : addrs ) {
374
- addrMap .put (each .toString (), each );
375
- }
376
-
377
- Set <String > changedGroupSet = new HashSet <>();
378
- for (MemcachedNode node : nodes ) {
379
- String nodeAddr = ((InetSocketAddress ) node .getSocketAddress ()).toString ();
380
- if (addrMap .remove (nodeAddr ) == null ) { // removed node
381
- changedGroupSet .add (node .getReplicaGroup ().getGroupName ());
382
- }
383
- }
384
- for (String addr : addrMap .keySet ()) { // newly added node
385
- ArcusReplNodeAddress a = (ArcusReplNodeAddress ) addrMap .get (addr );
386
- changedGroupSet .add (a .getGroupName ());
387
- }
388
- return changedGroupSet ;
389
- }
390
-
391
- private List <InetSocketAddress > findAddrsOfChangedGroups (List <InetSocketAddress > addrs ,
392
- Set <String > changedGroups ) {
393
- List <InetSocketAddress > changedGroupAddrs = new ArrayList <>();
394
- for (InetSocketAddress addr : addrs ) {
395
- if (changedGroups .contains (((ArcusReplNodeAddress ) addr ).getGroupName ())) {
396
- changedGroupAddrs .add (addr );
397
- }
398
- }
399
- return changedGroupAddrs ;
400
- }
401
-
402
369
private void updateReplConnections (List <InetSocketAddress > addrs ) throws IOException {
403
370
List <MemcachedNode > attachNodes = new ArrayList <>();
404
371
List <MemcachedNode > removeNodes = new ArrayList <>();
@@ -416,10 +383,11 @@ private void updateReplConnections(List<InetSocketAddress> addrs) throws IOExcep
416
383
* we find out the changed groups with the comparison of previous and current znode list,
417
384
* and update the state of groups based on them.
418
385
*/
419
- Set <String > changedGroups = findChangedGroups (addrs , locator .getAll ());
386
+ Set <String > changedGroups = MemcachedReplicaGroup . findChangedGroups (addrs , locator .getAll ());
420
387
421
388
Map <String , List <ArcusReplNodeAddress >> newAllGroups =
422
- ArcusReplNodeAddress .makeGroupAddrsList (findAddrsOfChangedGroups (addrs , changedGroups ));
389
+ ArcusReplNodeAddress .makeGroupAddrsList (
390
+ MemcachedReplicaGroup .findAddrsOfChangedGroups (addrs , changedGroups ));
423
391
424
392
// remove invalidated groups in changedGroups
425
393
for (Map .Entry <String , List <ArcusReplNodeAddress >> entry : newAllGroups .entrySet ()) {
@@ -467,8 +435,10 @@ private void updateReplConnections(List<InetSocketAddress> addrs) throws IOExcep
467
435
assert oldMasterAddr != null : "invalid old rgroup" ;
468
436
assert newMasterAddr != null : "invalid new rgroup" ;
469
437
470
- Set <ArcusReplNodeAddress > oldSlaveAddrs = getAddrsFromNodes (oldSlaveNodes );
471
- Set <ArcusReplNodeAddress > newSlaveAddrs = getSlaveAddrsFromGroupAddrs (newGroupAddrs );
438
+ Set <ArcusReplNodeAddress > oldSlaveAddrs
439
+ = MemcachedReplicaGroup .getAddrsFromNodes (oldSlaveNodes );
440
+ Set <ArcusReplNodeAddress > newSlaveAddrs
441
+ = MemcachedReplicaGroup .getSlaveAddrsFromGroupAddrs (newGroupAddrs );
472
442
473
443
if (oldMasterAddr .isSameAddress (newMasterAddr )) {
474
444
// add newly added slave node
@@ -560,30 +530,6 @@ private void updateReplConnections(List<InetSocketAddress> addrs) throws IOExcep
560
530
// Remove the unavailable nodes.
561
531
handleNodesToRemove (removeNodes );
562
532
}
563
-
564
- private Set <ArcusReplNodeAddress > getAddrsFromNodes (List <MemcachedNode > nodes ) {
565
- Set <ArcusReplNodeAddress > addrs = Collections .emptySet ();
566
- if (!nodes .isEmpty ()) {
567
- addrs = new HashSet <>((int ) (nodes .size () / .75f ) + 1 );
568
- for (MemcachedNode node : nodes ) {
569
- addrs .add ((ArcusReplNodeAddress ) node .getSocketAddress ());
570
- }
571
- }
572
- return addrs ;
573
- }
574
-
575
- private Set <ArcusReplNodeAddress > getSlaveAddrsFromGroupAddrs (
576
- List <ArcusReplNodeAddress > groupAddrs ) {
577
- Set <ArcusReplNodeAddress > slaveAddrs = Collections .emptySet ();
578
- int groupSize = groupAddrs .size ();
579
- if (groupSize > 1 ) {
580
- slaveAddrs = new HashSet <>((int ) ((groupSize - 1 ) / .75f ) + 1 );
581
- for (int i = 1 ; i < groupSize ; i ++) {
582
- slaveAddrs .add (groupAddrs .get (i ));
583
- }
584
- }
585
- return slaveAddrs ;
586
- }
587
533
/* ENABLE_REPLICATION end */
588
534
589
535
/* ENABLE_REPLICATION if */
0 commit comments