Search in sources :

Example 16 with ReadWriteLock

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();
    }
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 17 with ReadWriteLock

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();
    }
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Example 18 with ReadWriteLock

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();
    }
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 19 with ReadWriteLock

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();
}
Also used : ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 20 with ReadWriteLock

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();
    }
}
Also used : ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Aggregations

ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)45 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)36 Lock (java.util.concurrent.locks.Lock)21 Test (org.junit.Test)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 Nullable (org.jetbrains.annotations.Nullable)4 ArrayList (java.util.ArrayList)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Ignore (org.junit.Ignore)2 Member (cz.metacentrum.perun.core.api.Member)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Random (java.util.Random)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 Phaser (java.util.concurrent.Phaser)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1