gpt4 book ai didi

org.apache.helix.manager.zk.ZkBaseDataAccessor类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 23:56:49 30 4
gpt4 key购买 nike

本文整理了Java中org.apache.helix.manager.zk.ZkBaseDataAccessor类的一些代码示例,展示了ZkBaseDataAccessor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkBaseDataAccessor类的具体详情如下:
包路径:org.apache.helix.manager.zk.ZkBaseDataAccessor
类名称:ZkBaseDataAccessor

ZkBaseDataAccessor介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-pinot

void setPropertyStore(String clusterName) {
 _propertyStore =
   new ZkHelixPropertyStore<>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), "/" + clusterName + "/PROPERTYSTORE",
     null);
}

代码示例来源:origin: apache/incubator-pinot

LOGGER.info("Updating IdealState for table {}", tableName);
if (zkBaseDataAccessor
  .set(idealStateKey.getPath(), nextIdealState.getRecord(), currentIdealState.getRecord().getVersion(),
    AccessOption.PERSISTENT)) {

代码示例来源:origin: apache/helix

String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
 baseAccessor.create(path, new ZNRecord(Integer.toString(i)), AccessOption.PERSISTENT);
Assert.assertFalse(baseAccessor.exists(String.format("%s%s", root, path), 0),
  "Should not exist under new location");
Assert.assertTrue(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0),
  "Should exist under fallback location");
ZNRecord record = new ZNRecord("new0");
Assert.assertTrue(succeed);
record = baseAccessor.get(String.format("%s%s", fallbackRoot, path), null, 0);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), "0");
record = baseAccessor.get(String.format("%s%s", root, path), null, 0);
Assert.assertNotNull(record);
Assert.assertEquals(record.getId(), "new0");

代码示例来源:origin: apache/helix

@Test
public void testSyncExist() {
 String className = TestHelper.getTestClassName();
 String methodName = TestHelper.getTestMethodName();
 String testName = className + "_" + methodName;
 System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));
 String path = String.format("/%s/%s", _rootPath, "msg_0");
 ZNRecord record = new ZNRecord("msg_0");
 ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
 boolean success = accessor.exists(path, 0);
 Assert.assertFalse(success);
 success = accessor.create(path, record, AccessOption.EPHEMERAL);
 Assert.assertTrue(success);
 success = accessor.exists(path, 0);
 Assert.assertTrue(success);
 System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}

代码示例来源:origin: apache/helix

ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<>(_gZkClient);
boolean[] success = accessor.createChildren(paths, records, AccessOption.PERSISTENT);
for (int i = 0; i < 10; i++) {
 String msgId = "msg_" + i;
success = accessor.setChildren(paths, records, AccessOption.PERSISTENT);
for (int i = 0; i < 10; i++) {
 String msgId = "msg_" + i;
success = accessor.updateChildren(paths, znrecordUpdaters, AccessOption.PERSISTENT);
for (int i = 0; i < 10; i++) {
 String msgId = "msg_" + i;
records = accessor.getChildren(parentPath, null, 0);
for (int i = 0; i < 10; i++) {
 String msgId = "msg_" + i;
boolean[] exists = accessor.exists(paths, 0);
for (int i = 0; i < 10; i++) {
 String msgId = "msg_" + i;
Stat[] stats = accessor.getStats(paths, 0);
for (int i = 0; i < 10; i++) {
 String msgId = "msg_" + i;
success = accessor.remove(paths, 0);
for (int i = 0; i < 10; i++) {
 String msgId = "msg_" + i;

代码示例来源:origin: apache/helix

@Test
public void testSyncCreate() {
 String className = TestHelper.getTestClassName();
 String methodName = TestHelper.getTestMethodName();
 String testName = className + "_" + methodName;
 System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));
 String path = String.format("/%s/%s", _rootPath, "msg_0");
 ZNRecord record = new ZNRecord("msg_0");
 ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<>(_gZkClient);
 boolean success = accessor.create(path, record, AccessOption.PERSISTENT);
 Assert.assertTrue(success);
 ZNRecord getRecord = _gZkClient.readData(path);
 Assert.assertNotNull(getRecord);
 Assert.assertEquals(getRecord.getId(), "msg_0");
 record.setSimpleField("key0", "value0");
 success = accessor.create(path, record, AccessOption.PERSISTENT);
 Assert.assertFalse(success, "Should fail since node already exists");
 getRecord = _gZkClient.readData(path);
 Assert.assertNotNull(getRecord);
 Assert.assertEquals(getRecord.getSimpleFields().size(), 0);
 System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}

代码示例来源:origin: org.apache.helix/helix-core

public static void main(String[] args) {
 ZkClient zkclient = new ZkClient("localhost:2191");
 zkclient.setZkSerializer(new ZNRecordSerializer());
 ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(zkclient);
 List<List<String>> pathsCreated =
   new ArrayList<List<String>>(Collections.<List<String>> nCopies(createPaths.size(), null));
 accessor.create(createPaths, createRecords, needCreate, pathsCreated, AccessOption.PERSISTENT);
 System.out.println("pathsCreated: " + pathsCreated);
   new ArrayList<List<String>>(Collections.<List<String>> nCopies(setPaths.size(), null));
 boolean[] success =
   accessor.set(setPaths, setRecords, pathsCreated, null, AccessOption.PERSISTENT);
 System.out.println("pathsCreated: " + pathsCreated);
 System.out.println("setSuccess: " + Arrays.toString(success));
   accessor.update(updatePaths, updaters, pathsCreated, null, AccessOption.PERSISTENT);
 for (int i = 0; i < updatePaths.size(); i++) {
  success[i] = updateRecords.get(i) != null;

代码示例来源:origin: apache/helix

.buildZkClient(new HelixZkClient.ZkConnectionConfig(ZK_ADDR));
extZkclient.setZkSerializer(new ZNRecordSerializer());
ZkBaseDataAccessor<ZNRecord> extBaseAccessor = new ZkBaseDataAccessor<ZNRecord>(extZkclient);
String extViewPath = PropertyPathBuilder.externalView(clusterName);
ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
extBaseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
boolean[] success = extBaseAccessor.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 = extBaseAccessor.updateChildren(paths, updaters, AccessOption.PERSISTENT);
 records.add(record);
success = extBaseAccessor.setChildren(paths, records, AccessOption.PERSISTENT);
for (int i = 0; i < 10; i++) {
 Assert.assertTrue(success[i], "Should succeed in set: " + paths.get(i));
success = extBaseAccessor.remove(paths, 0);
for (int i = 0; i < 10; i++) {
 Assert.assertTrue(success[i], "Should succeed in remove: " + paths.get(i));

代码示例来源:origin: apache/helix

@Test
public void testSyncGetStat() {
 String className = TestHelper.getTestClassName();
 String methodName = TestHelper.getTestMethodName();
 String testName = className + "_" + methodName;
 System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));
 String path = String.format("/%s/%s", _rootPath, "msg_0");
 ZNRecord record = new ZNRecord("msg_0");
 ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
 Stat stat = accessor.getStat(path, 0);
 Assert.assertNull(stat);
 boolean success = accessor.create(path, record, AccessOption.EPHEMERAL);
 Assert.assertTrue(success);
 stat = accessor.getStat(path, 0);
 Assert.assertNotNull(stat);
 Assert.assertEquals(stat.getVersion(), 0);
 Assert.assertNotSame(stat.getEphemeralOwner(), 0);
 System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}

代码示例来源:origin: apache/helix

@Test
public void testSyncRemove() {
 String className = TestHelper.getTestClassName();
 String methodName = TestHelper.getTestMethodName();
 String testName = className + "_" + methodName;
 System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));
 String path = String.format("/%s/%s", _rootPath, "msg_0");
 ZNRecord record = new ZNRecord("msg_0");
 ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
 // Base data accessor shall not fail when remove a non-exist path
 boolean success = accessor.remove(path, 0);
 Assert.assertTrue(success);
 success = accessor.create(path, record, AccessOption.PERSISTENT);
 Assert.assertTrue(success);
 ZNRecord getRecord = _gZkClient.readData(path);
 Assert.assertNotNull(getRecord);
 Assert.assertEquals(getRecord.getId(), "msg_0");
 success = accessor.remove(path, 0);
 Assert.assertTrue(success);
 Assert.assertFalse(_gZkClient.exists(path));
 System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}

代码示例来源:origin: apache/helix

ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
String path = keyBuilder.liveInstance("localhost_12918").getPath();
Stat stat = new Stat();
ZNRecord data = accessor.get(path, stat, 2);
data.getSimpleFields().put("SESSION_ID", "invalid-id");
accessor.set(path, data, 2);
Thread.sleep(2000);

代码示例来源:origin: apache/helix

@Test
public void testSyncDoSet() {
 String className = TestHelper.getTestClassName();
 String methodName = TestHelper.getTestMethodName();
 String testName = className + "_" + methodName;
 System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));
 String path = String.format("/%s/%s/%s", _rootPath, "msg_0", "submsg_0");
 ZNRecord record = new ZNRecord("submsg_0");
 ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
 AccessResult result = accessor.doSet(path, record, -1, AccessOption.PERSISTENT);
 Assert.assertEquals(result._retCode, RetCode.OK);
 Assert.assertEquals(result._pathCreated.size(), 3);
 Assert.assertTrue(result._pathCreated.contains(String.format("/%s/%s", _rootPath, "msg_0")));
 Assert.assertTrue(result._pathCreated.contains(path));
 Assert.assertTrue(_gZkClient.exists(String.format("/%s/%s", _rootPath, "msg_0")));
 ZNRecord getRecord = _gZkClient.readData(path);
 Assert.assertNotNull(getRecord);
 Assert.assertEquals(getRecord.getId(), "submsg_0");
 System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}

代码示例来源:origin: apache/helix

@Test
public void testFailOnSingleGet() {
 String className = TestHelper.getTestClassName();
 String methodName = TestHelper.getTestMethodName();
 String clusterName = className + "_" + methodName;
 System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
 String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
 ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
 AutoFallbackPropertyStore<ZNRecord> store =
   new AutoFallbackPropertyStore<ZNRecord>(baseAccessor, root, fallbackRoot);
 String path = String.format("/%d", 0);
 Assert.assertFalse(baseAccessor.exists(String.format("%s%s", root, path), 0),
   "Should not exist under new location");
 Assert.assertFalse(baseAccessor.exists(String.format("%s%s", fallbackRoot, path), 0),
   "Should not exist under fallback location");
 // test single exist
 boolean exist = store.exists(path, 0);
 Assert.assertFalse(exist);
 // test single getStat
 Stat stat = store.getStat(path, 0);
 Assert.assertNull(stat);
 // test single get
 ZNRecord record = store.get(path, null, 0);
 Assert.assertNull(record);
 System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public boolean[] setChildren(List<String> paths, List<T> records, int options) {
 final int size = paths.size();
 List<String> serverPaths = prependChroot(paths);
 Cache<T> cache = getCache(serverPaths);
 if (cache != null) {
  try {
   cache.lockWrite();
   List<Stat> setStats = new ArrayList<Stat>();
   List<List<String>> pathsCreatedList =
     new ArrayList<List<String>>(Collections.<List<String>> nCopies(size, null));
   boolean[] success =
     _baseAccessor.set(serverPaths, records, pathsCreatedList, setStats, options);
   for (int i = 0; i < size; i++) {
    updateCache(cache, pathsCreatedList.get(i), success[i], serverPaths.get(i),
      records.get(i), setStats.get(i));
   }
   return success;
  } finally {
   cache.unlockWrite();
  }
 }
 return _baseAccessor.setChildren(serverPaths, records, options);
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public boolean set(String path, T data, int expectVersion, int options) {
 String clientPath = path;
 String serverPath = prependChroot(clientPath);
 Cache<T> cache = getCache(serverPath);
 boolean success = false;
 try {
  if (cache != null) {
   cache.lockWrite();
   ZkBaseDataAccessor<T>.AccessResult result =
     _baseAccessor.doSet(serverPath, data, expectVersion, options);
   success = result._retCode == RetCode.OK;
   updateCache(cache, result._pathCreated, success, serverPath, data, result._stat);
  } else {
   // no cache
   success = _baseAccessor.set(serverPath, data, expectVersion, options);
  }
 } catch (Exception e) {
 } finally {
  if (cache != null) {
   cache.unlockWrite();
  }
 }
 return success;
}

代码示例来源:origin: org.apache.helix/helix-core

try {
 merged = accessor.get(mergedKey, readStat, options);
} catch (ZkNoNodeException e) {
success = accessor.set(mergedKey, merged, readStat.getVersion(), options);
if (!success) {
 LOG.error("Fail to group commit. path: " + mergedKey + ", value: " + merged

代码示例来源:origin: org.apache.helix/helix-core

@Override
public List<T> get(List<String> paths, List<Stat> stats, int options,
  boolean throwException) throws HelixException {
 boolean[] needRead = new boolean[paths.size()];
 Arrays.fill(needRead, true);
 return get(paths, stats, needRead, throwException);
}

代码示例来源:origin: apache/helix

@Override
public Stat getStat(String path, int options) {
 String clientPath = path;
 String serverPath = prependChroot(clientPath);
 Cache<T> cache = getCache(serverPath);
 if (cache != null) {
  Stat stat = new Stat();
  ZNode znode = cache.get(serverPath);
  if (znode != null) {
   return znode.getStat();
  } else {
   // if cache miss, fall back to zk and update cache
   try {
    cache.lockWrite();
    T data = _baseAccessor.get(serverPath, stat, options);
    cache.update(serverPath, data, stat);
   } catch (ZkNoNodeException e) {
    return null;
   } finally {
    cache.unlockWrite();
   }
   return stat;
  }
 }
 // no cache
 return _baseAccessor.getStat(serverPath, options);
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public boolean[] createChildren(List<String> paths, List<T> records, int options) {
 final int size = paths.size();
 List<String> serverPaths = prependChroot(paths);
 Cache<T> cache = getCache(serverPaths);
 if (cache != null) {
  try {
   cache.lockWrite();
   boolean[] needCreate = new boolean[size];
   Arrays.fill(needCreate, true);
   List<List<String>> pathsCreatedList =
     new ArrayList<List<String>>(Collections.<List<String>> nCopies(size, null));
   CreateCallbackHandler[] createCbList =
     _baseAccessor.create(serverPaths, records, needCreate, pathsCreatedList, options);
   boolean[] success = new boolean[size];
   for (int i = 0; i < size; i++) {
    CreateCallbackHandler cb = createCbList[i];
    success[i] = (Code.get(cb.getRc()) == Code.OK);
    updateCache(cache, pathsCreatedList.get(i), success[i], serverPaths.get(i),
      records.get(i), ZNode.ZERO_STAT);
   }
   return success;
  } finally {
   cache.unlockWrite();
  }
 }
 // no cache
 return _baseAccessor.createChildren(serverPaths, records, options);
}

代码示例来源:origin: org.apache.helix/helix-core

get(paths, curStats, Arrays.copyOf(needUpdate, needUpdate.length), false);
createCbList = create(paths, newDataList, needCreate, pathsCreated, options);
for (int i = 0; i < paths.size(); i++) {
 CreateCallbackHandler createCb = createCbList[i];

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com