Check if immediate children of directory are in sync with UFS.

@param inode read-locked directory to check
@param alluxioUri path of directory to to check
435755
public void checkDirectory(InodeDirectory inode, AlluxioURI alluxioUri)
      throws FileDoesNotExistException, InvalidPathException, IOException {
    Preconditions.checkArgument(inode.isPersisted());
    UfsStatus[] ufsChildren = getChildrenInUFS(alluxioUri);
    // Filter out temporary files
    ufsChildren = Arrays.stream(ufsChildren)
        .filter(ufsStatus -> !PathUtils.isTemporaryFileName(ufsStatus.getName()))
        .toArray(UfsStatus[]::new);
    Arrays.sort(ufsChildren, Comparator.comparing(UfsStatus::getName));
    Inode[] alluxioChildren = Iterables.toArray(mInodeStore.getChildren(inode), Inode.class);
    Arrays.sort(alluxioChildren);
    int ufsPos = 0;
    for (Inode alluxioInode : alluxioChildren) {
      if (ufsPos >= ufsChildren.length) {
        break;
      }
      String ufsName = ufsChildren[ufsPos].getName();
      if (ufsName.endsWith(AlluxioURI.SEPARATOR)) {
        ufsName = ufsName.substring(0, ufsName.length() - 1);
      }
      if (ufsName.equals(alluxioInode.getName())) {
        ufsPos++;
      }
    }

    if (ufsPos == ufsChildren.length) {
      // Directory is in sync
      mSyncedDirectories.put(alluxioUri, inode);
    } else {
      // Invalidate ancestor directories if not a mount point
      AlluxioURI currentPath = alluxioUri;
      while (currentPath.getParent() != null && !mMountTable.isMountPoint(currentPath)
          && mSyncedDirectories.containsKey(currentPath.getParent())) {
        mSyncedDirectories.remove(currentPath.getParent());
        currentPath = currentPath.getParent();
      }
      LOG.debug("Ufs file {} does not match any file in Alluxio", ufsChildren[ufsPos]);
    }
  }
87495
public static boolean isUnderDirectory(File child, File parent) {
        if (child == null || parent == null)
            return false;

        URI childUri = child.toURI();
        URI relativeUri = parent.toURI().relativize(childUri);
        return relativeUri.equals(childUri) ? false : true;

    }
1085036
private boolean ouIsOK(CmsOrganizationalUnit ou) {

        try {
            for (CmsResource res : OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(
                m_clonedCms,
                ou.getName())) {

                if (m_simpleFieldParentFolderName.getValue().startsWith(res.getRootPath())) {
                    return true;
                }

            }
        } catch (CmsException e) {
            LOG.error("Unable to read Resources for Org Unit", e);
        }
        return false;
    }
420785
public static boolean supportAlluxioHA(PrintWriter reportWriter,
      AlluxioConfiguration alluxioConf) {
    if (alluxioConf.getBoolean(PropertyKey.ZOOKEEPER_ENABLED)) {
      reportWriter.println("Alluixo is running in high availability mode.\n");
      if (!alluxioConf.isSet(PropertyKey.ZOOKEEPER_ADDRESS)) {
        reportWriter.println("Please set Zookeeper address to support "
            + "Alluxio high availability mode.\n");
        return false;
      } else {
        reportWriter.printf("Zookeeper address is: %s.%n",
            alluxioConf.get(PropertyKey.ZOOKEEPER_ADDRESS));
      }
    }
    return true;
  }
554317
public void stopSyncForMount(long mountId) throws InvalidPathException, IOException {
    LOG.debug("Stop sync for mount id {}", mountId);
    if (mFilterMap.containsKey(mountId)) {
      List<Pair<AlluxioURI, MountTable.Resolution>> toBeDeleted = new ArrayList<>();
      for (AlluxioURI uri : mFilterMap.get(mountId)) {
        MountTable.Resolution resolution = resolveSyncPoint(uri);
        if (resolution != null) {
          toBeDeleted.add(new Pair<>(uri, resolution));
        }
      }
      // Calling stopSyncInternal outside of the traversal of mFilterMap.get(mountId) to avoid
      // ConcurrentModificationException
      for (Pair<AlluxioURI, MountTable.Resolution> deleteInfo : toBeDeleted) {
        stopSyncInternal(deleteInfo.getFirst(), deleteInfo.getSecond());
      }
    }
  }
1105113
public static void checkMasterClientService(AlluxioConfiguration alluxioConf) throws IOException {
    try (CloseableResource<FileSystemMasterClient> client =
      FileSystemContext.create(ClientContext.create(alluxioConf))
          .acquireMasterClientResource()) {
      InetSocketAddress address = client.get().getAddress();

      List<InetSocketAddress> addresses = Arrays.asList(address);
      MasterInquireClient inquireClient = new PollingMasterInquireClient(addresses, () ->
          new ExponentialBackoffRetry(50, 100, 2), alluxioConf);
      inquireClient.getPrimaryRpcAddress();
    } catch (UnavailableException e) {
      throw new IOException("Cannot connect to Alluxio leader master.");
    }
  }
225806
int getBlockIndex(INodeFile inode, Block blk, String file) throws IOException {
    if (inode == null) {
      throw new IOException("inode for file " + file + " is null");
    }
    readLock();
    try {
      return inode.getBlockIndex(blk, file);
    } finally {
      readUnlock();
    }
  }
530964
public LockResource lockInode(InodeView inode, LockMode mode) {
    return mInodeLocks.get(inode.getId(), mode);
  }
982732
private static void checkLocalDirs(String[] localDirs)
    throws DiskErrorException {
    boolean writable = false;

    if (localDirs != null) {
      for (int i = 0; i < localDirs.length; i++) {
        try {
          DiskChecker.checkDir(new File(localDirs[i]));
          writable = true;
        } catch(DiskErrorException e) {
          LOG.warn("Task Tracker local " + e.getMessage());
        }
      }
    }

    if (!writable)
      throw new DiskErrorException(
                                   "all local directories are not writable");
  }
325835
public void setDirectChildrenLoaded(Supplier<JournalContext> context, InodeDirectory dir) {
    mState.applyAndJournal(context, UpdateInodeDirectoryEntry.newBuilder()
        .setId(dir.getId())
        .setDirectChildrenLoaded(true)
        .build());
  }
290821
protected int checkDirectoryWriteable(String location) {
        final String methodName = "checkDirectoryWriteable()";
        int rc = CacheOnDisk.LOCATION_OK;
        if (location.equals("")) {
            rc = CacheOnDisk.LOCATION_NOT_DEFINED;
        } else if (location.startsWith("${") && location.indexOf("}") > 0) {
            rc = CacheOnDisk.LOCATION_NOT_VALID;
        } else {
            try {
                File f = new File(location);
                if (!f.exists()) {
                    if (!f.mkdirs()) {
                        rc = CacheOnDisk.LOCATION_CANNOT_MAKE_DIR;
                    }
                } else if (!f.isDirectory()) {
                    rc = CacheOnDisk.LOCATION_NOT_DIRECTORY;
                } else if (!f.canWrite()) {
                    rc = CacheOnDisk.LOCATION_NOT_WRITABLE;
                }
            } catch (Throwable t) {
                rc = CacheOnDisk.LOCATION_NOT_WRITABLE;
                com.ibm.ws.ffdc.FFDCFilter.processException(t, "com.ibm.ws.cache.CacheOnDisk.checkDirectoryWriteable", "1779", this);
                traceDebug(methodName, "cacheName=" + this.cacheName + " location=" + location + "\nException: " + ExceptionUtility.getStackTrace(t));
            }
        }

        traceDebug(methodName, "cacheName=" + this.cacheName + " location=" + location + " rc=" + rc);
        return rc;
    }
1136418
INode getINode(long id) {
    readLock();
    try {
      INode inode = inodeMap.get(id);
      return inode;
    } finally {
      readUnlock();
    }
  }
200214
public String getMountPoint(AlluxioURI uri) throws InvalidPathException {
    String path = uri.getPath();
    String lastMount = ROOT;
    try (LockResource r = new LockResource(mReadLock)) {
      for (Map.Entry<String, MountInfo> entry : mState.getMountTable().entrySet()) {
        String mount = entry.getKey();
        // we choose a new candidate path if the previous candidatepath is a prefix
        // of the current alluxioPath and the alluxioPath is a prefix of the path
        if (!mount.equals(ROOT) && PathUtils.hasPrefix(path, mount)
            && PathUtils.hasPrefix(mount, lastMount)) {
          lastMount = mount;
        }
      }
      return lastMount;
    }
  }
457092
private static boolean match(AlluxioURI fileURI, AlluxioURI patternURI) {
    return escape(fileURI.getPath()).matches(replaceWildcards(patternURI.getPath()));
  }
181637
private void ensureExists(AlluxioURI path) throws IOException {
    try {
      mFileSystem.getStatus(path);
    } catch (AlluxioException e) {
      throw new IOException(e);
    }
  }
704200
private boolean isOutFile(final URI toCheckPath) {
        final String path = toCheckPath.getPath();
        return !(path != null && path.startsWith(rootDir.getPath()));
    }
483338
private boolean checkChildren(boolean exclusive, int depth) {
        if (_children == null) {
            // a file

            return _owner == null || !(_exclusive || exclusive);
        } else {
            // a folder

            if (_owner == null) {
                // no owner, checking children

                if (depth != 0) {
                    boolean canLock = true;
                    int limit = _children.length;
                    for (int i = 0; i < limit; i++) {
                        if (!_children[i].checkChildren(exclusive, depth - 1)) {
                            canLock = false;
                        }
                    }
                    return canLock;
                } else {
                    // depth == 0 -> we don't care for children
                    return true;
                }
            } else {
                // there already is a owner
                return !(_exclusive || exclusive);
            }
        }

    }