final GridNodeInfo localNode = config.getLocalNode();
if(!_excludeNodeList.contains(localNode)) {
_excludeNodeList.add(localNode);
}
final GridNodeSelector nodeSelector = config.getNodeSelector();
final LockManager lockManager = directory.getLockManager();
final Map<GridNode, List<String>> assignMap = new HashMap<GridNode, List<String>>(_relativePaths.size());
final List<Pair<String, Lock>> localExecResources = new ArrayList<Pair<String, Lock>>(_relativePaths.size());
int totalLocked = 0;
for(String path : _relativePaths) {
ReadWriteLock lock = lockManager.obtainLock(path);
final Lock rlock = lock.readLock();
if(rlock.tryLock()) {
localExecResources.add(new Pair<String, Lock>(path, rlock));
} else {
totalLocked++;
final byte[] k = StringUtils.getBytes(path);
final GridNodeValueCollector collector = new GridNodeValueCollector(_excludeNodeList);
try {
directory.exactSearch(k, collector);
} catch (DbException e) {
String errmsg = "Exception caused while lookup: " + path;
LOG.error(errmsg, e);
throw new GridException(errmsg, e);
}
final List<GridNode> replicatedNodes = collector.getMatched();
if(replicatedNodes == null || replicatedNodes.isEmpty()) {
throw new GridException("No replicated document found for path: " + path);
}
// TODO Select a node that least recently used for write requests.
GridNode node = nodeSelector.selectNode(replicatedNodes, config);
assert (node != null);
List<String> mappedPaths = assignMap.get(node);
if(mappedPaths == null) {
mappedPaths = new ArrayList<String>(16);
assignMap.put(node, mappedPaths);