private static void rebalanceSwitch(Dataset source, Dataset target, MetadataProvider metadataProvider) throws AlgebricksException, RemoteException { MetadataTransactionContext mdTxnCtx = metadataProvider.getMetadataTxnContext(); // upgrade lock ICcApplicationContext appCtx = metadataProvider.getApplicationContext(); ActiveNotificationHandler activeNotificationHandler = (ActiveNotificationHandler) appCtx.getActiveNotificationHandler(); IMetadataLockManager lockManager = appCtx.getMetadataLockManager(); lockManager.upgradeDatasetLockToWrite(metadataProvider.getLocks(), DatasetUtil.getFullyQualifiedName(source)); LOGGER.info("Updating dataset {} node group from {} to {}", source.getDatasetName(), source.getNodeGroupName(), target.getNodeGroupName()); try { // Updates the dataset entry in the metadata storage MetadataManager.INSTANCE.updateDataset(mdTxnCtx, target); for (IActiveEntityEventsListener listener : activeNotificationHandler.getEventListeners()) { if (listener instanceof IActiveEntityController) { IActiveEntityController controller = (IActiveEntityController) listener; controller.replace(target); } } MetadataManager.INSTANCE.commitTransaction(mdTxnCtx); LOGGER.info("dataset {} node group updated to {}", target.getDatasetName(), target.getNodeGroupName()); } finally { lockManager.downgradeDatasetLockToExclusiveModify(metadataProvider.getLocks(), DatasetUtil.getFullyQualifiedName(target)); } }