/** * Check if an Instance exists in the Helix cluster. * * @param instanceName: Name of instance to check. * @return True if instance exists in the Helix cluster, False otherwise. */ public boolean instanceExists(String instanceName) { ZNRecord znRecord = _cacheInstanceConfigsDataAccessor.get("/" + instanceName, null, AccessOption.PERSISTENT); return (znRecord != null); }
/** * Get all instance Ids. * * @return List of instance Ids */ @Nonnull public List<String> getAllInstances() { return _cacheInstanceConfigsDataAccessor.getChildNames("/", AccessOption.PERSISTENT); }
/** * Returns the config for all the Helix instances in the cluster. */ public List<InstanceConfig> getAllHelixInstanceConfigs() { List<ZNRecord> znRecords = _cacheInstanceConfigsDataAccessor.getChildren("/", null, AccessOption.PERSISTENT); List<InstanceConfig> instanceConfigs = new ArrayList<>(znRecords.size()); znRecords.forEach(znRecord -> instanceConfigs.add(new InstanceConfig(znRecord))); return instanceConfigs; }
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, cachePaths, null); boolean[] success = accessor.createChildren(paths, records, AccessOption.PERSISTENT); for (int i = 0; i < 10; i++) { Assert.assertTrue(success[i], "Should succeed in create: " + paths.get(i)); updaters.add(updater); success = accessor.updateChildren(paths, updaters, AccessOption.PERSISTENT); records.add(record); success = accessor.setChildren(paths, records, AccessOption.PERSISTENT); for (int i = 0; i < 10; i++) { Assert.assertTrue(success[i], "Should succeed in set: " + paths.get(i)); records = accessor.get(paths, null, 0); for (int i = 0; i < 10; i++) { Assert.assertEquals(records.get(i).getId(), "TestDB" + i); records = accessor.getChildren(extViewPath, null, 0); for (int i = 0; i < 10; i++) { Assert.assertEquals(records.get(i).getId(), "TestDB" + i); success = accessor.exists(paths, 0); for (int i = 0; i < 10; i++) { Assert.assertTrue(success[i], "Should exits: TestDB" + i);
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, cachePaths, null); boolean success = accessor.create(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT); Assert.assertTrue(success, "Should succeed in create: " + path); newRecord.setSimpleField("" + j, "" + j); boolean success = accessor.update(path, new ZNRecordUpdater(newRecord), AccessOption.PERSISTENT); Assert.assertTrue(success, "Should succeed in update: " + path); boolean success = accessor.set(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT); Assert.assertTrue(success, "Should succeed in set: " + path); ZNRecord record = accessor.get(path, null, 0); Assert.assertEquals(record.getId(), "TestDB" + i); List<String> childNames = accessor.getChildNames(extViewPath, 0); String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_0", "TestDB" + i); Assert.assertTrue(accessor.exists(path, 0));
@Override public List<T> getChildren(String parentPath, List<Stat> stats, int options) { List<String> childNames = getChildNames(parentPath, options); if (childNames == null) { return null; } List<String> paths = new ArrayList<>(); for (String childName : childNames) { String path = parentPath.equals("/") ? "/" + childName : parentPath + "/" + childName; paths.add(path); } return get(paths, stats, options); }
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, null, cachePaths); accessor.subscribe(curStatePath, listener); newRecord.setSimpleField("" + j, "" + j); boolean success = accessor.update(path, new ZNRecordUpdater(newRecord), AccessOption.PERSISTENT); Assert.assertTrue(success, "Should succeed in update: " + path); String path = curStatePath + "/session_0/TestDB" + i; removePaths.add(path); boolean success = accessor.remove(path, AccessOption.PERSISTENT); Assert.assertTrue(success, "Should succeed in remove: " + path);
/** * Create Helix cluster if needed, and then start a Pinot controller instance. */ public synchronized void start() { _helixZkManager = HelixSetupUtils .setup(_helixClusterName, _helixZkURL, _instanceId, _isUpdateStateModel, _enableBatchMessageMode); Preconditions.checkNotNull(_helixZkManager); _helixAdmin = _helixZkManager.getClusterManagmentTool(); _propertyStore = _helixZkManager.getHelixPropertyStore(); _helixDataAccessor = _helixZkManager.getHelixDataAccessor(); // Cache instance zk paths. BaseDataAccessor<ZNRecord> baseDataAccessor = _helixDataAccessor.getBaseDataAccessor(); String instanceConfigs = PropertyPathBuilder.instanceConfig(_helixClusterName); _cacheInstanceConfigsDataAccessor = new ZkCacheBaseDataAccessor<>((ZkBaseDataAccessor<ZNRecord>) baseDataAccessor, instanceConfigs, null, Collections.singletonList(instanceConfigs)); _keyBuilder = _helixDataAccessor.keyBuilder(); _segmentDeletionManager = new SegmentDeletionManager(_dataDir, _helixAdmin, _helixClusterName, _propertyStore); ZKMetadataProvider.setClusterTenantIsolationEnabled(_propertyStore, _isSingleTenantCluster); _tableRebalancer = new TableRebalancer(_helixZkManager, _helixAdmin, _helixClusterName); }
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, Arrays.asList(curStatePath), null); boolean success = accessor.create(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT); Assert.assertTrue(success, "Should succeed in create: " + path); boolean success = accessor.create(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT); Assert.assertFalse(success, "Should fail in create due to NodeExists: " + path);
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, Arrays.asList(curStatePath, extViewPath), null); boolean[] success = accessor.createChildren(paths, records, AccessOption.PERSISTENT); for (int i = 0; i < 10; i++) { Assert.assertTrue(success[i], "Should succeed in create: " + paths.get(i)); success = accessor.createChildren(paths, records, AccessOption.PERSISTENT);
@Override public boolean[] exists(List<String> paths, int options) { final int size = paths.size(); boolean exists[] = new boolean[size]; for (int i = 0; i < size; i++) { exists[i] = exists(paths.get(i), options); } return exists; }
@Override public boolean set(String path, T data, int options) { return set(path, data, -1, options); }
private void updateCache(Cache<T> cache, List<String> createPaths, boolean success, String updatePath, T data, Stat stat) { if (createPaths == null || createPaths.isEmpty()) { if (success) { cache.update(updatePath, data, stat); } } else { String firstPath = firstCachePath(createPaths); if (firstPath != null) { cache.updateRecursive(firstPath); } } }
boolean[] success = _accessor.createChildren(paths, records, AccessOption.PERSISTENT);
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, null, zkCacheInitPaths); boolean[] success = accessor.createChildren(paths, records, AccessOption.PERSISTENT); for (int i = 0; i < 10; i++) { Assert.assertTrue(success[i], "Should succeed in create: " + paths.get(i)); updaters.add(updater); success = accessor.updateChildren(paths, updaters, AccessOption.PERSISTENT); records.add(record); success = accessor.setChildren(paths, records, AccessOption.PERSISTENT); for (int i = 0; i < 10; i++) { Assert.assertTrue(success[i], "Should succeed in set: " + paths.get(i)); records = accessor.get(paths, null, 0); for (int i = 0; i < 10; i++) { Assert.assertEquals(records.get(i).getId(), "TestDB" + i); records = accessor.getChildren(extViewPath, null, 0); for (int i = 0; i < 10; i++) { Assert.assertEquals(records.get(i).getId(), "TestDB" + i); success = accessor.exists(paths, 0); for (int i = 0; i < 10; i++) { Assert.assertTrue(success[i], "Should exits: " + paths.get(i));
@Override public List<T> getChildren(String parentPath, List<Stat> stats, int options) { List<String> childNames = getChildNames(parentPath, options); if (childNames == null) { return null; } List<String> paths = new ArrayList<>(); for (String childName : childNames) { String path = parentPath.equals("/") ? "/" + childName : parentPath + "/" + childName; paths.add(path); } return get(paths, stats, options); }
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, cachePaths, null);
@Override public boolean[] exists(List<String> paths, int options) { final int size = paths.size(); boolean exists[] = new boolean[size]; for (int i = 0; i < size; i++) { exists[i] = exists(paths.get(i), options); } return exists; }
@Override public boolean set(String path, T data, int options) { return set(path, data, -1, options); }
private void updateCache(Cache<T> cache, List<String> createPaths, boolean success, String updatePath, T data, Stat stat) { if (createPaths == null || createPaths.isEmpty()) { if (success) { cache.update(updatePath, data, stat); } } else { String firstPath = firstCachePath(createPaths); if (firstPath != null) { cache.updateRecursive(firstPath); } } }