Java Code Examples for org.apache.helix.BaseDataAccessor#remove()
The following examples show how to use
org.apache.helix.BaseDataAccessor#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertyStoreAccessor.java From helix with Apache License 2.0 | 6 votes |
/** * Recursively deletes the PropertyStore path. If the node does not exist, it returns OK(). * @param clusterId * @param path * @return */ @DELETE @Path("{path: .+}") public Response deletePropertyByPath(@PathParam("clusterId") String clusterId, @PathParam("path") String path) { path = "/" + path; if (!ZkValidationUtil.isPathValid(path)) { LOG.info("The propertyStore path {} is invalid for cluster {}", path, clusterId); return badRequest( "Invalid path string. Valid path strings use slash as the directory separator and names the location of ZNode"); } final String recordPath = PropertyPathBuilder.propertyStore(clusterId) + path; BaseDataAccessor<byte[]> propertyStoreDataAccessor = getByteArrayDataAccessor(); if (!propertyStoreDataAccessor.remove(recordPath, AccessOption.PERSISTENT)) { return serverError("Failed to delete PropertyStore record in path: " + path); } return OK(); }
Example 2
Source File: ZKPathDataDumpTask.java From helix with Apache License 2.0 | 5 votes |
void dump(BaseDataAccessor<ZNRecord> accessor, String ancestorPath, long threshold, int maxLeafCount) { List<String> leafPaths = scanPath(accessor, ancestorPath); if (leafPaths.isEmpty()) { return; } Stat[] stats = accessor.getStats(leafPaths, 0); List<String> dumpPaths = Lists.newArrayList(); long now = System.currentTimeMillis(); for (int i = 0; i < stats.length; i++) { Stat stat = stats[i]; if ((stats.length > maxLeafCount) || ((now - stat.getMtime()) > threshold)) { dumpPaths.add(leafPaths.get(i)); } } if (!dumpPaths.isEmpty()) { LOG.info("Dump statusUpdates and errors records for paths: " + dumpPaths); // No need to fail the batch read operation even it is partial result becuase it is for cleaning up. List<ZNRecord> dumpRecords = accessor.get(dumpPaths, null, 0, false); for (ZNRecord record : dumpRecords) { if (record != null) { LOG.info(new String(_jsonSerializer.serialize(record))); } } // clean up accessor.remove(dumpPaths, 0); LOG.info("Remove statusUpdates and errors records for paths: " + dumpPaths); } }
Example 3
Source File: TestMultiZkHelixJavaApis.java From helix with Apache License 2.0 | 4 votes |
private void verifyBaseDataAccessorMsdsEndpoint( RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig) { System.out.println("Start " + TestHelper.getTestMethodName()); // MSDS endpoint is not configured in builder, so config in system property is used. BaseDataAccessor<ZNRecord> firstDataAccessor = new ZkBaseDataAccessor.Builder<ZNRecord>().build(); // Create base data accessor with MSDS endpoint configured in builder. BaseDataAccessor<ZNRecord> secondDataAccessor = new ZkBaseDataAccessor.Builder<ZNRecord>().setRealmAwareZkConnectionConfig(connectionConfig) .build(); String methodName = TestHelper.getTestMethodName(); String clusterOnePath = formPath(CLUSTER_ONE, methodName); String clusterFourPath = formPath(CLUSTER_FOUR, methodName); ZNRecord record = new ZNRecord(methodName); try { firstDataAccessor.create(clusterOnePath, record, AccessOption.PERSISTENT); secondDataAccessor.create(clusterFourPath, record, AccessOption.PERSISTENT); // Verify data accessors that they could only talk to their own configured MSDS endpoint: // either being set in builder or system property. Assert.assertTrue(firstDataAccessor.exists(clusterOnePath, AccessOption.PERSISTENT)); verifyMsdsZkRealm(CLUSTER_FOUR, false, () -> firstDataAccessor.exists(clusterFourPath, AccessOption.PERSISTENT)); Assert.assertTrue(secondDataAccessor.exists(clusterFourPath, AccessOption.PERSISTENT)); verifyMsdsZkRealm(CLUSTER_ONE, false, () -> secondDataAccessor.exists(clusterOnePath, AccessOption.PERSISTENT)); firstDataAccessor.remove(clusterOnePath, AccessOption.PERSISTENT); secondDataAccessor.remove(clusterFourPath, AccessOption.PERSISTENT); Assert.assertFalse(firstDataAccessor.exists(clusterOnePath, AccessOption.PERSISTENT)); Assert.assertFalse(secondDataAccessor.exists(clusterFourPath, AccessOption.PERSISTENT)); } finally { firstDataAccessor.close(); secondDataAccessor.close(); } }