Search in sources :

Example 1 with VersionMismatchException

use of org.apache.drill.exec.exception.VersionMismatchException in project drill by apache.

the class TestDynamicUDFSupport method testExceedRetryAttemptsDuringUnregistration.

@Test
public void testExceedRetryAttemptsDuringUnregistration() throws Exception {
    RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
    copyDefaultJarsToStagingArea();
    test("create function using jar '%s'", default_binary_name);
    reset(remoteFunctionRegistry);
    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("drop function using jar '%s'", default_binary_name).unOrdered().baselineColumns("ok", "summary").baselineValues(false, summary).go();
    verify(remoteFunctionRegistry, times(remoteFunctionRegistry.getRetryAttempts() + 1)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
    FileSystem fs = remoteFunctionRegistry.getFs();
    assertTrue("Binary should be present in registry area", fs.exists(new Path(remoteFunctionRegistry.getRegistryArea(), default_binary_name)));
    assertTrue("Source should be present in registry area", fs.exists(new Path(remoteFunctionRegistry.getRegistryArea(), default_source_name)));
    Registry registry = remoteFunctionRegistry.getRegistry(new DataChangeVersion());
    assertEquals("Registry should contain one jar", registry.getJarList().size(), 1);
    assertEquals(registry.getJar(0).getName(), default_binary_name);
}
Also used : RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) 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) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) Test(org.junit.Test)

Example 2 with VersionMismatchException

use of org.apache.drill.exec.exception.VersionMismatchException in project drill by apache.

the class TestDynamicUDFSupport method testExceedRetryAttemptsDuringRegistration.

@Test
public void testExceedRetryAttemptsDuringRegistration() throws Exception {
    RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
    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'", default_binary_name).unOrdered().baselineColumns("ok", "summary").baselineValues(false, summary).go();
    verify(remoteFunctionRegistry, times(remoteFunctionRegistry.getRetryAttempts() + 1)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
    FileSystem fs = remoteFunctionRegistry.getFs();
    assertTrue("Binary should be present in staging area", fs.exists(new Path(remoteFunctionRegistry.getStagingArea(), default_binary_name)));
    assertTrue("Source should be present in staging area", fs.exists(new Path(remoteFunctionRegistry.getStagingArea(), default_source_name)));
    assertFalse("Registry area should be empty", fs.listFiles(remoteFunctionRegistry.getRegistryArea(), false).hasNext());
    assertFalse("Temporary area should be empty", fs.listFiles(remoteFunctionRegistry.getTmpArea(), false).hasNext());
    assertEquals("Registry should be empty", remoteFunctionRegistry.getRegistry(new DataChangeVersion()).getJarList().size(), 0);
}
Also used : RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) 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) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) Test(org.junit.Test)

Example 3 with VersionMismatchException

use of org.apache.drill.exec.exception.VersionMismatchException in project drill by apache.

the class TestDynamicUDFSupport method testSuccessfulUnregistrationAfterSeveralRetryAttempts.

@Test
public void testSuccessfulUnregistrationAfterSeveralRetryAttempts() throws Exception {
    RemoteFunctionRegistry remoteFunctionRegistry = spyRemoteFunctionRegistry();
    copyDefaultJarsToStagingArea();
    test("create function using jar '%s'", default_binary_name);
    reset(remoteFunctionRegistry);
    doThrow(new VersionMismatchException("Version mismatch detected", 1)).doThrow(new VersionMismatchException("Version mismatch detected", 1)).doCallRealMethod().when(remoteFunctionRegistry).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
    String summary = "The following UDFs in jar %s have been unregistered:\n" + "[custom_lower(VARCHAR-REQUIRED)]";
    testBuilder().sqlQuery("drop function using jar '%s'", default_binary_name).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format(summary, default_binary_name)).go();
    verify(remoteFunctionRegistry, times(3)).updateRegistry(any(Registry.class), any(DataChangeVersion.class));
    FileSystem fs = remoteFunctionRegistry.getFs();
    assertFalse("Registry area should be empty", fs.listFiles(remoteFunctionRegistry.getRegistryArea(), false).hasNext());
    assertEquals("Registry should be empty", remoteFunctionRegistry.getRegistry(new DataChangeVersion()).getJarList().size(), 0);
}
Also used : RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) FileSystem(org.apache.hadoop.fs.FileSystem) 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) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DataChangeVersion(org.apache.drill.exec.store.sys.store.DataChangeVersion) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) Test(org.junit.Test)

Example 4 with VersionMismatchException

use of org.apache.drill.exec.exception.VersionMismatchException in project drill by apache.

the class InMemoryStore method put.

@Override
public void put(final String key, final V value, final DataChangeVersion dataChangeVersion) {
    try (AutoCloseableLock lock = writeLock.open()) {
        if (dataChangeVersion != null && dataChangeVersion.getVersion() != version) {
            throw new VersionMismatchException("Version mismatch detected", dataChangeVersion.getVersion());
        }
        store.put(key, value);
        if (currentSize.incrementAndGet() > capacity) {
            //Pop Out Oldest
            store.pollLastEntry();
            currentSize.decrementAndGet();
        }
        version++;
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

Example 5 with VersionMismatchException

use of org.apache.drill.exec.exception.VersionMismatchException in project drill by axbaretto.

the class ZookeeperClient method put.

/**
 * Puts the given byte sequence into the given path.
 *
 * If path does not exists, this call creates it.
 *
 * If version holder is not null and path already exists, passes given version for comparison.
 * Zookeeper maintains stat structure that holds version number which increases each time znode data change is performed.
 * If we pass version that doesn't match the actual version of the data,
 * the update will fail {@link org.apache.zookeeper.KeeperException.BadVersionException}.
 * We catch such exception and re-throw it as {@link VersionMismatchException}.
 * Link to documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodes
 *
 * @param path  target path
 * @param data  data to store
 * @param version version holder
 */
public void put(final String path, final byte[] data, DataChangeVersion version) {
    Preconditions.checkNotNull(path, "path is required");
    Preconditions.checkNotNull(data, "data is required");
    final String target = PathUtils.join(root, path);
    try {
        // we make a consistent read to ensure this call won't fail upon consecutive calls on the same path
        // before cache is updated
        boolean hasNode = hasPath(path, true);
        if (!hasNode) {
            try {
                curator.create().withMode(mode).forPath(target, data);
            } catch (NodeExistsException e) {
                // Handle race conditions since Drill is distributed and other
                // drillbits may have just created the node. This assumes that we do want to
                // override the new node. Makes sense here, because if the node had existed,
                // we'd have updated it.
                hasNode = true;
            }
        }
        if (hasNode) {
            if (version != null) {
                try {
                    curator.setData().withVersion(version.getVersion()).forPath(target, data);
                } catch (final KeeperException.BadVersionException e) {
                    throw new VersionMismatchException("Unable to put data. Version mismatch is detected.", version.getVersion(), e);
                }
            } else {
                curator.setData().forPath(target, data);
            }
        }
        getCache().rebuildNode(target);
    } catch (final VersionMismatchException e) {
        throw e;
    } catch (final Exception e) {
        throw new DrillRuntimeException("unable to put ", e);
    }
}
Also used : NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Aggregations

VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)23 RemoteFunctionRegistry (org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry)16 Registry (org.apache.drill.exec.proto.UserBitShared.Registry)16 DataChangeVersion (org.apache.drill.exec.store.sys.store.DataChangeVersion)16 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)14 LocalFunctionRegistry (org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 Test (org.junit.Test)12 SlowTest (org.apache.drill.categories.SlowTest)8 SqlFunctionTest (org.apache.drill.categories.SqlFunctionTest)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Path (java.nio.file.Path)6 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)6 HadoopUtils.hadoopToJavaPath (org.apache.drill.test.HadoopUtils.hadoopToJavaPath)6 FileSystem (org.apache.hadoop.fs.FileSystem)6 Jar (org.apache.drill.exec.proto.UserBitShared.Jar)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 IOException (java.io.IOException)3 AutoCloseableLock (org.apache.drill.common.concurrent.AutoCloseableLock)3 Path (org.apache.hadoop.fs.Path)3