Search in sources :

Example 21 with DataChangeVersion

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);
}
Also used : RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) HadoopUtils.hadoopToJavaPath(org.apache.drill.test.HadoopUtils.hadoopToJavaPath) Path(java.nio.file.Path) LocalFunctionRegistry(org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) Registry(org.apache.drill.exec.proto.UserBitShared.Registry) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) SlowTest(org.apache.drill.categories.SlowTest) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) Test(org.junit.Test)

Example 22 with DataChangeVersion

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());
}
Also used : HadoopUtils.hadoopToJavaPath(org.apache.drill.test.HadoopUtils.hadoopToJavaPath) Path(java.nio.file.Path) RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) SlowTest(org.apache.drill.categories.SlowTest) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) Test(org.junit.Test)

Example 23 with DataChangeVersion

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);
}
Also used : DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 24 with DataChangeVersion

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());
}
Also used : DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 25 with DataChangeVersion

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;
    }
}
Also used : Jar(org.apache.drill.exec.proto.UserBitShared.Jar) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) Registry(org.apache.drill.exec.proto.UserBitShared.Registry) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) FunctionValidationException(org.apache.drill.exec.exception.FunctionValidationException) JarValidationException(org.apache.drill.exec.exception.JarValidationException) IOException(java.io.IOException) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

Aggregations

DataChangeVersion (org.apache.drill.exec.store.sys.store.DataChangeVersion)43 Test (org.junit.Test)34 RemoteFunctionRegistry (org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry)28 Registry (org.apache.drill.exec.proto.UserBitShared.Registry)25 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)24 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)23 LocalFunctionRegistry (org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry)21 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)19 SlowTest (org.apache.drill.categories.SlowTest)16 SqlFunctionTest (org.apache.drill.categories.SqlFunctionTest)16 Matchers.anyString (org.mockito.Matchers.anyString)16 Path (java.nio.file.Path)11 HadoopUtils.hadoopToJavaPath (org.apache.drill.test.HadoopUtils.hadoopToJavaPath)11 FileSystem (org.apache.hadoop.fs.FileSystem)11 Jar (org.apache.drill.exec.proto.UserBitShared.Jar)10 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)9 IOException (java.io.IOException)8 Path (org.apache.hadoop.fs.Path)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 CountDownLatch (java.util.concurrent.CountDownLatch)6