Search in sources :

Example 1 with StringPairEntry

use of alluxio.proto.journal.File.StringPairEntry in project alluxio by Alluxio.

the class FileSystemMaster method mountAndJournal.

/**
   * Mounts a UFS path onto an Alluxio path.
   * <p>
   * Writes to the journal.
   *
   * @param inodePath the Alluxio path to mount to
   * @param ufsPath the UFS path to mount
   * @param options the mount options
   * @param journalContext the journal context
   * @throws InvalidPathException if an invalid path is encountered
   * @throws FileAlreadyExistsException if the path to be mounted to already exists
   * @throws FileDoesNotExistException if the parent of the path to be mounted to does not exist
   * @throws IOException if an I/O error occurs
   * @throws AccessControlException if the permission check fails
   */
private void mountAndJournal(LockedInodePath inodePath, AlluxioURI ufsPath, MountOptions options, JournalContext journalContext) throws InvalidPathException, FileAlreadyExistsException, FileDoesNotExistException, IOException, AccessControlException {
    // Check that the Alluxio Path does not exist
    if (inodePath.fullPathExists()) {
        // TODO(calvin): Add a test to validate this (ALLUXIO-1831)
        throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(inodePath.getUri()));
    }
    mountInternal(inodePath, ufsPath, false, /* not replayed */
    options);
    boolean loadMetadataSucceeded = false;
    try {
        // This will create the directory at alluxioPath
        loadDirectoryMetadataAndJournal(inodePath, LoadMetadataOptions.defaults().setCreateAncestors(false), journalContext);
        loadMetadataSucceeded = true;
    } finally {
        if (!loadMetadataSucceeded) {
            unmountInternal(inodePath.getUri());
        }
    }
    // For proto, build a list of String pairs representing the properties map.
    Map<String, String> properties = options.getProperties();
    List<StringPairEntry> protoProperties = new ArrayList<>(properties.size());
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        protoProperties.add(StringPairEntry.newBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build());
    }
    AddMountPointEntry addMountPoint = AddMountPointEntry.newBuilder().setAlluxioPath(inodePath.getUri().toString()).setUfsPath(ufsPath.toString()).setReadOnly(options.isReadOnly()).addAllProperties(protoProperties).setShared(options.isShared()).build();
    appendJournalEntry(JournalEntry.newBuilder().setAddMountPoint(addMountPoint).build(), journalContext);
}
Also used : AddMountPointEntry(alluxio.proto.journal.File.AddMountPointEntry) StringPairEntry(alluxio.proto.journal.File.StringPairEntry) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) InvalidPathException(alluxio.exception.InvalidPathException)

Aggregations

InvalidPathException (alluxio.exception.InvalidPathException)1 AddMountPointEntry (alluxio.proto.journal.File.AddMountPointEntry)1 StringPairEntry (alluxio.proto.journal.File.StringPairEntry)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1