private boolean isStaleConfiguration(Configuration config) { String delimiter = "-"; String configId = config.getId(); // Bypasses item of "global" and folders of "version", just check db configurations. if (configId == null || configId.equals(Constants.GLOBAL_ID) || !configId.contains(delimiter)) { return false; } if (_serviceInfo.getId().endsWith(Constants.STANDALONE_ID)) { if (!configId.equals(_serviceInfo.getId())) { return true; } } else { CoordinatorClientInetAddressMap nodeMap = _coordinator.getInetAddessLookupMap(); int nodeCount = nodeMap.getControllerNodeIPLookupMap().size(); String nodeIndex = configId.split(delimiter)[1]; if (Constants.STANDALONE_ID.equalsIgnoreCase(nodeIndex) || Integer.parseInt(nodeIndex) > nodeCount) { return true; } } return false; }
private void removeStaleVersionedDbConfiguration() { String configKind = _coordinator.getVersionedDbConfigPath(_serviceInfo.getName(), _serviceInfo.getVersion()); List<Configuration> configs = _coordinator.queryAllConfiguration(_coordinator.getSiteId(), configKind); for (Configuration config : configs) { if (isStaleConfiguration(config)) { _coordinator.removeServiceConfiguration(_coordinator.getSiteId(), config); _log.info("Remove stale version db config, id: {}", config.getId()); } } }
private void removeStaleServiceConfiguration() { boolean isGeoDBSvc = isGeoDbsvc(); boolean resetAutoBootFlag = false; String configKind = _coordinator.getDbConfigPath(_serviceInfo.getName()); List<Configuration> configs = _coordinator.queryAllConfiguration(_coordinator.getSiteId(), configKind); for (Configuration config : configs) { if (isStaleConfiguration(config)) { boolean autoboot = Boolean.parseBoolean(config.getConfig(DbConfigConstants.AUTOBOOT)); String configId = config.getId(); if (isGeoDBSvc && !autoboot && (configId.equals("geodb-4") || configId.equals("geodb-5"))) { // for geodbsvc, if restore with the backup of 5 nodes to 3 nodes and the backup is made // on the cluster that the 'autoboot=false' is set on vipr4 or vipr5 // we should set the autoboot=false on the current node or no node with autoboot=false // TODO:This is a temporary/safest solution in Yoda, we'll provide a better soltuion post // Yoda resetAutoBootFlag = true; } if (isStaleConfiguration(config)) { _coordinator.removeServiceConfiguration(_coordinator.getSiteId(), config); _log.info("Remove stale db config, id: {}", config.getId()); } } } if (resetAutoBootFlag) { _log.info("set autoboot flag to false on {}", _serviceInfo.getId()); Configuration config = _coordinator.queryConfiguration( _coordinator.getSiteId(), configKind, _serviceInfo.getId()); config.setConfig(DbConfigConstants.AUTOBOOT, Boolean.FALSE.toString()); _coordinator.persistServiceConfiguration(_coordinator.getSiteId(), config); } }
/** * We select seeds based on the following rules - For DR standby sites, use all nodes in active * site as seeds For DR active site, use local nodes as seeds. The rule to select local seed is - * first boot node(AUTOBOOT = false) uses itself as seed nodes so that it could boot and * initialize schema - subsquent node(AUTOBOOT = true) uses other successfully booted(JOINED = * true) nodes as seeds */ @Override public List<InetAddress> getSeeds() { try { CoordinatorClientInetAddressMap nodeMap = _client.getInetAddessLookupMap(); List<Configuration> configs = _client.queryAllConfiguration(_client.getSiteId(), Constants.DB_CONFIG); List<InetAddress> seeds = new ArrayList<>(); // If we are upgrading from pre-2.5 releases, dbconfig exists in zk global area List<Configuration> leftoverConfig = _client.queryAllConfiguration(Constants.DB_CONFIG); configs.addAll(leftoverConfig); // Add extra seeds - seeds from remote sites for (String seed : extraSeeds) { if (StringUtils.isNotEmpty(seed)) { seeds.add(InetAddress.getByName(seed)); } } // On DR standby site, only use seeds from active site. On active site // we use local seeds if (isDrActiveSite) { for (int i = 0; i < configs.size(); i++) { Configuration config = configs.get(i); // Bypasses item of "global" and folders of "version", just check db configurations. if (config.getId() == null || config.getId().equals(Constants.GLOBAL_ID)) { continue; } String nodeIndex = config.getId().split("-")[1]; String nodeId = config.getConfig(DbConfigConstants.NODE_ID); if (nodeId == null) { // suppose that they are existing znodes from a previous version // set the NODE_ID config, id is like db-x nodeId = "vipr" + nodeIndex; config.setConfig(DbConfigConstants.NODE_ID, nodeId); config.removeConfig(DbConfigConstants.DB_IP); _client.persistServiceConfiguration(_client.getSiteId(), config); } if (!Boolean.parseBoolean(config.getConfig(DbConfigConstants.AUTOBOOT)) || (!config.getId().equals(_id) && Boolean.parseBoolean(config.getConfig(DbConfigConstants.JOINED)))) { // all non autobootstrap nodes + other nodes are used as seeds InetAddress ip = null; if (nodeMap != null) { String ipAddress = nodeMap.getConnectableInternalAddress(nodeId); _logger.debug("ip[" + i + "]: " + ipAddress); ip = InetAddress.getByName(ipAddress); } else { ip = InetAddress.getByName(nodeId); } seeds.add(ip); _logger.info("Seed {}", ip); } } } _logger.info("Seeds list {}", StringUtils.join(seeds.toArray(), ",")); return seeds; } catch (Exception e) { throw new IllegalStateException(e); } }