@@ -379,6 +379,11 @@ public long getWALPosition(ServerName serverName, String queueId, String fileNam
379
379
return 0 ;
380
380
}
381
381
382
+ /**
383
+ * This implement must update the cversion of root {@link #queuesZNode}. The optimistic lock of
384
+ * the {@link #getAllWALs()} method is based on the cversion of root {@link #queuesZNode}.
385
+ * @see #getAllWALs() to show the usage of the cversion of root {@link #queuesZNode} .
386
+ */
382
387
@ Override
383
388
public Pair <String , SortedSet <String >> claimQueue (ServerName sourceServerName , String queueId ,
384
389
ServerName destServerName ) throws ReplicationException {
@@ -417,6 +422,12 @@ public Pair<String, SortedSet<String>> claimQueue(ServerName sourceServerName, S
417
422
}
418
423
// add delete op for peer
419
424
listOfOps .add (ZKUtilOp .deleteNodeFailSilent (oldQueueNode ));
425
+ // Append new queue id for prevent lock competition in zookeeper server.
426
+ String claimLockZNode = ZNodePaths .joinZNode (queuesZNode , "cversion_" + newQueueId );
427
+ // A trick for update the cversion of root queuesZNode .
428
+ // The optimistic lock of the getAllWALs() method is based on the cversion of root queuesZNode
429
+ listOfOps .add (ZKUtilOp .createAndFailSilent (claimLockZNode , HConstants .EMPTY_BYTE_ARRAY ));
430
+ listOfOps .add (ZKUtilOp .deleteNodeFailSilent (claimLockZNode ));
420
431
421
432
LOG .trace ("The multi list size is {}" , listOfOps .size ());
422
433
ZKUtil .multiOrSequential (zookeeper , listOfOps , false );
@@ -505,6 +516,13 @@ protected int getQueuesZNodeCversion() throws KeeperException {
505
516
return stat .getCversion ();
506
517
}
507
518
519
+ /**
520
+ * The optimistic lock of this implement is based on the cversion of root {@link #queuesZNode}.
521
+ * Therefore, we must update the cversion of root {@link #queuesZNode} when migrate wal nodes to
522
+ * other queues.
523
+ * @see #claimQueue(ServerName, String, ServerName) as an example of updating root
524
+ * {@link #queuesZNode} cversion.
525
+ */
508
526
@ Override
509
527
public Set <String > getAllWALs () throws ReplicationException {
510
528
try {
0 commit comments