private boolean isLargeCluster(ExternalView externalView) { // Check if the number of replicas is sufficient to treat it as a large cluster final String helixReplicaCount = externalView.getRecord().getSimpleField("REPLICAS"); final int replicaCount; try { replicaCount = Integer.parseInt(helixReplicaCount); } catch (Exception e) { LOGGER.warn("Failed to parse the replica count ({}) from external view of table {}", helixReplicaCount, externalView.getResourceName()); return false; } if (replicaCount < _minReplicaCountForLargeCluster) { return false; } // Check if the server count is high enough to count as a large cluster final Set<String> instanceSet = new HashSet<>(); for (String partition : externalView.getPartitionSet()) { instanceSet.addAll(externalView.getStateMap(partition).keySet()); } return _minServerCountForLargeCluster <= instanceSet.size(); }
/** * return true if IdealState = ExternalView * @return */ public int isStable(String tableName) { IdealState idealState = helixAdmin.getResourceIdealState(clusterName, tableName); ExternalView externalView = helixAdmin.getResourceExternalView(clusterName, tableName); Map<String, Map<String, String>> mapFieldsIS = idealState.getRecord().getMapFields(); Map<String, Map<String, String>> mapFieldsEV = externalView.getRecord().getMapFields(); int numDiff = 0; for (String segment : mapFieldsIS.keySet()) { Map<String, String> mapIS = mapFieldsIS.get(segment); Map<String, String> mapEV = mapFieldsEV.get(segment); for (String server : mapIS.keySet()) { String state = mapIS.get(server); if (mapEV == null || mapEV.get(server) == null || !mapEV.get(server).equals(state)) { LOGGER.info( "Mismatch: segment " + segment + " server:" + server + " expected state:" + state + " actual state:" + ( (mapEV == null || mapEV.get(server) == null) ? "null" : mapEV.get(server))); numDiff = numDiff + 1; } } } return numDiff; }
/** * Check if IdealState = ExternalView. If its not equal, return the number of differing segments. */ public int isStable(String tableName) { IdealState idealState = _helixAdmin.getResourceIdealState(_helixClusterName, tableName); ExternalView externalView = _helixAdmin.getResourceExternalView(_helixClusterName, tableName); Map<String, Map<String, String>> mapFieldsIS = idealState.getRecord().getMapFields(); Map<String, Map<String, String>> mapFieldsEV = externalView.getRecord().getMapFields(); int numDiff = 0; for (String segment : mapFieldsIS.keySet()) { Map<String, String> mapIS = mapFieldsIS.get(segment); Map<String, String> mapEV = mapFieldsEV.get(segment); for (String server : mapIS.keySet()) { String state = mapIS.get(server); if (mapEV == null || mapEV.get(server) == null || !mapEV.get(server).equals(state)) { LOGGER.debug("Mismatch: segment" + segment + " server:" + server + " state:" + state); numDiff = numDiff + 1; } } } return numDiff; }
/** * return true if IdealState = ExternalView * @return */ public int isStable(String tableName) { IdealState idealState = helixAdmin.getResourceIdealState(clusterName, tableName); ExternalView externalView = helixAdmin.getResourceExternalView(clusterName, tableName); Map<String, Map<String, String>> mapFieldsIS = idealState.getRecord().getMapFields(); Map<String, Map<String, String>> mapFieldsEV = externalView.getRecord().getMapFields(); int numDiff = 0; for (String segment : mapFieldsIS.keySet()) { Map<String, String> mapIS = mapFieldsIS.get(segment); Map<String, String> mapEV = mapFieldsEV.get(segment); for (String server : mapIS.keySet()) { String state = mapIS.get(server); if (mapEV == null || mapEV.get(server) == null || !mapEV.get(server).equals(state)) { LOGGER.info("Mismatch: segment" + segment + " server:" + server + " state:" + state); numDiff = numDiff + 1; } } } return numDiff; }
@Nullable public Map<String, Map<String, String>> getExternalView(@Nonnull String tableNameOptType, CommonConstants.Helix.TableType tableType) { String tableNameWithType = getTableNameWithType(tableNameOptType, tableType); ExternalView resourceEV = _pinotHelixResourceManager.getHelixAdmin() .getResourceExternalView(_pinotHelixResourceManager.getHelixClusterName(), tableNameWithType); return resourceEV == null ? null : resourceEV.getRecord().getMapFields(); }
ExternalView resourceExternalView = helixAdmin.getResourceExternalView(clusterName, resourceName); Map<String, Map<String, String>> mapFieldsFromIS = resourceIdealState.getRecord().getMapFields(); Map<String, Map<String, String>> mapFieldsFromEV = resourceExternalView.getRecord().getMapFields(); boolean error = false; if (mapFieldsFromIS.size() != mapFieldsFromEV.size()) {
int externalViewRecordVersion = externalView.getRecord().getVersion(); int lastKnownExternalViewVersion = _lastKnownExternalViewVersionMap.get(tableName);
return; int currentVersionNumber = currentBrokerResource.getRecord().getVersion(); if (currentVersionNumber == _lastKnownBrokerResourceVersion.get()) { LOGGER.info("No qps quota change: external view for broker resource remains the same.");
private void buildRoutingTable(String tableNameWithType, ExternalView externalView, List<InstanceConfig> instanceConfigs) { int externalViewRecordVersion = externalView.getRecord().getVersion(); _lastKnownExternalViewVersionMap.put(tableNameWithType, externalViewRecordVersion);
/** * @param externalView * @param bestPossibleState map of partition to map of instance to state * @return */ boolean verifyExternalView(ExternalView externalView, Map<Partition, Map<String, String>> bestPossibleState) { Map<String, Map<String, String>> bestPossibleStateMap = convertBestPossibleState(bestPossibleState); // trimBestPossibleState(bestPossibleStateMap); Map<String, Map<String, String>> externalViewMap = externalView.getRecord().getMapFields(); return externalViewMap.equals(bestPossibleStateMap); }
/** * @param externalView * @param bestPossibleState map of partition to map of instance to state * @return */ boolean verifyExternalView(ExternalView externalView, Map<Partition, Map<String, String>> bestPossibleState) { Map<String, Map<String, String>> bestPossibleStateMap = convertBestPossibleState(bestPossibleState); // trimBestPossibleState(bestPossibleStateMap); Map<String, Map<String, String>> externalViewMap = externalView.getRecord().getMapFields(); return externalViewMap.equals(bestPossibleStateMap); }
@GET @Path("{resourceName}/externalView") public Response getResourceExternalView(@PathParam("clusterId") String clusterId, @PathParam("resourceName") String resourceName) { HelixAdmin admin = getHelixAdmin(); ExternalView externalView = admin.getResourceExternalView(clusterId, resourceName); if (externalView != null) { return JSONRepresentation(externalView.getRecord()); } return notFound(); }
private boolean verifyExternalView(ExternalView externalView, PartitionStateMap bestPossibleState, StateModelDefinition stateModelDef) { Set<String> ignoreStates = new HashSet<>( Arrays.asList(stateModelDef.getInitialState(), HelixDefinedState.DROPPED.toString())); Map<String, Map<String, String>> bestPossibleStateMap = convertBestPossibleState(bestPossibleState); removeEntryWithIgnoredStates(bestPossibleStateMap.entrySet().iterator(), ignoreStates); Map<String, Map<String, String>> externalViewMap = externalView.getRecord().getMapFields(); removeEntryWithIgnoredStates(externalViewMap.entrySet().iterator(), ignoreStates); return externalViewMap.equals(bestPossibleStateMap); }
private boolean verifyExternalView(ExternalView externalView, PartitionStateMap bestPossibleState, StateModelDefinition stateModelDef) { Set<String> ignoreStates = new HashSet<>( Arrays.asList(stateModelDef.getInitialState(), HelixDefinedState.DROPPED.toString())); Map<String, Map<String, String>> bestPossibleStateMap = convertBestPossibleState(bestPossibleState); removeEntryWithIgnoredStates(bestPossibleStateMap.entrySet().iterator(), ignoreStates); Map<String, Map<String, String>> externalViewMap = externalView.getRecord().getMapFields(); removeEntryWithIgnoredStates(externalViewMap.entrySet().iterator(), ignoreStates); return externalViewMap.equals(bestPossibleStateMap); }
private Set<String> getCurrentPartitionsOnInstance(String cluster, String dbName, String instance) { HelixAdmin admin = _gSetupTool.getClusterManagementTool(); Set<String> partitionSet = new HashSet<String>(); ExternalView ev = admin.getResourceExternalView(cluster, dbName); for (String partition : ev.getRecord().getMapFields().keySet()) { Map<String, String> assignments = ev.getRecord().getMapField(partition); for (String ins : assignments.keySet()) { if (ins.equals(instance)) { partitionSet.add(partition); } } } return partitionSet; } }
@Test (dependsOnMethods = "testMaintenanceModeInstanceBack") public void testExitMaintenanceModeNewResourceRecovery() throws InterruptedException { _gSetupTool.getClusterManagementTool().enableMaintenanceMode(CLUSTER_NAME, false); Assert.assertTrue(_clusterVerifier.verifyByPolling()); ExternalView externalView = _gSetupTool.getClusterManagementTool() .getResourceExternalView(CLUSTER_NAME, newResourceAddedDuringMaintenanceMode); Assert.assertEquals(externalView.getRecord().getMapFields().size(), 7); for (Map<String, String> stateMap : externalView.getRecord().getMapFields().values()) { Assert.assertTrue(stateMap.values().contains("MASTER")); } } }
@Test (dependsOnMethods = "testMaintenanceModeAddNewResource") public void testMaintenanceModeInstanceDown() throws InterruptedException { _participants[0].syncStop(); Assert.assertTrue(_clusterVerifier.verifyByPolling()); ExternalView externalView = _gSetupTool.getClusterManagementTool() .getResourceExternalView(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB); for (Map<String, String> stateMap : externalView.getRecord().getMapFields().values()) { Assert.assertTrue(stateMap.values().contains("MASTER")); } }
@Override public boolean verify() throws Exception { ExternalView extView = accessor.getProperty(keyBuilder.externalView("TestDB0")); for (int i = 0; i < p; i++) { String partition = "TestDB0_" + i; Map<String, String> map = extView.getRecord().getMapField(partition); if (map == null || map.size() != 1) { return false; } } return true; } }, 10 * 1000);
@Test (enabled = false) public void testOldEnableDisable() throws InterruptedException { _gSetupTool.getClusterManagementTool() .enableInstance(CLUSTER_NAME, _participants[0].getInstanceName(), false); Assert.assertTrue(_clusterVerifier.verify()); ExternalView externalView = _gSetupTool.getClusterManagementTool() .getResourceExternalView(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB); Assert.assertEquals(externalView.getRecord().getMapFields().size(), _numPartitions); for (Map<String, String> stateMap : externalView.getRecord().getMapFields().values()) { Assert.assertTrue(!stateMap.keySet().contains(_participants[0].getInstanceName())); } _gSetupTool.getClusterManagementTool() .enableInstance(CLUSTER_NAME, _participants[0].getInstanceName(), true); }
@Test (dependsOnMethods = "testMaintenanceModeInstanceDown") public void testMaintenanceModeInstanceBack() throws InterruptedException { _participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, _participants[0].getInstanceName()); _participants[0].syncStart(); Assert.assertTrue(_clusterVerifier.verifyByPolling()); ExternalView externalView = _gSetupTool.getClusterManagementTool() .getResourceExternalView(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB); for (Map<String, String> stateMap : externalView.getRecord().getMapFields().values()) { if (stateMap.containsKey(_participants[0].getInstanceName())) { Assert.assertTrue(stateMap.get(_participants[0].getInstanceName()).equals("SLAVE")); } } }