Skip to content

Commit

Permalink
PullRequest: 105 hotfix/optimize-meta-server
Browse files Browse the repository at this point in the history
Signed-off-by: 源三 <[email protected]>


* [opt]not explose raft/local logic

* [unit test]not running AllTests when auto-maven-build
  • Loading branch information
忘禅 authored and 源三 committed Dec 21, 2020
1 parent f20a551 commit a2aaf1d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,12 @@ protected void doStop() throws StopException {

@Override
public long getEpoch() {
if (isRaftLeader()) {
return getLocalLeaseManager().getEpoch();
}
return getRaftLeaseManager().getEpoch();
return getLeaseManager().getEpoch();
}

@Override
public List<T> getClusterMembers() {
if (isRaftLeader()) {
return getLocalLeaseManager().getClusterMembers();
}
return getRaftLeaseManager().getClusterMembers();
return getLeaseManager().getClusterMembers();
}

@Override
Expand All @@ -124,30 +118,15 @@ public boolean cancel(T renewal) {
@Override
public boolean renew(T renewal, int leaseDuration) {
int validLeaseDuration = leaseDuration > 0 ? leaseDuration : Lease.DEFAULT_DURATION_SECS;
Lease<T> lease = null;
if (!isRaftLeader()) {
lease = getRaftLeaseManager().getLease(renewal);
} else {
lock.readLock().lock();
try {
lease = getLocalLeaseManager().getLease(renewal);
} finally {
lock.readLock().unlock();
}
}

Lease<T> lease = getLeaseManager().getLease(renewal);
/*
* no exist lease, try register the node to all meta-servers through raft
* */
if (lease == null) {
getRaftLeaseManager().register(new Lease<>(renewal, validLeaseDuration));
notifyObservers(new NodeAdded<>(renewal));
} else {
if (isRaftLeader()) {
getLocalLeaseManager().renew(renewal, leaseDuration);
} else {
getRaftLeaseManager().renew(renewal, leaseDuration);
}
getLeaseManager().renew(renewal, leaseDuration);
}
return true;
}
Expand Down Expand Up @@ -209,6 +188,14 @@ public void refreshEpoch(long newEpoch) {
getLocalLeaseManager().refreshEpoch(newEpoch);
}

protected LeaseManager<T> getLeaseManager() {
if(isRaftLeader()) {
return getLocalLeaseManager();
} else {
return getRaftLeaseManager();
}
}

protected boolean isRaftLeader() {
return ServiceStateMachine.getInstance().isLeader();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,24 @@ public void updateClusterMembers(List<MetaNode> newMembers, long epoch) {

@Override
public SlotTable getSlotTable() {
if (ServiceStateMachine.getInstance().isLeader()) {
return localMetaServer.getSlotTable();
}
return raftMetaServer.getSlotTable();
return getMetaServer().getSlotTable();
}

@Override
public List<MetaNode> getClusterMembers() {
if (ServiceStateMachine.getInstance().isLeader()) {
return localMetaServer.getClusterMembers();
}
return raftMetaServer.getClusterMembers();
return getMetaServer().getClusterMembers();
}

@ReadOnLeader
public long getEpoch() {
return getMetaServer().getEpoch();
}

private CurrentDcMetaServer getMetaServer() {
if (ServiceStateMachine.getInstance().isLeader()) {
return localMetaServer.getEpoch();
return localMetaServer;
}
return raftMetaServer.getEpoch();
return raftMetaServer;
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,22 @@ public class DefaultSlotManager extends AbstractLifecycle implements SlotManager

private ScheduledFuture<?> future;

/**
* Post construct.
*
* @throws Exception the exception
*/
@PostConstruct
public void postConstruct() throws Exception {
LifecycleHelper.initializeIfPossible(this);
LifecycleHelper.startIfPossible(this);
}

/**
* Pre destroy.
*
* @throws Exception the exception
*/
@PreDestroy
public void preDestroy() throws Exception {
LifecycleHelper.stopIfPossible(this);
Expand Down Expand Up @@ -140,45 +150,65 @@ protected void doDispose() throws DisposeException {
super.doDispose();
}

/**
* Refresh.
*
* @param slotTable the slot table
*/
@Override
public void refresh(SlotTable slotTable) {
raftSlotManager.refresh(slotTable);
}

/**
* Gets get raft slot manager.
*
* @return the get raft slot manager
*/
public SlotManager getRaftSlotManager() {
return raftSlotManager;
}

/**
* Gets get slot nums.
*
* @return the get slot nums
*/
@Override
public int getSlotNums() {
if (isRaftLeader()) {
return localSlotManager.getSlotNums();
}
return raftSlotManager.getSlotNums();
return getSlotManager().getSlotNums();
}

/**
* Gets get slot replica nums.
*
* @return the get slot replica nums
*/
@Override
public int getSlotReplicaNums() {
if (isRaftLeader()) {
return localSlotManager.getSlotReplicaNums();
}
return raftSlotManager.getSlotReplicaNums();
return getSlotManager().getSlotReplicaNums();
}

/**
* Gets get data node managed slot.
*
* @param dataNode the data node
* @param ignoreFollowers the ignore followers
* @return the get data node managed slot
*/
@Override
public DataNodeSlot getDataNodeManagedSlot(DataNode dataNode, boolean ignoreFollowers) {
if (isRaftLeader()) {
return localSlotManager.getDataNodeManagedSlot(dataNode, ignoreFollowers);
}
return raftSlotManager.getDataNodeManagedSlot(dataNode, ignoreFollowers);
return getSlotManager().getDataNodeManagedSlot(dataNode, ignoreFollowers);
}

/**
* Gets get slot table.
*
* @return the get slot table
*/
@Override
public SlotTable getSlotTable() {
if (isRaftLeader()) {
return localSlotManager.getSlotTable();
}
return raftSlotManager.getSlotTable();
return getSlotManager().getSlotTable();
}

@VisibleForTesting
Expand All @@ -195,6 +225,11 @@ protected void initCheck() {
}

public enum SlotPeriodCheckType {
/**
* check slot assignment balance
*
* The goal is to balance slot numbers between data-servers
* */
CHECK_SLOT_ASSIGNMENT_BALANCE {
@Override
SlotPeriodCheckType next() {
Expand All @@ -211,6 +246,12 @@ SlotPeriodCheckType action(ArrangeTaskExecutor arrangeTaskExecutor,
return this;
}
},

/**
* check slot leader balance
*
* The goal is to balance slot leaders between data-servers
* */
CHECK_SLOT_LEADER_BALANCE {
@Override
SlotPeriodCheckType next() {
Expand All @@ -236,6 +277,14 @@ abstract SlotPeriodCheckType action(ArrangeTaskExecutor arrangeTaskExecutor,
DefaultDataServerManager dataServerManager);
}

private SlotManager getSlotManager() {
if(isRaftLeader()) {
return localSlotManager;
} else {
return raftSlotManager;
}
}

protected boolean isRaftLeader() {
return ServiceStateMachine.getInstance().isLeader();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@
import org.junit.runners.Suite;

@RunWith(Suite.class)
@Suite.SuiteClasses({ CRC16SlotFunctionTest.class, DefaultCrossDcMetaServerTest.class,
CrossDcSlotAllocatorTest.class, DefaultCurrentDcMetaServerTest.class,
DefaultSessionServerManagerTest.class, DefaultDataServerManagerTest.class,
DefaultLeaseManagerTest.class, CrossDcMetaServerManagerTest.class,
TestAbstractRaftEnabledLeaseManager.class, LeaseTest.class,
DefaultMetaServerManagerTest.class, ArrangeTaskExecutorTest.class,
DataServerProvideDataNotifierTest.class, DefaultLocalMetaServerTest.class,
DataLeaseManagerTest.class, SessionLeaseManagerTest.class,
SessionServerProvideDataNotifierTest.class,
DefaultProvideDataNotifierTest.class, LocalSlotManagerTest.class,
NodeModifiedTest.class, DefaultSlotManagerTest.class,
DataServerArrangeTaskDispatcherTest.class, DefaultSlotArrangerTest.class,
ServerDeadRebalanceWorkTest.class, InitReshardingTaskTest.class,
SlotLeaderRebalanceTaskTest.class, SlotReassignTaskTest.class })
@Suite.SuiteClasses({ CRC16SlotFunctionTest.class,
// DefaultCrossDcMetaServerTest.class,
// CrossDcSlotAllocatorTest.class, DefaultCurrentDcMetaServerTest.class,
// DefaultSessionServerManagerTest.class, DefaultDataServerManagerTest.class,
// DefaultLeaseManagerTest.class, CrossDcMetaServerManagerTest.class,
// TestAbstractRaftEnabledLeaseManager.class, LeaseTest.class,
// DefaultMetaServerManagerTest.class, ArrangeTaskExecutorTest.class,
// DataServerProvideDataNotifierTest.class, DefaultLocalMetaServerTest.class,
// DataLeaseManagerTest.class, SessionLeaseManagerTest.class,
// SessionServerProvideDataNotifierTest.class,
// DefaultProvideDataNotifierTest.class, LocalSlotManagerTest.class,
// NodeModifiedTest.class, DefaultSlotManagerTest.class,
// DataServerArrangeTaskDispatcherTest.class, DefaultSlotArrangerTest.class,
// ServerDeadRebalanceWorkTest.class, InitReshardingTaskTest.class,
// SlotLeaderRebalanceTaskTest.class, SlotReassignTaskTest.class
})
public class AllTests {
}

0 comments on commit a2aaf1d

Please sign in to comment.