/// <summary> /// This method must be used to obtain the dir allocation context for a /// particular value of the context name. /// </summary> /// <remarks> /// This method must be used to obtain the dir allocation context for a /// particular value of the context name. The context name must be an item /// defined in the Configuration object for which we want to control the /// dir allocations (e.g., <code>mapred.local.dir</code>). The method will /// create a context for that name if it doesn't already exist. /// </remarks> private LocalDirAllocator.AllocatorPerContext ObtainContext(string contextCfgItemName ) { lock (contexts) { LocalDirAllocator.AllocatorPerContext l = contexts[contextCfgItemName]; if (l == null) { contexts[contextCfgItemName] = (l = new LocalDirAllocator.AllocatorPerContext(contextCfgItemName )); } return(l); } }
/// <summary>Get the current directory index for the given configuration item.</summary> /// <returns>the current directory index for the given configuration item.</returns> internal virtual int GetCurrentDirectoryIndex() { LocalDirAllocator.AllocatorPerContext context = ObtainContext(contextCfgItemName); return(context.GetCurrentDirectoryIndex()); }
/// <summary> /// We search through all the configured dirs for the file's existence /// and return true when we find /// </summary> /// <param name="pathStr">the requested file (this will be searched)</param> /// <param name="conf">the Configuration object</param> /// <returns>true if files exist. false otherwise</returns> /// <exception cref="System.IO.IOException"/> public virtual bool IfExists(string pathStr, Configuration conf) { LocalDirAllocator.AllocatorPerContext context = ObtainContext(contextCfgItemName); return(context.IfExists(pathStr, conf)); }
/// <summary>Creates a temporary file in the local FS.</summary> /// <remarks> /// Creates a temporary file in the local FS. Pass size as -1 if not known /// apriori. We round-robin over the set of disks (via the configured dirs) /// and select the first complete path which has enough space. A file is /// created on this directory. The file is guaranteed to go away when the /// JVM exits. /// </remarks> /// <param name="pathStr">prefix for the temporary file</param> /// <param name="size">the size of the file that is going to be written</param> /// <param name="conf">the Configuration object</param> /// <returns>a unique temporary file</returns> /// <exception cref="System.IO.IOException"/> public virtual FilePath CreateTmpFileForWrite(string pathStr, long size, Configuration conf) { LocalDirAllocator.AllocatorPerContext context = ObtainContext(contextCfgItemName); return(context.CreateTmpFileForWrite(pathStr, size, conf)); }
/// <summary>Get a path from the local FS for reading.</summary> /// <remarks> /// Get a path from the local FS for reading. We search through all the /// configured dirs for the file's existence and return the complete /// path to the file when we find one /// </remarks> /// <param name="pathStr">the requested file (this will be searched)</param> /// <param name="conf">the Configuration object</param> /// <returns>the complete path to the file on a local disk</returns> /// <exception cref="System.IO.IOException"/> public virtual Path GetLocalPathToRead(string pathStr, Configuration conf) { LocalDirAllocator.AllocatorPerContext context = ObtainContext(contextCfgItemName); return(context.GetLocalPathToRead(pathStr, conf)); }
/// <summary>Get a path from the local FS.</summary> /// <remarks> /// Get a path from the local FS. Pass size as /// SIZE_UNKNOWN if not known apriori. We /// round-robin over the set of disks (via the configured dirs) and return /// the first complete path which has enough space /// </remarks> /// <param name="pathStr"> /// the requested path (this will be created on the first /// available disk) /// </param> /// <param name="size">the size of the file that is going to be written</param> /// <param name="conf">the Configuration object</param> /// <param name="checkWrite">ensure that the path is writable</param> /// <returns>the complete path to the file on a local disk</returns> /// <exception cref="System.IO.IOException"/> public virtual Path GetLocalPathForWrite(string pathStr, long size, Configuration conf, bool checkWrite) { LocalDirAllocator.AllocatorPerContext context = ObtainContext(contextCfgItemName); return(context.GetLocalPathForWrite(pathStr, size, conf, checkWrite)); }