This is an automated email from the ASF dual-hosted git repository. xxyu pushed a commit to branch kylin5 in repository https://gitbox.apache.org/repos/asf/kylin.git
commit 531a25f207e105dd023e476f1ee447ce48d6491f Author: Junqing Cai <[email protected]> AuthorDate: Thu Jan 5 10:15:06 2023 +0800 [DIRTY] fix upgrade in resource group --- .../apache/kylin/metadata/epoch/EpochManager.java | 3 +- .../kylin/metadata/epoch/EpochManagerTest.java | 87 ++++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src/core-metadata/src/main/java/org/apache/kylin/metadata/epoch/EpochManager.java b/src/core-metadata/src/main/java/org/apache/kylin/metadata/epoch/EpochManager.java index 6337b8505b..a68d25eeec 100644 --- a/src/core-metadata/src/main/java/org/apache/kylin/metadata/epoch/EpochManager.java +++ b/src/core-metadata/src/main/java/org/apache/kylin/metadata/epoch/EpochManager.java @@ -716,9 +716,8 @@ public class EpochManager { return false; } - ResourceGroupManager rgManager = ResourceGroupManager.getInstance(config); String epochServer = getHostAndPort(epoch.getCurrentEpochOwner()); - if (!rgManager.instanceHasPermissionToOwnEpochTarget(epoch.getEpochTarget(), epochServer)) { + if (!currentInstanceHasPermissionToOwn(epoch.getEpochTarget(), epochServer)) { logger.debug("Epoch {}'s owner is not in build request type resource group.", epoch); return false; } diff --git a/src/core-metadata/src/test/java/org/apache/kylin/metadata/epoch/EpochManagerTest.java b/src/core-metadata/src/test/java/org/apache/kylin/metadata/epoch/EpochManagerTest.java index 6891ed7253..fb0856c4cc 100644 --- a/src/core-metadata/src/test/java/org/apache/kylin/metadata/epoch/EpochManagerTest.java +++ b/src/core-metadata/src/test/java/org/apache/kylin/metadata/epoch/EpochManagerTest.java @@ -490,4 +490,91 @@ class EpochManagerTest { Assertions.assertFalse(epochManager.getOwnedEpochs().isEmpty()); } + @Test + void testIsEpochLegal() { + EpochManager epochManager = EpochManager.getInstance(); + { + Epoch epoch = null; + Boolean isEpochLegal = ReflectionTestUtils.invokeMethod(epochManager, "isEpochLegal", epoch); + Assertions.assertNotNull(isEpochLegal); + Assertions.assertFalse(isEpochLegal); + } + + { + Epoch epoch = new Epoch(); + epoch.setEpochTarget("test1"); + epoch.setCurrentEpochOwner(null); + epoch.setEpochId(1); + epoch.setLastEpochRenewTime(System.currentTimeMillis()); + Boolean isEpochLegal = ReflectionTestUtils.invokeMethod(epochManager, "isEpochLegal", epoch); + Assertions.assertNotNull(isEpochLegal); + Assertions.assertFalse(isEpochLegal); + } + + { + Epoch epoch = new Epoch(); + epoch.setEpochTarget("test1"); + epoch.setCurrentEpochOwner("abc"); + epoch.setEpochId(1); + epoch.setLastEpochRenewTime(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)); + Boolean isEpochLegal = ReflectionTestUtils.invokeMethod(epochManager, "isEpochLegal", epoch); + Assertions.assertNotNull(isEpochLegal); + Assertions.assertFalse(isEpochLegal); + } + + { + Epoch epoch = new Epoch(); + epoch.setEpochTarget("test1"); + epoch.setCurrentEpochOwner("abc"); + epoch.setEpochId(1); + epoch.setLastEpochRenewTime(System.currentTimeMillis()); + Boolean isEpochLegal = ReflectionTestUtils.invokeMethod(epochManager, "isEpochLegal", epoch); + Assertions.assertNotNull(isEpochLegal); + Assertions.assertTrue(isEpochLegal); + } + } + + @Test + @MetadataInfo + void testIsEpochLegal_WithResourceGroup() { + val manager = ResourceGroupManager.getInstance(getTestConfig()); + manager.getResourceGroup(); + manager.updateResourceGroup(copyForWrite -> copyForWrite.setResourceGroupEnabled(true)); + val epochManager = EpochManager.getInstance(); + Epoch epoch = new Epoch(); + epoch.setEpochTarget("test1"); + epoch.setCurrentEpochOwner("abc"); + epoch.setEpochId(1); + epoch.setLastEpochRenewTime(System.currentTimeMillis()); + Boolean isEpochLegal = ReflectionTestUtils.invokeMethod(epochManager, "isEpochLegal", epoch); + Assertions.assertNotNull(isEpochLegal); + Assertions.assertFalse(isEpochLegal); + } + + @Test + @MetadataInfo + void testIsEpochLegal_WithResourceGroupInMaintMode() { + val manager = ResourceGroupManager.getInstance(getTestConfig()); + manager.getResourceGroup(); + manager.updateResourceGroup(copyForWrite -> copyForWrite.setResourceGroupEnabled(true)); + + val epochManager = EpochManager.getInstance(); + + Epoch epoch = new Epoch(); + epoch.setEpochTarget(UnitOfWork.GLOBAL_UNIT); + epoch.setCurrentEpochOwner("testOwner"); + epoch.setEpochId(1); + epoch.setLastEpochRenewTime(System.currentTimeMillis()); + getEpochStore().insertBatch(Lists.newArrayList(epoch)); + + epochManager.setMaintenanceMode("test"); + + //test another target + epoch.setEpochTarget("test"); + + Boolean isEpochLegal = ReflectionTestUtils.invokeMethod(epochManager, "isEpochLegal", epoch); + Assertions.assertNotNull(isEpochLegal); + Assertions.assertTrue(isEpochLegal); + } + }
