use of java.util.concurrent.locks.ReadWriteLock in project hive by apache.
the class QueryTracker method registerFragment.
/**
* Register a new fragment for a specific query
*/
QueryFragmentInfo registerFragment(QueryIdentifier queryIdentifier, String appIdString, String dagIdString, String dagName, String hiveQueryIdString, int dagIdentifier, String vertexName, int fragmentNumber, int attemptNumber, String user, SignableVertexSpec vertex, Token<JobTokenIdentifier> appToken, String fragmentIdString, LlapTokenInfo tokenInfo, final LlapNodeId amNodeId) throws IOException {
ReadWriteLock dagLock = getDagLock(queryIdentifier);
// Note: This is a readLock to prevent a race with queryComplete. Operations
// and mutations within this lock need to be on concurrent structures.
dagLock.readLock().lock();
try {
if (completedDagMap.contains(queryIdentifier)) {
// Cleanup the dag lock here, since it may have been created after the query completed
dagSpecificLocks.remove(queryIdentifier);
String message = "Dag " + dagName + " already complete. Rejecting fragment [" + vertexName + ", " + fragmentNumber + ", " + attemptNumber + "]";
LOG.info(message);
throw new RuntimeException(message);
}
// out of the request provided that it's signed.
if (tokenInfo == null) {
tokenInfo = LlapTokenChecker.getTokenInfo(clusterId);
}
boolean isExistingQueryInfo = true;
QueryInfo queryInfo = queryInfoMap.get(queryIdentifier);
if (queryInfo == null) {
if (UserGroupInformation.isSecurityEnabled()) {
Preconditions.checkNotNull(tokenInfo.userName);
}
queryInfo = new QueryInfo(queryIdentifier, appIdString, dagIdString, dagName, hiveQueryIdString, dagIdentifier, user, getSourceCompletionMap(queryIdentifier), localDirsBase, localFs, tokenInfo.userName, tokenInfo.appId, amNodeId);
QueryInfo old = queryInfoMap.putIfAbsent(queryIdentifier, queryInfo);
if (old != null) {
queryInfo = old;
} else {
// Ensure the UGI is setup once.
queryInfo.setupUmbilicalUgi(vertex.getTokenIdentifier(), appToken, amNodeId.getHostname(), amNodeId.getPort());
isExistingQueryInfo = false;
}
}
if (isExistingQueryInfo) {
// We already retrieved the incoming info, check without UGI.
LlapTokenChecker.checkPermissions(tokenInfo, queryInfo.getTokenUserName(), queryInfo.getTokenAppId(), queryInfo.getQueryIdentifier());
}
queryIdentifierToHiveQueryId.putIfAbsent(queryIdentifier, hiveQueryIdString);
if (LOG.isDebugEnabled()) {
LOG.debug("Registering request for {} with the ShuffleHandler", queryIdentifier);
}
ShuffleHandler.get().registerDag(appIdString, dagIdentifier, appToken, user, queryInfo.getLocalDirs());
return queryInfo.registerFragment(vertexName, fragmentNumber, attemptNumber, vertex, fragmentIdString);
} finally {
dagLock.readLock().unlock();
}
}
use of java.util.concurrent.locks.ReadWriteLock in project hive by apache.
the class QueryTracker method getDagLock.
private ReadWriteLock getDagLock(QueryIdentifier queryIdentifier) {
lock.lock();
try {
ReadWriteLock dagLock = dagSpecificLocks.get(queryIdentifier);
if (dagLock == null) {
dagLock = new ReentrantReadWriteLock();
dagSpecificLocks.put(queryIdentifier, dagLock);
}
return dagLock;
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReadWriteLock in project hive by apache.
the class QueryTracker method getRegisteredFragments.
List<QueryFragmentInfo> getRegisteredFragments(QueryIdentifier queryIdentifier) {
ReadWriteLock dagLock = getDagLock(queryIdentifier);
dagLock.readLock().lock();
try {
QueryInfo queryInfo = queryInfoMap.get(queryIdentifier);
if (queryInfo == null) {
// Race with queryComplete
LOG.warn("Unknown query: Returning an empty list of fragments");
return Collections.emptyList();
}
return queryInfo.getRegisteredFragments();
} finally {
dagLock.readLock().unlock();
}
}
use of java.util.concurrent.locks.ReadWriteLock in project jimfs by google.
the class FileSystemView method unlockSourceAndCopy.
/**
* Unlocks source and copy files after copying content. Also closes the source file so its
* content can be deleted if it was deleted.
*/
private void unlockSourceAndCopy(File sourceFile, File copyFile) {
ReadWriteLock sourceLock = sourceFile.contentLock();
if (sourceLock != null) {
sourceLock.readLock().unlock();
}
ReadWriteLock copyLock = copyFile.contentLock();
if (copyLock != null) {
copyLock.writeLock().unlock();
}
sourceFile.closed();
}
use of java.util.concurrent.locks.ReadWriteLock in project jimfs by google.
the class FileSystemView method lockSourceAndCopy.
/**
* Locks source and copy files before copying content. Also marks the source file as opened so
* that its content won't be deleted until after the copy if it is deleted.
*/
private void lockSourceAndCopy(File sourceFile, File copyFile) {
sourceFile.opened();
ReadWriteLock sourceLock = sourceFile.contentLock();
if (sourceLock != null) {
sourceLock.readLock().lock();
}
ReadWriteLock copyLock = copyFile.contentLock();
if (copyLock != null) {
copyLock.writeLock().lock();
}
}
Aggregations