Skip to content
Permalink
Browse files
[NO ISSUE][RT] Introduce query compilation lock
- user model changes: no
- storage format changes: no
- interface changes: yes

Details:

- Add query compilation lock that can be used to ensure
  no queries are currently running in the cluster.

Change-Id: I663458df62040c0c01a13afde36b5cf765e57929
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/12645
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Murtadha Hubail <mhubail@apache.org>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Reviewed-by: Ian Maxon <imaxon@uci.edu>
  • Loading branch information
mhubail committed Aug 4, 2021
1 parent 68e707e commit c5c6ec478aa2a37134271240d1530c38513b2342
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
@@ -42,6 +42,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;

import org.apache.asterix.active.ActivityState;
@@ -283,6 +284,7 @@ public class QueryTranslator extends AbstractLangTranslator implements IStatemen
protected final IMetadataLockUtil lockUtil;
protected final IResponsePrinter responsePrinter;
protected final WarningCollector warningCollector;
protected final ReentrantReadWriteLock compilationLock;

public QueryTranslator(ICcApplicationContext appCtx, List<Statement> statements, SessionOutput output,
ILangCompilationProvider compilationProvider, ExecutorService executorService,
@@ -301,6 +303,7 @@ public QueryTranslator(ICcApplicationContext appCtx, List<Statement> statements,
this.executorService = executorService;
this.responsePrinter = responsePrinter;
this.warningCollector = new WarningCollector();
this.compilationLock = appCtx.getCompilationLock();
if (appCtx.getServiceContext().getAppConfig().getBoolean(CCConfig.Option.ENFORCE_FRAME_WRITER_PROTOCOL)) {
this.jobFlags.add(JobFlag.ENFORCE_CONTRACT);
}
@@ -3392,12 +3395,14 @@ public JobSpecification handleInsertUpsertStatement(MetadataProvider metadataPro
final IMetadataLocker locker = new IMetadataLocker() {
@Override
public void lock() throws AlgebricksException {
compilationLock.readLock().lock();
lockUtil.insertDeleteUpsertBegin(lockManager, metadataProvider.getLocks(), dataverseName, datasetName);
}

@Override
public void unlock() {
metadataProvider.getLocks().unlock();
compilationLock.readLock().unlock();
}
};
final IStatementCompiler compiler = () -> {
@@ -3987,13 +3992,15 @@ protected void handleQuery(MetadataProvider metadataProvider, Query query, IHyra
final IMetadataLocker locker = new IMetadataLocker() {
@Override
public void lock() {
compilationLock.readLock().lock();
}

@Override
public void unlock() {
metadataProvider.getLocks().unlock();
// release external datasets' locks acquired during compilation of the query
ExternalDatasetsRegistry.INSTANCE.releaseAcquiredLocks(metadataProvider);
compilationLock.readLock().unlock();
}
};
final IStatementCompiler compiler = () -> {
@@ -18,6 +18,8 @@
*/
package org.apache.asterix.common.dataflow;

import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.apache.asterix.common.api.IApplicationContext;
import org.apache.asterix.common.api.ICoordinationService;
import org.apache.asterix.common.api.IMetadataLockManager;
@@ -149,4 +151,11 @@ public interface ICcApplicationContext extends IApplicationContext {
* @return the adapter factory service
*/
IAdapterFactoryService getAdapterFactoryService();

/**
* Gets the cluster query compilation lock
*
* @return the cluster query compilation lock
*/
ReentrantReadWriteLock getCompilationLock();
}
@@ -19,6 +19,7 @@
package org.apache.asterix.runtime.utils;

import java.io.IOException;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Supplier;

import org.apache.asterix.common.api.IConfigValidator;
@@ -100,6 +101,7 @@ public class CcApplicationContext implements ICcApplicationContext {
private final IRequestTracker requestTracker;
private final IConfigValidator configValidator;
private final IAdapterFactoryService adapterFactoryService;
private final ReentrantReadWriteLock compilationLock = new ReentrantReadWriteLock(true);

public CcApplicationContext(ICCServiceContext ccServiceCtx, IHyracksClientConnection hcc,
Supplier<IMetadataBootstrap> metadataBootstrapSupplier, IGlobalRecoveryManager globalRecoveryManager,
@@ -314,4 +316,9 @@ public IRequestTracker getRequestTracker() {
public IAdapterFactoryService getAdapterFactoryService() {
return adapterFactoryService;
}

@Override
public ReentrantReadWriteLock getCompilationLock() {
return compilationLock;
}
}

0 comments on commit c5c6ec4

Please sign in to comment.