use of org.apache.drill.exec.store.sys.store.DataChangeVersion in project drill by apache.
the class TestDynamicUDFSupport method testExceedRetryAttemptsDuringRegistration.
@Test
public void testExceedRetryAttemptsDuringRegistration() throws Exception {
RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
Path registryPath = hadoopToJavaPath(remoteFunctionRegistry.getRegistryArea());
Path stagingPath = hadoopToJavaPath(remoteFunctionRegistry.getStagingArea());
Path tmpPath = hadoopToJavaPath(remoteFunctionRegistry.getTmpArea());
copyDefaultJarsToStagingArea();
doThrow(new VersionMismatchException("Version mismatch detected", 1)).when(remoteFunctionRegistry).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
String summary = "Failed to update remote function registry. Exceeded retry attempts limit.";
testBuilder().sqlQuery("create function using jar '%s'", defaultBinaryJar).unOrdered().baselineColumns("ok", "summary").baselineValues(false, summary).go();
verify(remoteFunctionRegistry, times(remoteFunctionRegistry.getRetryAttempts() + 1)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
assertTrue("Binary should be present in staging area", stagingPath.resolve(defaultBinaryJar).toFile().exists());
assertTrue("Source should be present in staging area", stagingPath.resolve(defaultSourceJar).toFile().exists());
assertTrue("Registry area should be empty", ArrayUtils.isEmpty(registryPath.toFile().listFiles()));
assertTrue("Temporary area should be empty", ArrayUtils.isEmpty(tmpPath.toFile().listFiles()));
assertEquals("Registry should be empty", remoteFunctionRegistry.getRegistry(new DataChangeVersion()).getJarList().size(), 0);
}
use of org.apache.drill.exec.store.sys.store.DataChangeVersion in project drill by apache.
the class TestDynamicUDFSupport method testDropFunction.
@Test
public void testDropFunction() throws Exception {
copyDefaultJarsToStagingArea();
test("create function using jar '%s'", defaultBinaryJar);
test("select custom_lower('A') from (values(1))");
Path localUdfDirPath = hadoopToJavaPath((org.apache.hadoop.fs.Path) FieldUtils.readField(getDrillbitContext().getFunctionImplementationRegistry(), "localUdfDir", true));
assertTrue("Binary should exist in local udf directory", localUdfDirPath.resolve(defaultBinaryJar).toFile().exists());
assertTrue("Source should exist in local udf directory", localUdfDirPath.resolve(defaultSourceJar).toFile().exists());
String summary = "The following UDFs in jar %s have been unregistered:\n" + "[custom_lower(VARCHAR-REQUIRED)]";
testBuilder().sqlQuery("drop function using jar '%s'", defaultBinaryJar).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format(summary, defaultBinaryJar)).go();
try {
test("select custom_lower('A') from (values(1))");
fail();
} catch (UserRemoteException e) {
assertTrue(e.getMessage().contains("No match found for function signature custom_lower(<CHARACTER>)"));
}
RemoteFunctionRegistry remoteFunctionRegistry = getDrillbitContext().getRemoteFunctionRegistry();
Path registryPath = hadoopToJavaPath(remoteFunctionRegistry.getRegistryArea());
assertEquals("Remote registry should be empty", remoteFunctionRegistry.getRegistry(new DataChangeVersion()).getJarList().size(), 0);
assertFalse("Binary should not be present in registry area", registryPath.resolve(defaultBinaryJar).toFile().exists());
assertFalse("Source should not be present in registry area", registryPath.resolve(defaultSourceJar).toFile().exists());
assertFalse("Binary should not be present in local udf directory", localUdfDirPath.resolve(defaultBinaryJar).toFile().exists());
assertFalse("Source should not be present in local udf directory", localUdfDirPath.resolve(defaultSourceJar).toFile().exists());
}
use of org.apache.drill.exec.store.sys.store.DataChangeVersion in project drill by apache.
the class TestZookeeperClient method testPutWithNonMatchingVersion.
@Test(expected = VersionMismatchException.class)
public void testPutWithNonMatchingVersion() {
client.put(path, data);
DataChangeVersion version = new DataChangeVersion();
version.setVersion(123);
client.put(path, data, version);
}
use of org.apache.drill.exec.store.sys.store.DataChangeVersion in project drill by apache.
the class TestZookeeperClient method testHasPathFalseWithVersion.
@Test
public void testHasPathFalseWithVersion() {
DataChangeVersion version0 = new DataChangeVersion();
version0.setVersion(-1);
assertFalse(client.hasPath("unknown_path", true, version0));
assertEquals("Versions should not have changed", -1, version0.getVersion());
}
use of org.apache.drill.exec.store.sys.store.DataChangeVersion in project drill by apache.
the class CreateFunctionHandler method initRemoteRegistration.
/**
* Instantiates remote registration. First gets remote function registry with version.
* Version is used to ensure that we update the same registry we validated against.
* Then validates against list of remote jars.
* If validation is successful, first copies jars to registry area and starts updating remote function registry.
* If during update {@link VersionMismatchException} was detected,
* attempts to repeat remote registration process till retry attempts exceeds the limit.
* If retry attempts number hits 0, throws exception that failed to update remote function registry.
* In case of any error, if jars have been already copied to registry area, they will be deleted.
*
* @param functions list of functions present in jar
* @param jarManager helper class for copying jars to registry area
* @param remoteRegistry remote function registry
* @throws IOException in case of problems with copying jars to registry area
*/
private void initRemoteRegistration(List<String> functions, JarManager jarManager, RemoteFunctionRegistry remoteRegistry) throws IOException {
int retryAttempts = remoteRegistry.getRetryAttempts();
boolean copyJars = true;
try {
while (retryAttempts >= 0) {
DataChangeVersion version = new DataChangeVersion();
List<Jar> remoteJars = remoteRegistry.getRegistry(version).getJarList();
validateAgainstRemoteRegistry(remoteJars, jarManager.getBinaryName(), functions);
if (copyJars) {
jarManager.copyToRegistryArea();
copyJars = false;
}
List<Jar> jars = Lists.newArrayList(remoteJars);
jars.add(Jar.newBuilder().setName(jarManager.getBinaryName()).addAllFunctionSignature(functions).build());
Registry updatedRegistry = Registry.newBuilder().addAllJar(jars).build();
try {
remoteRegistry.updateRegistry(updatedRegistry, version);
return;
} catch (VersionMismatchException ex) {
logger.debug("Failed to update function registry during registration, version mismatch was detected.", ex);
retryAttempts--;
}
}
throw new DrillRuntimeException("Failed to update remote function registry. Exceeded retry attempts limit.");
} catch (Exception e) {
if (!copyJars) {
jarManager.deleteQuietlyFromRegistryArea();
}
throw e;
}
}
Aggregations