id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
18,800
Alluxio/alluxio
integration/checker/src/main/java/alluxio/checker/MapReduceIntegrationChecker.java
MapReduceIntegrationChecker.run
private int run(String[] args) throws Exception { Configuration conf = new Configuration(); String numMaps = new GenericOptionsParser(conf, args).getRemainingArgs()[0]; conf.set(MRJobConfig.NUM_MAPS, numMaps); createHdfsFilesystem(conf); Job job = Job.getInstance(conf, "MapReduceIntegrationChecker"); job.setJarByClass(MapReduceIntegrationChecker.class); job.setMapperClass(CheckerMapper.class); job.setCombinerClass(CheckerReducer.class); job.setReducerClass(CheckerReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setInputFormatClass(EmptyInputFormat.class); FileOutputFormat.setOutputPath(job, mOutputFilePath); try { if (!job.waitForCompletion(true)) { return 1; } Status resultStatus = generateReport(); return resultStatus.equals(Status.SUCCESS) ? 0 : (resultStatus.equals(Status.FAIL_TO_FIND_CLASS) ? 2 : 1); } finally { if (mFileSystem.exists(mOutputFilePath)) { mFileSystem.delete(mOutputFilePath, true); } mFileSystem.close(); } }
java
private int run(String[] args) throws Exception { Configuration conf = new Configuration(); String numMaps = new GenericOptionsParser(conf, args).getRemainingArgs()[0]; conf.set(MRJobConfig.NUM_MAPS, numMaps); createHdfsFilesystem(conf); Job job = Job.getInstance(conf, "MapReduceIntegrationChecker"); job.setJarByClass(MapReduceIntegrationChecker.class); job.setMapperClass(CheckerMapper.class); job.setCombinerClass(CheckerReducer.class); job.setReducerClass(CheckerReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setInputFormatClass(EmptyInputFormat.class); FileOutputFormat.setOutputPath(job, mOutputFilePath); try { if (!job.waitForCompletion(true)) { return 1; } Status resultStatus = generateReport(); return resultStatus.equals(Status.SUCCESS) ? 0 : (resultStatus.equals(Status.FAIL_TO_FIND_CLASS) ? 2 : 1); } finally { if (mFileSystem.exists(mOutputFilePath)) { mFileSystem.delete(mOutputFilePath, true); } mFileSystem.close(); } }
[ "private", "int", "run", "(", "String", "[", "]", "args", ")", "throws", "Exception", "{", "Configuration", "conf", "=", "new", "Configuration", "(", ")", ";", "String", "numMaps", "=", "new", "GenericOptionsParser", "(", "conf", ",", "args", ")", ".", "getRemainingArgs", "(", ")", "[", "0", "]", ";", "conf", ".", "set", "(", "MRJobConfig", ".", "NUM_MAPS", ",", "numMaps", ")", ";", "createHdfsFilesystem", "(", "conf", ")", ";", "Job", "job", "=", "Job", ".", "getInstance", "(", "conf", ",", "\"MapReduceIntegrationChecker\"", ")", ";", "job", ".", "setJarByClass", "(", "MapReduceIntegrationChecker", ".", "class", ")", ";", "job", ".", "setMapperClass", "(", "CheckerMapper", ".", "class", ")", ";", "job", ".", "setCombinerClass", "(", "CheckerReducer", ".", "class", ")", ";", "job", ".", "setReducerClass", "(", "CheckerReducer", ".", "class", ")", ";", "job", ".", "setOutputKeyClass", "(", "Text", ".", "class", ")", ";", "job", ".", "setOutputValueClass", "(", "Text", ".", "class", ")", ";", "job", ".", "setInputFormatClass", "(", "EmptyInputFormat", ".", "class", ")", ";", "FileOutputFormat", ".", "setOutputPath", "(", "job", ",", "mOutputFilePath", ")", ";", "try", "{", "if", "(", "!", "job", ".", "waitForCompletion", "(", "true", ")", ")", "{", "return", "1", ";", "}", "Status", "resultStatus", "=", "generateReport", "(", ")", ";", "return", "resultStatus", ".", "equals", "(", "Status", ".", "SUCCESS", ")", "?", "0", ":", "(", "resultStatus", ".", "equals", "(", "Status", ".", "FAIL_TO_FIND_CLASS", ")", "?", "2", ":", "1", ")", ";", "}", "finally", "{", "if", "(", "mFileSystem", ".", "exists", "(", "mOutputFilePath", ")", ")", "{", "mFileSystem", ".", "delete", "(", "mOutputFilePath", ",", "true", ")", ";", "}", "mFileSystem", ".", "close", "(", ")", ";", "}", "}" ]
Implements MapReduce with Alluxio integration checker. @return 0 for success, 2 for unable to find Alluxio classes, 1 otherwise
[ "Implements", "MapReduce", "with", "Alluxio", "integration", "checker", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/integration/checker/src/main/java/alluxio/checker/MapReduceIntegrationChecker.java#L267-L296
18,801
Alluxio/alluxio
integration/checker/src/main/java/alluxio/checker/MapReduceIntegrationChecker.java
MapReduceIntegrationChecker.main
public static void main(String[] args) throws Exception { MapReduceIntegrationChecker checker = new MapReduceIntegrationChecker(); System.exit(checker.run(args)); }
java
public static void main(String[] args) throws Exception { MapReduceIntegrationChecker checker = new MapReduceIntegrationChecker(); System.exit(checker.run(args)); }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "throws", "Exception", "{", "MapReduceIntegrationChecker", "checker", "=", "new", "MapReduceIntegrationChecker", "(", ")", ";", "System", ".", "exit", "(", "checker", ".", "run", "(", "args", ")", ")", ";", "}" ]
Main function will be triggered via hadoop jar. @param args numMaps will be passed in
[ "Main", "function", "will", "be", "triggered", "via", "hadoop", "jar", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/integration/checker/src/main/java/alluxio/checker/MapReduceIntegrationChecker.java#L303-L306
18,802
Alluxio/alluxio
core/common/src/main/java/alluxio/util/JvmPauseMonitor.java
JvmPauseMonitor.stop
public void stop() { Preconditions.checkState(mJvmMonitorThread != null, "JVM monitor thread does not start"); mJvmMonitorThread.interrupt(); try { mJvmMonitorThread.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } reset(); }
java
public void stop() { Preconditions.checkState(mJvmMonitorThread != null, "JVM monitor thread does not start"); mJvmMonitorThread.interrupt(); try { mJvmMonitorThread.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } reset(); }
[ "public", "void", "stop", "(", ")", "{", "Preconditions", ".", "checkState", "(", "mJvmMonitorThread", "!=", "null", ",", "\"JVM monitor thread does not start\"", ")", ";", "mJvmMonitorThread", ".", "interrupt", "(", ")", ";", "try", "{", "mJvmMonitorThread", ".", "join", "(", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "Thread", ".", "currentThread", "(", ")", ".", "interrupt", "(", ")", ";", "}", "reset", "(", ")", ";", "}" ]
Stops jvm monitor.
[ "Stops", "jvm", "monitor", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/JvmPauseMonitor.java#L83-L93
18,803
Alluxio/alluxio
underfs/s3a/src/main/java/alluxio/underfs/s3a/S3AUtils.java
S3AUtils.translateBucketAcl
public static short translateBucketAcl(AccessControlList acl, String userId) { short mode = (short) 0; for (Grant grant : acl.getGrantsAsList()) { Permission perm = grant.getPermission(); Grantee grantee = grant.getGrantee(); if (perm.equals(Permission.Read)) { if (isUserIdInGrantee(grantee, userId)) { // If the bucket is readable by the user, add r and x to the owner mode. mode |= (short) 0500; } } else if (perm.equals(Permission.Write)) { if (isUserIdInGrantee(grantee, userId)) { // If the bucket is writable by the user, +w to the owner mode. mode |= (short) 0200; } } else if (perm.equals(Permission.FullControl)) { if (isUserIdInGrantee(grantee, userId)) { // If the user has full control to the bucket, +rwx to the owner mode. mode |= (short) 0700; } } } return mode; }
java
public static short translateBucketAcl(AccessControlList acl, String userId) { short mode = (short) 0; for (Grant grant : acl.getGrantsAsList()) { Permission perm = grant.getPermission(); Grantee grantee = grant.getGrantee(); if (perm.equals(Permission.Read)) { if (isUserIdInGrantee(grantee, userId)) { // If the bucket is readable by the user, add r and x to the owner mode. mode |= (short) 0500; } } else if (perm.equals(Permission.Write)) { if (isUserIdInGrantee(grantee, userId)) { // If the bucket is writable by the user, +w to the owner mode. mode |= (short) 0200; } } else if (perm.equals(Permission.FullControl)) { if (isUserIdInGrantee(grantee, userId)) { // If the user has full control to the bucket, +rwx to the owner mode. mode |= (short) 0700; } } } return mode; }
[ "public", "static", "short", "translateBucketAcl", "(", "AccessControlList", "acl", ",", "String", "userId", ")", "{", "short", "mode", "=", "(", "short", ")", "0", ";", "for", "(", "Grant", "grant", ":", "acl", ".", "getGrantsAsList", "(", ")", ")", "{", "Permission", "perm", "=", "grant", ".", "getPermission", "(", ")", ";", "Grantee", "grantee", "=", "grant", ".", "getGrantee", "(", ")", ";", "if", "(", "perm", ".", "equals", "(", "Permission", ".", "Read", ")", ")", "{", "if", "(", "isUserIdInGrantee", "(", "grantee", ",", "userId", ")", ")", "{", "// If the bucket is readable by the user, add r and x to the owner mode.", "mode", "|=", "(", "short", ")", "0500", ";", "}", "}", "else", "if", "(", "perm", ".", "equals", "(", "Permission", ".", "Write", ")", ")", "{", "if", "(", "isUserIdInGrantee", "(", "grantee", ",", "userId", ")", ")", "{", "// If the bucket is writable by the user, +w to the owner mode.", "mode", "|=", "(", "short", ")", "0200", ";", "}", "}", "else", "if", "(", "perm", ".", "equals", "(", "Permission", ".", "FullControl", ")", ")", "{", "if", "(", "isUserIdInGrantee", "(", "grantee", ",", "userId", ")", ")", "{", "// If the user has full control to the bucket, +rwx to the owner mode.", "mode", "|=", "(", "short", ")", "0700", ";", "}", "}", "}", "return", "mode", ";", "}" ]
Translates S3 bucket ACL to Alluxio owner mode. @param acl the acl of S3 bucket @param userId the S3 user id of the Alluxio owner @return the translated posix mode in short format
[ "Translates", "S3", "bucket", "ACL", "to", "Alluxio", "owner", "mode", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/underfs/s3a/src/main/java/alluxio/underfs/s3a/S3AUtils.java#L31-L54
18,804
Alluxio/alluxio
core/base/src/main/java/alluxio/uri/StandardURI.java
StandardURI.compareScheme
private int compareScheme(URI other) { String scheme = getScheme(); String otherScheme = other.getScheme(); if (scheme == null && otherScheme == null) { return 0; } if (scheme != null) { if (otherScheme != null) { return scheme.compareToIgnoreCase(otherScheme); } // not null is greater than 'null'. return 1; } // 'null' is less than not null. return -1; }
java
private int compareScheme(URI other) { String scheme = getScheme(); String otherScheme = other.getScheme(); if (scheme == null && otherScheme == null) { return 0; } if (scheme != null) { if (otherScheme != null) { return scheme.compareToIgnoreCase(otherScheme); } // not null is greater than 'null'. return 1; } // 'null' is less than not null. return -1; }
[ "private", "int", "compareScheme", "(", "URI", "other", ")", "{", "String", "scheme", "=", "getScheme", "(", ")", ";", "String", "otherScheme", "=", "other", ".", "getScheme", "(", ")", ";", "if", "(", "scheme", "==", "null", "&&", "otherScheme", "==", "null", ")", "{", "return", "0", ";", "}", "if", "(", "scheme", "!=", "null", ")", "{", "if", "(", "otherScheme", "!=", "null", ")", "{", "return", "scheme", ".", "compareToIgnoreCase", "(", "otherScheme", ")", ";", "}", "// not null is greater than 'null'.", "return", "1", ";", "}", "// 'null' is less than not null.", "return", "-", "1", ";", "}" ]
Compares the schemes of this URI and a given URI. @param other the other {@link URI} to compare the scheme @return a negative integer, zero, or a positive integer if this scheme is respectively less than, equal to, or greater than the full scheme of the other URI.
[ "Compares", "the", "schemes", "of", "this", "URI", "and", "a", "given", "URI", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/base/src/main/java/alluxio/uri/StandardURI.java#L163-L179
18,805
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java
InodeTreePersistentState.applyAndJournal
public long applyAndJournal(Supplier<JournalContext> context, NewBlockEntry entry) { try { long id = applyNewBlock(entry); context.get().append(JournalEntry.newBuilder().setNewBlock(entry).build()); return id; } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
java
public long applyAndJournal(Supplier<JournalContext> context, NewBlockEntry entry) { try { long id = applyNewBlock(entry); context.get().append(JournalEntry.newBuilder().setNewBlock(entry).build()); return id; } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
[ "public", "long", "applyAndJournal", "(", "Supplier", "<", "JournalContext", ">", "context", ",", "NewBlockEntry", "entry", ")", "{", "try", "{", "long", "id", "=", "applyNewBlock", "(", "entry", ")", ";", "context", ".", "get", "(", ")", ".", "append", "(", "JournalEntry", ".", "newBuilder", "(", ")", ".", "setNewBlock", "(", "entry", ")", ".", "build", "(", ")", ")", ";", "return", "id", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "ProcessUtils", ".", "fatalError", "(", "LOG", ",", "t", ",", "\"Failed to apply %s\"", ",", "entry", ")", ";", "throw", "t", ";", "// fatalError will usually system.exit", "}", "}" ]
Allocates and returns the next block ID for the indicated inode. @param context journal context supplier @param entry new block entry @return the new block id
[ "Allocates", "and", "returns", "the", "next", "block", "ID", "for", "the", "indicated", "inode", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java#L185-L194
18,806
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java
InodeTreePersistentState.applyAndJournal
public void applyAndJournal(Supplier<JournalContext> context, RenameEntry entry) { try { applyRename(entry); context.get().append(JournalEntry.newBuilder().setRename(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
java
public void applyAndJournal(Supplier<JournalContext> context, RenameEntry entry) { try { applyRename(entry); context.get().append(JournalEntry.newBuilder().setRename(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
[ "public", "void", "applyAndJournal", "(", "Supplier", "<", "JournalContext", ">", "context", ",", "RenameEntry", "entry", ")", "{", "try", "{", "applyRename", "(", "entry", ")", ";", "context", ".", "get", "(", ")", ".", "append", "(", "JournalEntry", ".", "newBuilder", "(", ")", ".", "setRename", "(", "entry", ")", ".", "build", "(", ")", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "ProcessUtils", ".", "fatalError", "(", "LOG", ",", "t", ",", "\"Failed to apply %s\"", ",", "entry", ")", ";", "throw", "t", ";", "// fatalError will usually system.exit", "}", "}" ]
Renames an inode. @param context journal context supplier @param entry rename entry
[ "Renames", "an", "inode", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java#L202-L210
18,807
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java
InodeTreePersistentState.applyAndJournal
public void applyAndJournal(Supplier<JournalContext> context, SetAclEntry entry) { try { applySetAcl(entry); context.get().append(JournalEntry.newBuilder().setSetAcl(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
java
public void applyAndJournal(Supplier<JournalContext> context, SetAclEntry entry) { try { applySetAcl(entry); context.get().append(JournalEntry.newBuilder().setSetAcl(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
[ "public", "void", "applyAndJournal", "(", "Supplier", "<", "JournalContext", ">", "context", ",", "SetAclEntry", "entry", ")", "{", "try", "{", "applySetAcl", "(", "entry", ")", ";", "context", ".", "get", "(", ")", ".", "append", "(", "JournalEntry", ".", "newBuilder", "(", ")", ".", "setSetAcl", "(", "entry", ")", ".", "build", "(", ")", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "ProcessUtils", ".", "fatalError", "(", "LOG", ",", "t", ",", "\"Failed to apply %s\"", ",", "entry", ")", ";", "throw", "t", ";", "// fatalError will usually system.exit", "}", "}" ]
Sets an ACL for an inode. @param context journal context supplier @param entry set acl entry
[ "Sets", "an", "ACL", "for", "an", "inode", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java#L218-L226
18,808
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java
InodeTreePersistentState.applyAndJournal
public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeEntry entry) { try { applyUpdateInode(entry); context.get().append(JournalEntry.newBuilder().setUpdateInode(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
java
public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeEntry entry) { try { applyUpdateInode(entry); context.get().append(JournalEntry.newBuilder().setUpdateInode(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
[ "public", "void", "applyAndJournal", "(", "Supplier", "<", "JournalContext", ">", "context", ",", "UpdateInodeEntry", "entry", ")", "{", "try", "{", "applyUpdateInode", "(", "entry", ")", ";", "context", ".", "get", "(", ")", ".", "append", "(", "JournalEntry", ".", "newBuilder", "(", ")", ".", "setUpdateInode", "(", "entry", ")", ".", "build", "(", ")", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "ProcessUtils", ".", "fatalError", "(", "LOG", ",", "t", ",", "\"Failed to apply %s\"", ",", "entry", ")", ";", "throw", "t", ";", "// fatalError will usually system.exit", "}", "}" ]
Updates an inode's state. This is used for state common to both files and directories. @param context journal context supplier @param entry update inode entry
[ "Updates", "an", "inode", "s", "state", ".", "This", "is", "used", "for", "state", "common", "to", "both", "files", "and", "directories", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java#L234-L242
18,809
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java
InodeTreePersistentState.applyAndJournal
public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeDirectoryEntry entry) { try { applyUpdateInodeDirectory(entry); context.get().append(JournalEntry.newBuilder().setUpdateInodeDirectory(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
java
public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeDirectoryEntry entry) { try { applyUpdateInodeDirectory(entry); context.get().append(JournalEntry.newBuilder().setUpdateInodeDirectory(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
[ "public", "void", "applyAndJournal", "(", "Supplier", "<", "JournalContext", ">", "context", ",", "UpdateInodeDirectoryEntry", "entry", ")", "{", "try", "{", "applyUpdateInodeDirectory", "(", "entry", ")", ";", "context", ".", "get", "(", ")", ".", "append", "(", "JournalEntry", ".", "newBuilder", "(", ")", ".", "setUpdateInodeDirectory", "(", "entry", ")", ".", "build", "(", ")", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "ProcessUtils", ".", "fatalError", "(", "LOG", ",", "t", ",", "\"Failed to apply %s\"", ",", "entry", ")", ";", "throw", "t", ";", "// fatalError will usually system.exit", "}", "}" ]
Updates an inode directory's state. @param context journal context supplier @param entry update inode directory entry
[ "Updates", "an", "inode", "directory", "s", "state", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java#L250-L258
18,810
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java
InodeTreePersistentState.applyAndJournal
public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeFileEntry entry) { try { applyUpdateInodeFile(entry); context.get().append(JournalEntry.newBuilder().setUpdateInodeFile(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
java
public void applyAndJournal(Supplier<JournalContext> context, UpdateInodeFileEntry entry) { try { applyUpdateInodeFile(entry); context.get().append(JournalEntry.newBuilder().setUpdateInodeFile(entry).build()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", entry); throw t; // fatalError will usually system.exit } }
[ "public", "void", "applyAndJournal", "(", "Supplier", "<", "JournalContext", ">", "context", ",", "UpdateInodeFileEntry", "entry", ")", "{", "try", "{", "applyUpdateInodeFile", "(", "entry", ")", ";", "context", ".", "get", "(", ")", ".", "append", "(", "JournalEntry", ".", "newBuilder", "(", ")", ".", "setUpdateInodeFile", "(", "entry", ")", ".", "build", "(", ")", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "ProcessUtils", ".", "fatalError", "(", "LOG", ",", "t", ",", "\"Failed to apply %s\"", ",", "entry", ")", ";", "throw", "t", ";", "// fatalError will usually system.exit", "}", "}" ]
Updates an inode file's state. @param context journal context supplier @param entry update inode file entry
[ "Updates", "an", "inode", "file", "s", "state", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java#L266-L274
18,811
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java
InodeTreePersistentState.applyAndJournal
public void applyAndJournal(Supplier<JournalContext> context, MutableInode<?> inode) { try { applyCreateInode(inode); context.get().append(inode.toJournalEntry()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", inode); throw t; // fatalError will usually system.exit } }
java
public void applyAndJournal(Supplier<JournalContext> context, MutableInode<?> inode) { try { applyCreateInode(inode); context.get().append(inode.toJournalEntry()); } catch (Throwable t) { ProcessUtils.fatalError(LOG, t, "Failed to apply %s", inode); throw t; // fatalError will usually system.exit } }
[ "public", "void", "applyAndJournal", "(", "Supplier", "<", "JournalContext", ">", "context", ",", "MutableInode", "<", "?", ">", "inode", ")", "{", "try", "{", "applyCreateInode", "(", "inode", ")", ";", "context", ".", "get", "(", ")", ".", "append", "(", "inode", ".", "toJournalEntry", "(", ")", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "ProcessUtils", ".", "fatalError", "(", "LOG", ",", "t", ",", "\"Failed to apply %s\"", ",", "inode", ")", ";", "throw", "t", ";", "// fatalError will usually system.exit", "}", "}" ]
Adds an inode to the inode tree. @param context journal context supplier @param inode an inode to add and create a journal entry for
[ "Adds", "an", "inode", "to", "the", "inode", "tree", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/InodeTreePersistentState.java#L282-L290
18,812
Alluxio/alluxio
core/common/src/main/java/alluxio/heartbeat/SleepingTimer.java
SleepingTimer.tick
public void tick() throws InterruptedException { if (mPreviousTickMs != 0) { long executionTimeMs = mClock.millis() - mPreviousTickMs; if (executionTimeMs > mIntervalMs) { mLogger.warn("{} last execution took {} ms. Longer than the interval {}", mThreadName, executionTimeMs, mIntervalMs); } else { mSleeper.sleep(Duration.ofMillis(mIntervalMs - executionTimeMs)); } } mPreviousTickMs = mClock.millis(); }
java
public void tick() throws InterruptedException { if (mPreviousTickMs != 0) { long executionTimeMs = mClock.millis() - mPreviousTickMs; if (executionTimeMs > mIntervalMs) { mLogger.warn("{} last execution took {} ms. Longer than the interval {}", mThreadName, executionTimeMs, mIntervalMs); } else { mSleeper.sleep(Duration.ofMillis(mIntervalMs - executionTimeMs)); } } mPreviousTickMs = mClock.millis(); }
[ "public", "void", "tick", "(", ")", "throws", "InterruptedException", "{", "if", "(", "mPreviousTickMs", "!=", "0", ")", "{", "long", "executionTimeMs", "=", "mClock", ".", "millis", "(", ")", "-", "mPreviousTickMs", ";", "if", "(", "executionTimeMs", ">", "mIntervalMs", ")", "{", "mLogger", ".", "warn", "(", "\"{} last execution took {} ms. Longer than the interval {}\"", ",", "mThreadName", ",", "executionTimeMs", ",", "mIntervalMs", ")", ";", "}", "else", "{", "mSleeper", ".", "sleep", "(", "Duration", ".", "ofMillis", "(", "mIntervalMs", "-", "executionTimeMs", ")", ")", ";", "}", "}", "mPreviousTickMs", "=", "mClock", ".", "millis", "(", ")", ";", "}" ]
Enforces the thread waits for the given interval between consecutive ticks. @throws InterruptedException if the thread is interrupted while waiting
[ "Enforces", "the", "thread", "waits", "for", "the", "given", "interval", "between", "consecutive", "ticks", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/heartbeat/SleepingTimer.java#L74-L85
18,813
Alluxio/alluxio
core/common/src/main/java/alluxio/heartbeat/HeartbeatContext.java
HeartbeatContext.setTimerClass
@SuppressWarnings("unused") private static synchronized void setTimerClass(String name, Class<? extends HeartbeatTimer> timerClass) { if (timerClass == null) { sTimerClasses.remove(name); } else { sTimerClasses.put(name, timerClass); } }
java
@SuppressWarnings("unused") private static synchronized void setTimerClass(String name, Class<? extends HeartbeatTimer> timerClass) { if (timerClass == null) { sTimerClasses.remove(name); } else { sTimerClasses.put(name, timerClass); } }
[ "@", "SuppressWarnings", "(", "\"unused\"", ")", "private", "static", "synchronized", "void", "setTimerClass", "(", "String", "name", ",", "Class", "<", "?", "extends", "HeartbeatTimer", ">", "timerClass", ")", "{", "if", "(", "timerClass", "==", "null", ")", "{", "sTimerClasses", ".", "remove", "(", "name", ")", ";", "}", "else", "{", "sTimerClasses", ".", "put", "(", "name", ",", "timerClass", ")", ";", "}", "}" ]
Sets the timer class to use for the specified executor thread. This method should only be used by tests. @param name a name of a heartbeat executor thread @param timerClass the timer class to use for the executor thread
[ "Sets", "the", "timer", "class", "to", "use", "for", "the", "specified", "executor", "thread", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/heartbeat/HeartbeatContext.java#L116-L124
18,814
Alluxio/alluxio
core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java
JournalUtils.getJournalLocation
public static URI getJournalLocation() { String journalDirectory = ServerConfiguration.get(PropertyKey.MASTER_JOURNAL_FOLDER); if (!journalDirectory.endsWith(AlluxioURI.SEPARATOR)) { journalDirectory += AlluxioURI.SEPARATOR; } try { return new URI(journalDirectory); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
java
public static URI getJournalLocation() { String journalDirectory = ServerConfiguration.get(PropertyKey.MASTER_JOURNAL_FOLDER); if (!journalDirectory.endsWith(AlluxioURI.SEPARATOR)) { journalDirectory += AlluxioURI.SEPARATOR; } try { return new URI(journalDirectory); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
[ "public", "static", "URI", "getJournalLocation", "(", ")", "{", "String", "journalDirectory", "=", "ServerConfiguration", ".", "get", "(", "PropertyKey", ".", "MASTER_JOURNAL_FOLDER", ")", ";", "if", "(", "!", "journalDirectory", ".", "endsWith", "(", "AlluxioURI", ".", "SEPARATOR", ")", ")", "{", "journalDirectory", "+=", "AlluxioURI", ".", "SEPARATOR", ";", "}", "try", "{", "return", "new", "URI", "(", "journalDirectory", ")", ";", "}", "catch", "(", "URISyntaxException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "}" ]
Returns a URI for the configured location for the specified journal. @return the journal location
[ "Returns", "a", "URI", "for", "the", "configured", "location", "for", "the", "specified", "journal", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java#L53-L63
18,815
Alluxio/alluxio
core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java
JournalUtils.writeJournalEntryCheckpoint
public static void writeJournalEntryCheckpoint(OutputStream output, JournalEntryIterable iterable) throws IOException, InterruptedException { output = new CheckpointOutputStream(output, CheckpointType.JOURNAL_ENTRY); Iterator<JournalEntry> it = iterable.getJournalEntryIterator(); LOG.info("Write journal entry checkpoint"); while (it.hasNext()) { if (Thread.interrupted()) { throw new InterruptedException(); } it.next().writeDelimitedTo(output); } output.flush(); }
java
public static void writeJournalEntryCheckpoint(OutputStream output, JournalEntryIterable iterable) throws IOException, InterruptedException { output = new CheckpointOutputStream(output, CheckpointType.JOURNAL_ENTRY); Iterator<JournalEntry> it = iterable.getJournalEntryIterator(); LOG.info("Write journal entry checkpoint"); while (it.hasNext()) { if (Thread.interrupted()) { throw new InterruptedException(); } it.next().writeDelimitedTo(output); } output.flush(); }
[ "public", "static", "void", "writeJournalEntryCheckpoint", "(", "OutputStream", "output", ",", "JournalEntryIterable", "iterable", ")", "throws", "IOException", ",", "InterruptedException", "{", "output", "=", "new", "CheckpointOutputStream", "(", "output", ",", "CheckpointType", ".", "JOURNAL_ENTRY", ")", ";", "Iterator", "<", "JournalEntry", ">", "it", "=", "iterable", ".", "getJournalEntryIterator", "(", ")", ";", "LOG", ".", "info", "(", "\"Write journal entry checkpoint\"", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "if", "(", "Thread", ".", "interrupted", "(", ")", ")", "{", "throw", "new", "InterruptedException", "(", ")", ";", "}", "it", ".", "next", "(", ")", ".", "writeDelimitedTo", "(", "output", ")", ";", "}", "output", ".", "flush", "(", ")", ";", "}" ]
Writes a checkpoint of the entries in the given iterable. This is the complement of {@link #restoreJournalEntryCheckpoint(CheckpointInputStream, Journaled)}. @param output the stream to write to @param iterable the iterable for fetching journal entries
[ "Writes", "a", "checkpoint", "of", "the", "entries", "in", "the", "given", "iterable", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java#L74-L86
18,816
Alluxio/alluxio
core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java
JournalUtils.restoreJournalEntryCheckpoint
public static void restoreJournalEntryCheckpoint(CheckpointInputStream input, Journaled journaled) throws IOException { Preconditions.checkState(input.getType() == CheckpointType.JOURNAL_ENTRY, "Unrecognized checkpoint type when restoring %s: %s", journaled.getCheckpointName(), input.getType()); journaled.resetState(); LOG.info("Reading journal entries"); JournalEntryStreamReader reader = new JournalEntryStreamReader(input); JournalEntry entry; while ((entry = reader.readEntry()) != null) { try { journaled.processJournalEntry(entry); } catch (Throwable t) { handleJournalReplayFailure(LOG, t, "Failed to process journal entry %s from a journal checkpoint", entry); } } }
java
public static void restoreJournalEntryCheckpoint(CheckpointInputStream input, Journaled journaled) throws IOException { Preconditions.checkState(input.getType() == CheckpointType.JOURNAL_ENTRY, "Unrecognized checkpoint type when restoring %s: %s", journaled.getCheckpointName(), input.getType()); journaled.resetState(); LOG.info("Reading journal entries"); JournalEntryStreamReader reader = new JournalEntryStreamReader(input); JournalEntry entry; while ((entry = reader.readEntry()) != null) { try { journaled.processJournalEntry(entry); } catch (Throwable t) { handleJournalReplayFailure(LOG, t, "Failed to process journal entry %s from a journal checkpoint", entry); } } }
[ "public", "static", "void", "restoreJournalEntryCheckpoint", "(", "CheckpointInputStream", "input", ",", "Journaled", "journaled", ")", "throws", "IOException", "{", "Preconditions", ".", "checkState", "(", "input", ".", "getType", "(", ")", "==", "CheckpointType", ".", "JOURNAL_ENTRY", ",", "\"Unrecognized checkpoint type when restoring %s: %s\"", ",", "journaled", ".", "getCheckpointName", "(", ")", ",", "input", ".", "getType", "(", ")", ")", ";", "journaled", ".", "resetState", "(", ")", ";", "LOG", ".", "info", "(", "\"Reading journal entries\"", ")", ";", "JournalEntryStreamReader", "reader", "=", "new", "JournalEntryStreamReader", "(", "input", ")", ";", "JournalEntry", "entry", ";", "while", "(", "(", "entry", "=", "reader", ".", "readEntry", "(", ")", ")", "!=", "null", ")", "{", "try", "{", "journaled", ".", "processJournalEntry", "(", "entry", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "handleJournalReplayFailure", "(", "LOG", ",", "t", ",", "\"Failed to process journal entry %s from a journal checkpoint\"", ",", "entry", ")", ";", "}", "}", "}" ]
Restores the given journaled object from the journal entries in the input stream. This is the complement of {@link #writeJournalEntryCheckpoint(OutputStream, JournalEntryIterable)}. @param input the stream to read from @param journaled the object to restore
[ "Restores", "the", "given", "journaled", "object", "from", "the", "journal", "entries", "in", "the", "input", "stream", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java#L97-L114
18,817
Alluxio/alluxio
core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java
JournalUtils.writeToCheckpoint
public static void writeToCheckpoint(OutputStream output, List<? extends Checkpointed> components) throws IOException, InterruptedException { OutputChunked chunked = new OutputChunked( new CheckpointOutputStream(output, CheckpointType.COMPOUND), 64 * Constants.KB); for (Checkpointed component : components) { chunked.writeString(component.getCheckpointName().toString()); component.writeToCheckpoint(chunked); chunked.endChunks(); } chunked.flush(); }
java
public static void writeToCheckpoint(OutputStream output, List<? extends Checkpointed> components) throws IOException, InterruptedException { OutputChunked chunked = new OutputChunked( new CheckpointOutputStream(output, CheckpointType.COMPOUND), 64 * Constants.KB); for (Checkpointed component : components) { chunked.writeString(component.getCheckpointName().toString()); component.writeToCheckpoint(chunked); chunked.endChunks(); } chunked.flush(); }
[ "public", "static", "void", "writeToCheckpoint", "(", "OutputStream", "output", ",", "List", "<", "?", "extends", "Checkpointed", ">", "components", ")", "throws", "IOException", ",", "InterruptedException", "{", "OutputChunked", "chunked", "=", "new", "OutputChunked", "(", "new", "CheckpointOutputStream", "(", "output", ",", "CheckpointType", ".", "COMPOUND", ")", ",", "64", "*", "Constants", ".", "KB", ")", ";", "for", "(", "Checkpointed", "component", ":", "components", ")", "{", "chunked", ".", "writeString", "(", "component", ".", "getCheckpointName", "(", ")", ".", "toString", "(", ")", ")", ";", "component", ".", "writeToCheckpoint", "(", "chunked", ")", ";", "chunked", ".", "endChunks", "(", ")", ";", "}", "chunked", ".", "flush", "(", ")", ";", "}" ]
Writes a composite checkpoint for the given checkpointed components. This is the complement of {@link #restoreFromCheckpoint(CheckpointInputStream, List)}. @param output the stream to write to @param components the components to checkpoint
[ "Writes", "a", "composite", "checkpoint", "for", "the", "given", "checkpointed", "components", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java#L124-L134
18,818
Alluxio/alluxio
core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java
JournalUtils.restoreFromCheckpoint
public static void restoreFromCheckpoint(CheckpointInputStream input, List<? extends Checkpointed> components) throws IOException { CompoundCheckpointReader reader = new CompoundCheckpointReader(input); Optional<Entry> next; while ((next = reader.nextCheckpoint()).isPresent()) { Entry nextEntry = next.get(); boolean found = false; for (Checkpointed component : components) { if (component.getCheckpointName().equals(nextEntry.getName())) { component.restoreFromCheckpoint(nextEntry.getStream()); found = true; break; } } if (!found) { throw new RuntimeException(String.format( "Unrecognized checkpoint name: %s. Existing components: %s", nextEntry.getName(), Arrays .toString(StreamUtils.map(Checkpointed::getCheckpointName, components).toArray()))); } } }
java
public static void restoreFromCheckpoint(CheckpointInputStream input, List<? extends Checkpointed> components) throws IOException { CompoundCheckpointReader reader = new CompoundCheckpointReader(input); Optional<Entry> next; while ((next = reader.nextCheckpoint()).isPresent()) { Entry nextEntry = next.get(); boolean found = false; for (Checkpointed component : components) { if (component.getCheckpointName().equals(nextEntry.getName())) { component.restoreFromCheckpoint(nextEntry.getStream()); found = true; break; } } if (!found) { throw new RuntimeException(String.format( "Unrecognized checkpoint name: %s. Existing components: %s", nextEntry.getName(), Arrays .toString(StreamUtils.map(Checkpointed::getCheckpointName, components).toArray()))); } } }
[ "public", "static", "void", "restoreFromCheckpoint", "(", "CheckpointInputStream", "input", ",", "List", "<", "?", "extends", "Checkpointed", ">", "components", ")", "throws", "IOException", "{", "CompoundCheckpointReader", "reader", "=", "new", "CompoundCheckpointReader", "(", "input", ")", ";", "Optional", "<", "Entry", ">", "next", ";", "while", "(", "(", "next", "=", "reader", ".", "nextCheckpoint", "(", ")", ")", ".", "isPresent", "(", ")", ")", "{", "Entry", "nextEntry", "=", "next", ".", "get", "(", ")", ";", "boolean", "found", "=", "false", ";", "for", "(", "Checkpointed", "component", ":", "components", ")", "{", "if", "(", "component", ".", "getCheckpointName", "(", ")", ".", "equals", "(", "nextEntry", ".", "getName", "(", ")", ")", ")", "{", "component", ".", "restoreFromCheckpoint", "(", "nextEntry", ".", "getStream", "(", ")", ")", ";", "found", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "found", ")", "{", "throw", "new", "RuntimeException", "(", "String", ".", "format", "(", "\"Unrecognized checkpoint name: %s. Existing components: %s\"", ",", "nextEntry", ".", "getName", "(", ")", ",", "Arrays", ".", "toString", "(", "StreamUtils", ".", "map", "(", "Checkpointed", "::", "getCheckpointName", ",", "components", ")", ".", "toArray", "(", ")", ")", ")", ")", ";", "}", "}", "}" ]
Restores the given checkpointed components from a composite checkpoint. This is the complement of {@link #writeToCheckpoint(OutputStream, List)}. @param input the stream to read from @param components the components to restore
[ "Restores", "the", "given", "checkpointed", "components", "from", "a", "composite", "checkpoint", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/master/journal/JournalUtils.java#L144-L164
18,819
Alluxio/alluxio
shell/src/main/java/alluxio/cli/fsadmin/report/MetricsCommand.java
MetricsCommand.printMetric
private void printMetric(String metricName, String nickName, boolean valueIsBytes) { if (mMetricsMap == null || !mMetricsMap.containsKey(metricName)) { return; } MetricValue metricValue = mMetricsMap.get(metricName); String formattedValue = valueIsBytes ? FormatUtils.getSizeFromBytes(metricValue.getLongValue()) : getFormattedValue(metricValue); mPrintStream.println(INDENT + String.format(mInfoFormat, nickName == null ? metricName : nickName, formattedValue)); mMetricsMap.remove(metricName); }
java
private void printMetric(String metricName, String nickName, boolean valueIsBytes) { if (mMetricsMap == null || !mMetricsMap.containsKey(metricName)) { return; } MetricValue metricValue = mMetricsMap.get(metricName); String formattedValue = valueIsBytes ? FormatUtils.getSizeFromBytes(metricValue.getLongValue()) : getFormattedValue(metricValue); mPrintStream.println(INDENT + String.format(mInfoFormat, nickName == null ? metricName : nickName, formattedValue)); mMetricsMap.remove(metricName); }
[ "private", "void", "printMetric", "(", "String", "metricName", ",", "String", "nickName", ",", "boolean", "valueIsBytes", ")", "{", "if", "(", "mMetricsMap", "==", "null", "||", "!", "mMetricsMap", ".", "containsKey", "(", "metricName", ")", ")", "{", "return", ";", "}", "MetricValue", "metricValue", "=", "mMetricsMap", ".", "get", "(", "metricName", ")", ";", "String", "formattedValue", "=", "valueIsBytes", "?", "FormatUtils", ".", "getSizeFromBytes", "(", "metricValue", ".", "getLongValue", "(", ")", ")", ":", "getFormattedValue", "(", "metricValue", ")", ";", "mPrintStream", ".", "println", "(", "INDENT", "+", "String", ".", "format", "(", "mInfoFormat", ",", "nickName", "==", "null", "?", "metricName", ":", "nickName", ",", "formattedValue", ")", ")", ";", "mMetricsMap", ".", "remove", "(", "metricName", ")", ";", "}" ]
Prints the metrics information. @param metricName the metric name to get a metric value @param nickName the metric name to print @param valueIsBytes whether the metric value is bytes
[ "Prints", "the", "metrics", "information", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/shell/src/main/java/alluxio/cli/fsadmin/report/MetricsCommand.java#L160-L170
18,820
Alluxio/alluxio
shell/src/main/java/alluxio/cli/fsadmin/report/MetricsCommand.java
MetricsCommand.getFormattedValue
private String getFormattedValue(MetricValue metricValue) { if (metricValue.hasDoubleValue()) { return DECIMAL_FORMAT.format(metricValue.getDoubleValue()); } else { return DECIMAL_FORMAT.format(metricValue.getLongValue()); } }
java
private String getFormattedValue(MetricValue metricValue) { if (metricValue.hasDoubleValue()) { return DECIMAL_FORMAT.format(metricValue.getDoubleValue()); } else { return DECIMAL_FORMAT.format(metricValue.getLongValue()); } }
[ "private", "String", "getFormattedValue", "(", "MetricValue", "metricValue", ")", "{", "if", "(", "metricValue", ".", "hasDoubleValue", "(", ")", ")", "{", "return", "DECIMAL_FORMAT", ".", "format", "(", "metricValue", ".", "getDoubleValue", "(", ")", ")", ";", "}", "else", "{", "return", "DECIMAL_FORMAT", ".", "format", "(", "metricValue", ".", "getLongValue", "(", ")", ")", ";", "}", "}" ]
Gets the formatted metric value. @param metricValue the metricValue to transform @return the formatted metric value
[ "Gets", "the", "formatted", "metric", "value", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/shell/src/main/java/alluxio/cli/fsadmin/report/MetricsCommand.java#L178-L184
18,821
Alluxio/alluxio
core/server/worker/src/main/java/alluxio/Sessions.java
Sessions.getTimedOutSessions
public List<Long> getTimedOutSessions() { List<Long> ret = new ArrayList<>(); synchronized (mSessions) { for (Entry<Long, SessionInfo> entry : mSessions.entrySet()) { if (entry.getValue().timeout()) { ret.add(entry.getKey()); } } } return ret; }
java
public List<Long> getTimedOutSessions() { List<Long> ret = new ArrayList<>(); synchronized (mSessions) { for (Entry<Long, SessionInfo> entry : mSessions.entrySet()) { if (entry.getValue().timeout()) { ret.add(entry.getKey()); } } } return ret; }
[ "public", "List", "<", "Long", ">", "getTimedOutSessions", "(", ")", "{", "List", "<", "Long", ">", "ret", "=", "new", "ArrayList", "<>", "(", ")", ";", "synchronized", "(", "mSessions", ")", "{", "for", "(", "Entry", "<", "Long", ",", "SessionInfo", ">", "entry", ":", "mSessions", ".", "entrySet", "(", ")", ")", "{", "if", "(", "entry", ".", "getValue", "(", ")", ".", "timeout", "(", ")", ")", "{", "ret", ".", "add", "(", "entry", ".", "getKey", "(", ")", ")", ";", "}", "}", "}", "return", "ret", ";", "}" ]
Gets the sessions that timed out. @return the list of session ids of sessions that timed out
[ "Gets", "the", "sessions", "that", "timed", "out", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/worker/src/main/java/alluxio/Sessions.java#L61-L71
18,822
Alluxio/alluxio
core/server/worker/src/main/java/alluxio/Sessions.java
Sessions.sessionHeartbeat
public void sessionHeartbeat(long sessionId) { synchronized (mSessions) { if (mSessions.containsKey(sessionId)) { mSessions.get(sessionId).heartbeat(); } else { int sessionTimeoutMs = (int) ServerConfiguration .getMs(PropertyKey.WORKER_SESSION_TIMEOUT_MS); mSessions.put(sessionId, new SessionInfo(sessionId, sessionTimeoutMs)); } } }
java
public void sessionHeartbeat(long sessionId) { synchronized (mSessions) { if (mSessions.containsKey(sessionId)) { mSessions.get(sessionId).heartbeat(); } else { int sessionTimeoutMs = (int) ServerConfiguration .getMs(PropertyKey.WORKER_SESSION_TIMEOUT_MS); mSessions.put(sessionId, new SessionInfo(sessionId, sessionTimeoutMs)); } } }
[ "public", "void", "sessionHeartbeat", "(", "long", "sessionId", ")", "{", "synchronized", "(", "mSessions", ")", "{", "if", "(", "mSessions", ".", "containsKey", "(", "sessionId", ")", ")", "{", "mSessions", ".", "get", "(", "sessionId", ")", ".", "heartbeat", "(", ")", ";", "}", "else", "{", "int", "sessionTimeoutMs", "=", "(", "int", ")", "ServerConfiguration", ".", "getMs", "(", "PropertyKey", ".", "WORKER_SESSION_TIMEOUT_MS", ")", ";", "mSessions", ".", "put", "(", "sessionId", ",", "new", "SessionInfo", "(", "sessionId", ",", "sessionTimeoutMs", ")", ")", ";", "}", "}", "}" ]
Performs session heartbeat. @param sessionId the id of the session
[ "Performs", "session", "heartbeat", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/worker/src/main/java/alluxio/Sessions.java#L90-L100
18,823
Alluxio/alluxio
core/common/src/main/java/alluxio/conf/InstancedConfiguration.java
InstancedConfiguration.lookupRecursively
private String lookupRecursively(String base, Set<String> seen) throws UnresolvablePropertyException { // check argument if (base == null) { throw new UnresolvablePropertyException("Can't resolve property with null value"); } String resolved = base; // Lets find pattern match to ${key}. // TODO(hsaputra): Consider using Apache Commons StrSubstitutor. Matcher matcher = CONF_REGEX.matcher(base); while (matcher.find()) { String match = matcher.group(2).trim(); if (!seen.add(match)) { throw new RuntimeException(ExceptionMessage.KEY_CIRCULAR_DEPENDENCY.getMessage(match)); } if (!PropertyKey.isValid(match)) { throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(match)); } String value = lookupRecursively(mProperties.get(PropertyKey.fromString(match)), seen); seen.remove(match); if (value == null) { throw new UnresolvablePropertyException(ExceptionMessage .UNDEFINED_CONFIGURATION_KEY.getMessage(match)); } LOG.debug("Replacing {} with {}", matcher.group(1), value); resolved = resolved.replaceFirst(REGEX_STRING, Matcher.quoteReplacement(value)); } return resolved; }
java
private String lookupRecursively(String base, Set<String> seen) throws UnresolvablePropertyException { // check argument if (base == null) { throw new UnresolvablePropertyException("Can't resolve property with null value"); } String resolved = base; // Lets find pattern match to ${key}. // TODO(hsaputra): Consider using Apache Commons StrSubstitutor. Matcher matcher = CONF_REGEX.matcher(base); while (matcher.find()) { String match = matcher.group(2).trim(); if (!seen.add(match)) { throw new RuntimeException(ExceptionMessage.KEY_CIRCULAR_DEPENDENCY.getMessage(match)); } if (!PropertyKey.isValid(match)) { throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(match)); } String value = lookupRecursively(mProperties.get(PropertyKey.fromString(match)), seen); seen.remove(match); if (value == null) { throw new UnresolvablePropertyException(ExceptionMessage .UNDEFINED_CONFIGURATION_KEY.getMessage(match)); } LOG.debug("Replacing {} with {}", matcher.group(1), value); resolved = resolved.replaceFirst(REGEX_STRING, Matcher.quoteReplacement(value)); } return resolved; }
[ "private", "String", "lookupRecursively", "(", "String", "base", ",", "Set", "<", "String", ">", "seen", ")", "throws", "UnresolvablePropertyException", "{", "// check argument", "if", "(", "base", "==", "null", ")", "{", "throw", "new", "UnresolvablePropertyException", "(", "\"Can't resolve property with null value\"", ")", ";", "}", "String", "resolved", "=", "base", ";", "// Lets find pattern match to ${key}.", "// TODO(hsaputra): Consider using Apache Commons StrSubstitutor.", "Matcher", "matcher", "=", "CONF_REGEX", ".", "matcher", "(", "base", ")", ";", "while", "(", "matcher", ".", "find", "(", ")", ")", "{", "String", "match", "=", "matcher", ".", "group", "(", "2", ")", ".", "trim", "(", ")", ";", "if", "(", "!", "seen", ".", "add", "(", "match", ")", ")", "{", "throw", "new", "RuntimeException", "(", "ExceptionMessage", ".", "KEY_CIRCULAR_DEPENDENCY", ".", "getMessage", "(", "match", ")", ")", ";", "}", "if", "(", "!", "PropertyKey", ".", "isValid", "(", "match", ")", ")", "{", "throw", "new", "RuntimeException", "(", "ExceptionMessage", ".", "INVALID_CONFIGURATION_KEY", ".", "getMessage", "(", "match", ")", ")", ";", "}", "String", "value", "=", "lookupRecursively", "(", "mProperties", ".", "get", "(", "PropertyKey", ".", "fromString", "(", "match", ")", ")", ",", "seen", ")", ";", "seen", ".", "remove", "(", "match", ")", ";", "if", "(", "value", "==", "null", ")", "{", "throw", "new", "UnresolvablePropertyException", "(", "ExceptionMessage", ".", "UNDEFINED_CONFIGURATION_KEY", ".", "getMessage", "(", "match", ")", ")", ";", "}", "LOG", ".", "debug", "(", "\"Replacing {} with {}\"", ",", "matcher", ".", "group", "(", "1", ")", ",", "value", ")", ";", "resolved", "=", "resolved", ".", "replaceFirst", "(", "REGEX_STRING", ",", "Matcher", ".", "quoteReplacement", "(", "value", ")", ")", ";", "}", "return", "resolved", ";", "}" ]
Actual recursive lookup replacement. @param base the string to resolve @param seen strings already seen during this lookup, used to prevent unbound recursion @return the resolved string
[ "Actual", "recursive", "lookup", "replacement", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/conf/InstancedConfiguration.java#L387-L416
18,824
Alluxio/alluxio
core/common/src/main/java/alluxio/conf/InstancedConfiguration.java
InstancedConfiguration.checkWorkerPorts
private void checkWorkerPorts() { int maxWorkersPerHost = getInt(PropertyKey.INTEGRATION_YARN_WORKERS_PER_HOST_MAX); if (maxWorkersPerHost > 1) { String message = "%s cannot be specified when allowing multiple workers per host with " + PropertyKey.Name.INTEGRATION_YARN_WORKERS_PER_HOST_MAX + "=" + maxWorkersPerHost; Preconditions.checkState(System.getProperty(PropertyKey.Name.WORKER_RPC_PORT) == null, String.format(message, PropertyKey.WORKER_RPC_PORT)); Preconditions.checkState(System.getProperty(PropertyKey.Name.WORKER_WEB_PORT) == null, String.format(message, PropertyKey.WORKER_WEB_PORT)); } }
java
private void checkWorkerPorts() { int maxWorkersPerHost = getInt(PropertyKey.INTEGRATION_YARN_WORKERS_PER_HOST_MAX); if (maxWorkersPerHost > 1) { String message = "%s cannot be specified when allowing multiple workers per host with " + PropertyKey.Name.INTEGRATION_YARN_WORKERS_PER_HOST_MAX + "=" + maxWorkersPerHost; Preconditions.checkState(System.getProperty(PropertyKey.Name.WORKER_RPC_PORT) == null, String.format(message, PropertyKey.WORKER_RPC_PORT)); Preconditions.checkState(System.getProperty(PropertyKey.Name.WORKER_WEB_PORT) == null, String.format(message, PropertyKey.WORKER_WEB_PORT)); } }
[ "private", "void", "checkWorkerPorts", "(", ")", "{", "int", "maxWorkersPerHost", "=", "getInt", "(", "PropertyKey", ".", "INTEGRATION_YARN_WORKERS_PER_HOST_MAX", ")", ";", "if", "(", "maxWorkersPerHost", ">", "1", ")", "{", "String", "message", "=", "\"%s cannot be specified when allowing multiple workers per host with \"", "+", "PropertyKey", ".", "Name", ".", "INTEGRATION_YARN_WORKERS_PER_HOST_MAX", "+", "\"=\"", "+", "maxWorkersPerHost", ";", "Preconditions", ".", "checkState", "(", "System", ".", "getProperty", "(", "PropertyKey", ".", "Name", ".", "WORKER_RPC_PORT", ")", "==", "null", ",", "String", ".", "format", "(", "message", ",", "PropertyKey", ".", "WORKER_RPC_PORT", ")", ")", ";", "Preconditions", ".", "checkState", "(", "System", ".", "getProperty", "(", "PropertyKey", ".", "Name", ".", "WORKER_WEB_PORT", ")", "==", "null", ",", "String", ".", "format", "(", "message", ",", "PropertyKey", ".", "WORKER_WEB_PORT", ")", ")", ";", "}", "}" ]
Validates worker port configuration. @throws IllegalStateException if invalid worker port configuration is encountered
[ "Validates", "worker", "port", "configuration", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/conf/InstancedConfiguration.java#L423-L433
18,825
Alluxio/alluxio
core/common/src/main/java/alluxio/conf/InstancedConfiguration.java
InstancedConfiguration.checkTimeouts
private void checkTimeouts() { long waitTime = getMs(PropertyKey.MASTER_WORKER_CONNECT_WAIT_TIME); long retryInterval = getMs(PropertyKey.USER_RPC_RETRY_MAX_SLEEP_MS); if (waitTime < retryInterval) { LOG.warn("{}={}ms is smaller than {}={}ms. Workers might not have enough time to register. " + "Consider either increasing {} or decreasing {}", PropertyKey.Name.MASTER_WORKER_CONNECT_WAIT_TIME, waitTime, PropertyKey.Name.USER_RPC_RETRY_MAX_SLEEP_MS, retryInterval, PropertyKey.Name.MASTER_WORKER_CONNECT_WAIT_TIME, PropertyKey.Name.USER_RPC_RETRY_MAX_SLEEP_MS); } checkHeartbeatTimeout(PropertyKey.MASTER_MASTER_HEARTBEAT_INTERVAL, PropertyKey.MASTER_HEARTBEAT_TIMEOUT); // Skip checking block worker heartbeat config because the timeout is master-side while the // heartbeat interval is worker-side. }
java
private void checkTimeouts() { long waitTime = getMs(PropertyKey.MASTER_WORKER_CONNECT_WAIT_TIME); long retryInterval = getMs(PropertyKey.USER_RPC_RETRY_MAX_SLEEP_MS); if (waitTime < retryInterval) { LOG.warn("{}={}ms is smaller than {}={}ms. Workers might not have enough time to register. " + "Consider either increasing {} or decreasing {}", PropertyKey.Name.MASTER_WORKER_CONNECT_WAIT_TIME, waitTime, PropertyKey.Name.USER_RPC_RETRY_MAX_SLEEP_MS, retryInterval, PropertyKey.Name.MASTER_WORKER_CONNECT_WAIT_TIME, PropertyKey.Name.USER_RPC_RETRY_MAX_SLEEP_MS); } checkHeartbeatTimeout(PropertyKey.MASTER_MASTER_HEARTBEAT_INTERVAL, PropertyKey.MASTER_HEARTBEAT_TIMEOUT); // Skip checking block worker heartbeat config because the timeout is master-side while the // heartbeat interval is worker-side. }
[ "private", "void", "checkTimeouts", "(", ")", "{", "long", "waitTime", "=", "getMs", "(", "PropertyKey", ".", "MASTER_WORKER_CONNECT_WAIT_TIME", ")", ";", "long", "retryInterval", "=", "getMs", "(", "PropertyKey", ".", "USER_RPC_RETRY_MAX_SLEEP_MS", ")", ";", "if", "(", "waitTime", "<", "retryInterval", ")", "{", "LOG", ".", "warn", "(", "\"{}={}ms is smaller than {}={}ms. Workers might not have enough time to register. \"", "+", "\"Consider either increasing {} or decreasing {}\"", ",", "PropertyKey", ".", "Name", ".", "MASTER_WORKER_CONNECT_WAIT_TIME", ",", "waitTime", ",", "PropertyKey", ".", "Name", ".", "USER_RPC_RETRY_MAX_SLEEP_MS", ",", "retryInterval", ",", "PropertyKey", ".", "Name", ".", "MASTER_WORKER_CONNECT_WAIT_TIME", ",", "PropertyKey", ".", "Name", ".", "USER_RPC_RETRY_MAX_SLEEP_MS", ")", ";", "}", "checkHeartbeatTimeout", "(", "PropertyKey", ".", "MASTER_MASTER_HEARTBEAT_INTERVAL", ",", "PropertyKey", ".", "MASTER_HEARTBEAT_TIMEOUT", ")", ";", "// Skip checking block worker heartbeat config because the timeout is master-side while the", "// heartbeat interval is worker-side.", "}" ]
Validates timeout related configuration.
[ "Validates", "timeout", "related", "configuration", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/conf/InstancedConfiguration.java#L438-L453
18,826
Alluxio/alluxio
core/common/src/main/java/alluxio/conf/InstancedConfiguration.java
InstancedConfiguration.checkHeartbeatTimeout
private void checkHeartbeatTimeout(PropertyKey intervalKey, PropertyKey timeoutKey) { long interval = getMs(intervalKey); long timeout = getMs(timeoutKey); Preconditions.checkState(interval < timeout, "heartbeat interval (%s=%s) must be less than heartbeat timeout (%s=%s)", intervalKey, interval, timeoutKey, timeout); }
java
private void checkHeartbeatTimeout(PropertyKey intervalKey, PropertyKey timeoutKey) { long interval = getMs(intervalKey); long timeout = getMs(timeoutKey); Preconditions.checkState(interval < timeout, "heartbeat interval (%s=%s) must be less than heartbeat timeout (%s=%s)", intervalKey, interval, timeoutKey, timeout); }
[ "private", "void", "checkHeartbeatTimeout", "(", "PropertyKey", "intervalKey", ",", "PropertyKey", "timeoutKey", ")", "{", "long", "interval", "=", "getMs", "(", "intervalKey", ")", ";", "long", "timeout", "=", "getMs", "(", "timeoutKey", ")", ";", "Preconditions", ".", "checkState", "(", "interval", "<", "timeout", ",", "\"heartbeat interval (%s=%s) must be less than heartbeat timeout (%s=%s)\"", ",", "intervalKey", ",", "interval", ",", "timeoutKey", ",", "timeout", ")", ";", "}" ]
Checks that the interval is shorter than the timeout. @param intervalKey property key for an interval @param timeoutKey property key for a timeout
[ "Checks", "that", "the", "interval", "is", "shorter", "than", "the", "timeout", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/conf/InstancedConfiguration.java#L461-L467
18,827
Alluxio/alluxio
core/common/src/main/java/alluxio/conf/InstancedConfiguration.java
InstancedConfiguration.checkUserFileBufferBytes
private void checkUserFileBufferBytes() { if (!isSet(PropertyKey.USER_FILE_BUFFER_BYTES)) { // load from hadoop conf return; } long usrFileBufferBytes = getBytes(PropertyKey.USER_FILE_BUFFER_BYTES); Preconditions.checkState((usrFileBufferBytes & Integer.MAX_VALUE) == usrFileBufferBytes, PreconditionMessage.INVALID_USER_FILE_BUFFER_BYTES.toString(), PropertyKey.Name.USER_FILE_BUFFER_BYTES, usrFileBufferBytes); }
java
private void checkUserFileBufferBytes() { if (!isSet(PropertyKey.USER_FILE_BUFFER_BYTES)) { // load from hadoop conf return; } long usrFileBufferBytes = getBytes(PropertyKey.USER_FILE_BUFFER_BYTES); Preconditions.checkState((usrFileBufferBytes & Integer.MAX_VALUE) == usrFileBufferBytes, PreconditionMessage.INVALID_USER_FILE_BUFFER_BYTES.toString(), PropertyKey.Name.USER_FILE_BUFFER_BYTES, usrFileBufferBytes); }
[ "private", "void", "checkUserFileBufferBytes", "(", ")", "{", "if", "(", "!", "isSet", "(", "PropertyKey", ".", "USER_FILE_BUFFER_BYTES", ")", ")", "{", "// load from hadoop conf", "return", ";", "}", "long", "usrFileBufferBytes", "=", "getBytes", "(", "PropertyKey", ".", "USER_FILE_BUFFER_BYTES", ")", ";", "Preconditions", ".", "checkState", "(", "(", "usrFileBufferBytes", "&", "Integer", ".", "MAX_VALUE", ")", "==", "usrFileBufferBytes", ",", "PreconditionMessage", ".", "INVALID_USER_FILE_BUFFER_BYTES", ".", "toString", "(", ")", ",", "PropertyKey", ".", "Name", ".", "USER_FILE_BUFFER_BYTES", ",", "usrFileBufferBytes", ")", ";", "}" ]
Validates the user file buffer size is a non-negative number. @throws IllegalStateException if invalid user file buffer size configuration is encountered
[ "Validates", "the", "user", "file", "buffer", "size", "is", "a", "non", "-", "negative", "number", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/conf/InstancedConfiguration.java#L474-L482
18,828
Alluxio/alluxio
core/common/src/main/java/alluxio/conf/InstancedConfiguration.java
InstancedConfiguration.checkZkConfiguration
private void checkZkConfiguration() { Preconditions.checkState( isSet(PropertyKey.ZOOKEEPER_ADDRESS) == getBoolean(PropertyKey.ZOOKEEPER_ENABLED), PreconditionMessage.INCONSISTENT_ZK_CONFIGURATION.toString(), PropertyKey.Name.ZOOKEEPER_ADDRESS, PropertyKey.Name.ZOOKEEPER_ENABLED); }
java
private void checkZkConfiguration() { Preconditions.checkState( isSet(PropertyKey.ZOOKEEPER_ADDRESS) == getBoolean(PropertyKey.ZOOKEEPER_ENABLED), PreconditionMessage.INCONSISTENT_ZK_CONFIGURATION.toString(), PropertyKey.Name.ZOOKEEPER_ADDRESS, PropertyKey.Name.ZOOKEEPER_ENABLED); }
[ "private", "void", "checkZkConfiguration", "(", ")", "{", "Preconditions", ".", "checkState", "(", "isSet", "(", "PropertyKey", ".", "ZOOKEEPER_ADDRESS", ")", "==", "getBoolean", "(", "PropertyKey", ".", "ZOOKEEPER_ENABLED", ")", ",", "PreconditionMessage", ".", "INCONSISTENT_ZK_CONFIGURATION", ".", "toString", "(", ")", ",", "PropertyKey", ".", "Name", ".", "ZOOKEEPER_ADDRESS", ",", "PropertyKey", ".", "Name", ".", "ZOOKEEPER_ENABLED", ")", ";", "}" ]
Validates Zookeeper-related configuration and prints warnings for possible sources of error. @throws IllegalStateException if invalid Zookeeper configuration is encountered
[ "Validates", "Zookeeper", "-", "related", "configuration", "and", "prints", "warnings", "for", "possible", "sources", "of", "error", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/conf/InstancedConfiguration.java#L489-L494
18,829
Alluxio/alluxio
core/common/src/main/java/alluxio/conf/InstancedConfiguration.java
InstancedConfiguration.checkTieredLocality
private void checkTieredLocality() { // Check that any custom tiers set by alluxio.locality.{custom_tier}=value are also defined in // the tier ordering defined by alluxio.locality.order. Set<String> tiers = Sets.newHashSet(getList(PropertyKey.LOCALITY_ORDER, ",")); Set<PropertyKey> predefinedKeys = new HashSet<>(PropertyKey.defaultKeys()); for (PropertyKey key : mProperties.keySet()) { if (predefinedKeys.contains(key)) { // Skip non-templated keys. continue; } Matcher matcher = Template.LOCALITY_TIER.match(key.toString()); if (matcher.matches() && matcher.group(1) != null) { String tierName = matcher.group(1); if (!tiers.contains(tierName)) { throw new IllegalStateException( String.format("Tier %s is configured by %s, but does not exist in the tier list %s " + "configured by %s", tierName, key, tiers, PropertyKey.LOCALITY_ORDER)); } } } }
java
private void checkTieredLocality() { // Check that any custom tiers set by alluxio.locality.{custom_tier}=value are also defined in // the tier ordering defined by alluxio.locality.order. Set<String> tiers = Sets.newHashSet(getList(PropertyKey.LOCALITY_ORDER, ",")); Set<PropertyKey> predefinedKeys = new HashSet<>(PropertyKey.defaultKeys()); for (PropertyKey key : mProperties.keySet()) { if (predefinedKeys.contains(key)) { // Skip non-templated keys. continue; } Matcher matcher = Template.LOCALITY_TIER.match(key.toString()); if (matcher.matches() && matcher.group(1) != null) { String tierName = matcher.group(1); if (!tiers.contains(tierName)) { throw new IllegalStateException( String.format("Tier %s is configured by %s, but does not exist in the tier list %s " + "configured by %s", tierName, key, tiers, PropertyKey.LOCALITY_ORDER)); } } } }
[ "private", "void", "checkTieredLocality", "(", ")", "{", "// Check that any custom tiers set by alluxio.locality.{custom_tier}=value are also defined in", "// the tier ordering defined by alluxio.locality.order.", "Set", "<", "String", ">", "tiers", "=", "Sets", ".", "newHashSet", "(", "getList", "(", "PropertyKey", ".", "LOCALITY_ORDER", ",", "\",\"", ")", ")", ";", "Set", "<", "PropertyKey", ">", "predefinedKeys", "=", "new", "HashSet", "<>", "(", "PropertyKey", ".", "defaultKeys", "(", ")", ")", ";", "for", "(", "PropertyKey", "key", ":", "mProperties", ".", "keySet", "(", ")", ")", "{", "if", "(", "predefinedKeys", ".", "contains", "(", "key", ")", ")", "{", "// Skip non-templated keys.", "continue", ";", "}", "Matcher", "matcher", "=", "Template", ".", "LOCALITY_TIER", ".", "match", "(", "key", ".", "toString", "(", ")", ")", ";", "if", "(", "matcher", ".", "matches", "(", ")", "&&", "matcher", ".", "group", "(", "1", ")", "!=", "null", ")", "{", "String", "tierName", "=", "matcher", ".", "group", "(", "1", ")", ";", "if", "(", "!", "tiers", ".", "contains", "(", "tierName", ")", ")", "{", "throw", "new", "IllegalStateException", "(", "String", ".", "format", "(", "\"Tier %s is configured by %s, but does not exist in the tier list %s \"", "+", "\"configured by %s\"", ",", "tierName", ",", "key", ",", "tiers", ",", "PropertyKey", ".", "LOCALITY_ORDER", ")", ")", ";", "}", "}", "}", "}" ]
Checks that tiered locality configuration is consistent. @throws IllegalStateException if invalid tiered locality configuration is encountered
[ "Checks", "that", "tiered", "locality", "configuration", "is", "consistent", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/conf/InstancedConfiguration.java#L501-L521
18,830
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.changeLocalFileGroup
public static void changeLocalFileGroup(String path, String group) throws IOException { UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); PosixFileAttributeView view = Files.getFileAttributeView(Paths.get(path), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group); view.setGroup(groupPrincipal); }
java
public static void changeLocalFileGroup(String path, String group) throws IOException { UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); PosixFileAttributeView view = Files.getFileAttributeView(Paths.get(path), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group); view.setGroup(groupPrincipal); }
[ "public", "static", "void", "changeLocalFileGroup", "(", "String", "path", ",", "String", "group", ")", "throws", "IOException", "{", "UserPrincipalLookupService", "lookupService", "=", "FileSystems", ".", "getDefault", "(", ")", ".", "getUserPrincipalLookupService", "(", ")", ";", "PosixFileAttributeView", "view", "=", "Files", ".", "getFileAttributeView", "(", "Paths", ".", "get", "(", "path", ")", ",", "PosixFileAttributeView", ".", "class", ",", "LinkOption", ".", "NOFOLLOW_LINKS", ")", ";", "GroupPrincipal", "groupPrincipal", "=", "lookupService", ".", "lookupPrincipalByGroupName", "(", "group", ")", ";", "view", ".", "setGroup", "(", "groupPrincipal", ")", ";", "}" ]
Changes the local file's group. @param path that will change owner @param group the new group
[ "Changes", "the", "local", "file", "s", "group", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L57-L65
18,831
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.changeLocalFilePermission
public static void changeLocalFilePermission(String filePath, String perms) throws IOException { Files.setPosixFilePermissions(Paths.get(filePath), PosixFilePermissions.fromString(perms)); }
java
public static void changeLocalFilePermission(String filePath, String perms) throws IOException { Files.setPosixFilePermissions(Paths.get(filePath), PosixFilePermissions.fromString(perms)); }
[ "public", "static", "void", "changeLocalFilePermission", "(", "String", "filePath", ",", "String", "perms", ")", "throws", "IOException", "{", "Files", ".", "setPosixFilePermissions", "(", "Paths", ".", "get", "(", "filePath", ")", ",", "PosixFilePermissions", ".", "fromString", "(", "perms", ")", ")", ";", "}" ]
Changes local file's permission. @param filePath that will change permission @param perms the permission, e.g. "rwxr--r--"
[ "Changes", "local", "file", "s", "permission", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L73-L75
18,832
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.getLocalFileOwner
public static String getLocalFileOwner(String filePath) throws IOException { PosixFileAttributes attr = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class); return attr.owner().getName(); }
java
public static String getLocalFileOwner(String filePath) throws IOException { PosixFileAttributes attr = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class); return attr.owner().getName(); }
[ "public", "static", "String", "getLocalFileOwner", "(", "String", "filePath", ")", "throws", "IOException", "{", "PosixFileAttributes", "attr", "=", "Files", ".", "readAttributes", "(", "Paths", ".", "get", "(", "filePath", ")", ",", "PosixFileAttributes", ".", "class", ")", ";", "return", "attr", ".", "owner", "(", ")", ".", "getName", "(", ")", ";", "}" ]
Gets local file's owner. @param filePath the file path @return the owner of the local file
[ "Gets", "local", "file", "s", "owner", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L92-L96
18,833
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.getLocalFileGroup
public static String getLocalFileGroup(String filePath) throws IOException { PosixFileAttributes attr = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class); return attr.group().getName(); }
java
public static String getLocalFileGroup(String filePath) throws IOException { PosixFileAttributes attr = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class); return attr.group().getName(); }
[ "public", "static", "String", "getLocalFileGroup", "(", "String", "filePath", ")", "throws", "IOException", "{", "PosixFileAttributes", "attr", "=", "Files", ".", "readAttributes", "(", "Paths", ".", "get", "(", "filePath", ")", ",", "PosixFileAttributes", ".", "class", ")", ";", "return", "attr", ".", "group", "(", ")", ".", "getName", "(", ")", ";", "}" ]
Gets local file's group. @param filePath the file path @return the group of the local file
[ "Gets", "local", "file", "s", "group", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L104-L108
18,834
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.getLocalFileMode
public static short getLocalFileMode(String filePath) throws IOException { Set<PosixFilePermission> permission = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class).permissions(); return translatePosixPermissionToMode(permission); }
java
public static short getLocalFileMode(String filePath) throws IOException { Set<PosixFilePermission> permission = Files.readAttributes(Paths.get(filePath), PosixFileAttributes.class).permissions(); return translatePosixPermissionToMode(permission); }
[ "public", "static", "short", "getLocalFileMode", "(", "String", "filePath", ")", "throws", "IOException", "{", "Set", "<", "PosixFilePermission", ">", "permission", "=", "Files", ".", "readAttributes", "(", "Paths", ".", "get", "(", "filePath", ")", ",", "PosixFileAttributes", ".", "class", ")", ".", "permissions", "(", ")", ";", "return", "translatePosixPermissionToMode", "(", "permission", ")", ";", "}" ]
Gets local file's permission mode. @param filePath the file path @return the file mode in short, e.g. 0777
[ "Gets", "local", "file", "s", "permission", "mode", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L116-L120
18,835
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.translatePosixPermissionToMode
public static short translatePosixPermissionToMode(Set<PosixFilePermission> permission) { int mode = 0; for (PosixFilePermission action : PosixFilePermission.values()) { mode = mode << 1; mode += permission.contains(action) ? 1 : 0; } return (short) mode; }
java
public static short translatePosixPermissionToMode(Set<PosixFilePermission> permission) { int mode = 0; for (PosixFilePermission action : PosixFilePermission.values()) { mode = mode << 1; mode += permission.contains(action) ? 1 : 0; } return (short) mode; }
[ "public", "static", "short", "translatePosixPermissionToMode", "(", "Set", "<", "PosixFilePermission", ">", "permission", ")", "{", "int", "mode", "=", "0", ";", "for", "(", "PosixFilePermission", "action", ":", "PosixFilePermission", ".", "values", "(", ")", ")", "{", "mode", "=", "mode", "<<", "1", ";", "mode", "+=", "permission", ".", "contains", "(", "action", ")", "?", "1", ":", "0", ";", "}", "return", "(", "short", ")", "mode", ";", "}" ]
Translate posix file permissions to short mode. @param permission posix file permission @return mode for file
[ "Translate", "posix", "file", "permissions", "to", "short", "mode", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L128-L135
18,836
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.changeLocalFileUser
public static void changeLocalFileUser(String path, String user) throws IOException { UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); PosixFileAttributeView view = Files.getFileAttributeView(Paths.get(path), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(user); view.setOwner(userPrincipal); }
java
public static void changeLocalFileUser(String path, String user) throws IOException { UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); PosixFileAttributeView view = Files.getFileAttributeView(Paths.get(path), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(user); view.setOwner(userPrincipal); }
[ "public", "static", "void", "changeLocalFileUser", "(", "String", "path", ",", "String", "user", ")", "throws", "IOException", "{", "UserPrincipalLookupService", "lookupService", "=", "FileSystems", ".", "getDefault", "(", ")", ".", "getUserPrincipalLookupService", "(", ")", ";", "PosixFileAttributeView", "view", "=", "Files", ".", "getFileAttributeView", "(", "Paths", ".", "get", "(", "path", ")", ",", "PosixFileAttributeView", ".", "class", ",", "LinkOption", ".", "NOFOLLOW_LINKS", ")", ";", "UserPrincipal", "userPrincipal", "=", "lookupService", ".", "lookupPrincipalByName", "(", "user", ")", ";", "view", ".", "setOwner", "(", "userPrincipal", ")", ";", "}" ]
Changes the local file's user. @param path that will change owner @param user the new user
[ "Changes", "the", "local", "file", "s", "user", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L143-L151
18,837
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.createBlockPath
public static void createBlockPath(String path, String workerDataFolderPermissions) throws IOException { try { createStorageDirPath(PathUtils.getParent(path), workerDataFolderPermissions); } catch (InvalidPathException e) { throw new IOException("Failed to create block path, get parent path of " + path + "failed", e); } catch (IOException e) { throw new IOException("Failed to create block path " + path, e); } }
java
public static void createBlockPath(String path, String workerDataFolderPermissions) throws IOException { try { createStorageDirPath(PathUtils.getParent(path), workerDataFolderPermissions); } catch (InvalidPathException e) { throw new IOException("Failed to create block path, get parent path of " + path + "failed", e); } catch (IOException e) { throw new IOException("Failed to create block path " + path, e); } }
[ "public", "static", "void", "createBlockPath", "(", "String", "path", ",", "String", "workerDataFolderPermissions", ")", "throws", "IOException", "{", "try", "{", "createStorageDirPath", "(", "PathUtils", ".", "getParent", "(", "path", ")", ",", "workerDataFolderPermissions", ")", ";", "}", "catch", "(", "InvalidPathException", "e", ")", "{", "throw", "new", "IOException", "(", "\"Failed to create block path, get parent path of \"", "+", "path", "+", "\"failed\"", ",", "e", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "IOException", "(", "\"Failed to create block path \"", "+", "path", ",", "e", ")", ";", "}", "}" ]
Creates the local block path and all the parent directories. Also, sets the appropriate permissions. @param path the path of the block @param workerDataFolderPermissions The permissions to set on the worker's data folder
[ "Creates", "the", "local", "block", "path", "and", "all", "the", "parent", "directories", ".", "Also", "sets", "the", "appropriate", "permissions", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L187-L197
18,838
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.delete
public static void delete(String path) throws IOException { if (!Files.deleteIfExists(Paths.get(path))) { throw new IOException("Failed to delete " + path); } }
java
public static void delete(String path) throws IOException { if (!Files.deleteIfExists(Paths.get(path))) { throw new IOException("Failed to delete " + path); } }
[ "public", "static", "void", "delete", "(", "String", "path", ")", "throws", "IOException", "{", "if", "(", "!", "Files", ".", "deleteIfExists", "(", "Paths", ".", "get", "(", "path", ")", ")", ")", "{", "throw", "new", "IOException", "(", "\"Failed to delete \"", "+", "path", ")", ";", "}", "}" ]
Deletes the file or directory. @param path pathname string of file or directory
[ "Deletes", "the", "file", "or", "directory", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L215-L219
18,839
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.deletePathRecursively
public static void deletePathRecursively(String path) throws IOException { if (!exists(path)) { return; } Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); }
java
public static void deletePathRecursively(String path) throws IOException { if (!exists(path)) { return; } Path root = Paths.get(path); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; } } }); }
[ "public", "static", "void", "deletePathRecursively", "(", "String", "path", ")", "throws", "IOException", "{", "if", "(", "!", "exists", "(", "path", ")", ")", "{", "return", ";", "}", "Path", "root", "=", "Paths", ".", "get", "(", "path", ")", ";", "Files", ".", "walkFileTree", "(", "root", ",", "new", "SimpleFileVisitor", "<", "Path", ">", "(", ")", "{", "@", "Override", "public", "FileVisitResult", "visitFile", "(", "Path", "file", ",", "BasicFileAttributes", "attrs", ")", "throws", "IOException", "{", "Files", ".", "delete", "(", "file", ")", ";", "return", "FileVisitResult", ".", "CONTINUE", ";", "}", "@", "Override", "public", "FileVisitResult", "postVisitDirectory", "(", "Path", "dir", ",", "IOException", "e", ")", "throws", "IOException", "{", "if", "(", "e", "==", "null", ")", "{", "Files", ".", "delete", "(", "dir", ")", ";", "return", "FileVisitResult", ".", "CONTINUE", ";", "}", "else", "{", "throw", "e", ";", "}", "}", "}", ")", ";", "}" ]
Deletes a file or a directory, recursively if it is a directory. If the path does not exist, nothing happens. @param path pathname to be deleted
[ "Deletes", "a", "file", "or", "a", "directory", "recursively", "if", "it", "is", "a", "directory", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L228-L250
18,840
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.createStorageDirPath
public static boolean createStorageDirPath(String path, String workerDataFolderPermissions) throws IOException { if (Files.exists(Paths.get(path))) { return false; } Path storagePath; try { storagePath = Files.createDirectories(Paths.get(path)); } catch (UnsupportedOperationException | SecurityException | IOException e) { throw new IOException("Failed to create folder " + path, e); } String absolutePath = storagePath.toAbsolutePath().toString(); changeLocalFilePermission(absolutePath, workerDataFolderPermissions); setLocalDirStickyBit(absolutePath); return true; }
java
public static boolean createStorageDirPath(String path, String workerDataFolderPermissions) throws IOException { if (Files.exists(Paths.get(path))) { return false; } Path storagePath; try { storagePath = Files.createDirectories(Paths.get(path)); } catch (UnsupportedOperationException | SecurityException | IOException e) { throw new IOException("Failed to create folder " + path, e); } String absolutePath = storagePath.toAbsolutePath().toString(); changeLocalFilePermission(absolutePath, workerDataFolderPermissions); setLocalDirStickyBit(absolutePath); return true; }
[ "public", "static", "boolean", "createStorageDirPath", "(", "String", "path", ",", "String", "workerDataFolderPermissions", ")", "throws", "IOException", "{", "if", "(", "Files", ".", "exists", "(", "Paths", ".", "get", "(", "path", ")", ")", ")", "{", "return", "false", ";", "}", "Path", "storagePath", ";", "try", "{", "storagePath", "=", "Files", ".", "createDirectories", "(", "Paths", ".", "get", "(", "path", ")", ")", ";", "}", "catch", "(", "UnsupportedOperationException", "|", "SecurityException", "|", "IOException", "e", ")", "{", "throw", "new", "IOException", "(", "\"Failed to create folder \"", "+", "path", ",", "e", ")", ";", "}", "String", "absolutePath", "=", "storagePath", ".", "toAbsolutePath", "(", ")", ".", "toString", "(", ")", ";", "changeLocalFilePermission", "(", "absolutePath", ",", "workerDataFolderPermissions", ")", ";", "setLocalDirStickyBit", "(", "absolutePath", ")", ";", "return", "true", ";", "}" ]
Creates the storage directory path, including any necessary but nonexistent parent directories. If the directory already exists, do nothing. Also, appropriate directory permissions (w/ StickyBit) are set. @param path storage directory path to create @param workerDataFolderPermissions the permissions to set for the worker's data folder @return true if the directory is created and false if the directory already exists
[ "Creates", "the", "storage", "directory", "path", "including", "any", "necessary", "but", "nonexistent", "parent", "directories", ".", "If", "the", "directory", "already", "exists", "do", "nothing", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L262-L277
18,841
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.createFile
public static void createFile(String filePath) throws IOException { Path storagePath = Paths.get(filePath); Files.createDirectories(storagePath.getParent()); Files.createFile(storagePath); }
java
public static void createFile(String filePath) throws IOException { Path storagePath = Paths.get(filePath); Files.createDirectories(storagePath.getParent()); Files.createFile(storagePath); }
[ "public", "static", "void", "createFile", "(", "String", "filePath", ")", "throws", "IOException", "{", "Path", "storagePath", "=", "Paths", ".", "get", "(", "filePath", ")", ";", "Files", ".", "createDirectories", "(", "storagePath", ".", "getParent", "(", ")", ")", ";", "Files", ".", "createFile", "(", "storagePath", ")", ";", "}" ]
Creates an empty file and its intermediate directories if necessary. @param filePath pathname string of the file to create
[ "Creates", "an", "empty", "file", "and", "its", "intermediate", "directories", "if", "necessary", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L284-L288
18,842
Alluxio/alluxio
core/common/src/main/java/alluxio/util/io/FileUtils.java
FileUtils.isStorageDirAccessible
public static boolean isStorageDirAccessible(String path) { Path filePath = Paths.get(path); return Files.exists(filePath) && Files.isReadable(filePath) && Files.isWritable(filePath) && Files.isExecutable(filePath); }
java
public static boolean isStorageDirAccessible(String path) { Path filePath = Paths.get(path); return Files.exists(filePath) && Files.isReadable(filePath) && Files.isWritable(filePath) && Files.isExecutable(filePath); }
[ "public", "static", "boolean", "isStorageDirAccessible", "(", "String", "path", ")", "{", "Path", "filePath", "=", "Paths", ".", "get", "(", "path", ")", ";", "return", "Files", ".", "exists", "(", "filePath", ")", "&&", "Files", ".", "isReadable", "(", "filePath", ")", "&&", "Files", ".", "isWritable", "(", "filePath", ")", "&&", "Files", ".", "isExecutable", "(", "filePath", ")", ";", "}" ]
Checks if a storage directory path is accessible. @param path the given path @return true if path exists, false otherwise
[ "Checks", "if", "a", "storage", "directory", "path", "is", "accessible", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/util/io/FileUtils.java#L315-L321
18,843
Alluxio/alluxio
core/server/common/src/main/java/alluxio/master/BackupManager.java
BackupManager.backup
public void backup(OutputStream os) throws IOException { int count = 0; GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(os); for (Master master : mRegistry.getServers()) { Iterator<JournalEntry> it = master.getJournalEntryIterator(); while (it.hasNext()) { it.next().toBuilder().clearSequenceNumber().build().writeDelimitedTo(zipStream); count++; } } // finish() instead of close() since close would close os, which is owned by the caller. zipStream.finish(); LOG.info("Created backup with {} entries", count); }
java
public void backup(OutputStream os) throws IOException { int count = 0; GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(os); for (Master master : mRegistry.getServers()) { Iterator<JournalEntry> it = master.getJournalEntryIterator(); while (it.hasNext()) { it.next().toBuilder().clearSequenceNumber().build().writeDelimitedTo(zipStream); count++; } } // finish() instead of close() since close would close os, which is owned by the caller. zipStream.finish(); LOG.info("Created backup with {} entries", count); }
[ "public", "void", "backup", "(", "OutputStream", "os", ")", "throws", "IOException", "{", "int", "count", "=", "0", ";", "GzipCompressorOutputStream", "zipStream", "=", "new", "GzipCompressorOutputStream", "(", "os", ")", ";", "for", "(", "Master", "master", ":", "mRegistry", ".", "getServers", "(", ")", ")", "{", "Iterator", "<", "JournalEntry", ">", "it", "=", "master", ".", "getJournalEntryIterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "it", ".", "next", "(", ")", ".", "toBuilder", "(", ")", ".", "clearSequenceNumber", "(", ")", ".", "build", "(", ")", ".", "writeDelimitedTo", "(", "zipStream", ")", ";", "count", "++", ";", "}", "}", "// finish() instead of close() since close would close os, which is owned by the caller.", "zipStream", ".", "finish", "(", ")", ";", "LOG", ".", "info", "(", "\"Created backup with {} entries\"", ",", "count", ")", ";", "}" ]
Writes a backup to the specified stream. @param os the stream to write to
[ "Writes", "a", "backup", "to", "the", "specified", "stream", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/master/BackupManager.java#L65-L78
18,844
Alluxio/alluxio
core/server/common/src/main/java/alluxio/master/BackupManager.java
BackupManager.initFromBackup
public void initFromBackup(InputStream is) throws IOException { int count = 0; try (GzipCompressorInputStream gzIn = new GzipCompressorInputStream(is); JournalEntryStreamReader reader = new JournalEntryStreamReader(gzIn)) { List<Master> masters = mRegistry.getServers(); JournalEntry entry; Map<String, Master> mastersByName = Maps.uniqueIndex(masters, Master::getName); while ((entry = reader.readEntry()) != null) { String masterName = JournalEntryAssociation.getMasterForEntry(entry); Master master = mastersByName.get(masterName); try { master.processJournalEntry(entry); } catch (Throwable t) { JournalUtils.handleJournalReplayFailure( LOG, t, "Failed to process journal entry %s when init from backup", entry); } try (JournalContext jc = master.createJournalContext()) { jc.append(entry); count++; } } } LOG.info("Restored {} entries from backup", count); }
java
public void initFromBackup(InputStream is) throws IOException { int count = 0; try (GzipCompressorInputStream gzIn = new GzipCompressorInputStream(is); JournalEntryStreamReader reader = new JournalEntryStreamReader(gzIn)) { List<Master> masters = mRegistry.getServers(); JournalEntry entry; Map<String, Master> mastersByName = Maps.uniqueIndex(masters, Master::getName); while ((entry = reader.readEntry()) != null) { String masterName = JournalEntryAssociation.getMasterForEntry(entry); Master master = mastersByName.get(masterName); try { master.processJournalEntry(entry); } catch (Throwable t) { JournalUtils.handleJournalReplayFailure( LOG, t, "Failed to process journal entry %s when init from backup", entry); } try (JournalContext jc = master.createJournalContext()) { jc.append(entry); count++; } } } LOG.info("Restored {} entries from backup", count); }
[ "public", "void", "initFromBackup", "(", "InputStream", "is", ")", "throws", "IOException", "{", "int", "count", "=", "0", ";", "try", "(", "GzipCompressorInputStream", "gzIn", "=", "new", "GzipCompressorInputStream", "(", "is", ")", ";", "JournalEntryStreamReader", "reader", "=", "new", "JournalEntryStreamReader", "(", "gzIn", ")", ")", "{", "List", "<", "Master", ">", "masters", "=", "mRegistry", ".", "getServers", "(", ")", ";", "JournalEntry", "entry", ";", "Map", "<", "String", ",", "Master", ">", "mastersByName", "=", "Maps", ".", "uniqueIndex", "(", "masters", ",", "Master", "::", "getName", ")", ";", "while", "(", "(", "entry", "=", "reader", ".", "readEntry", "(", ")", ")", "!=", "null", ")", "{", "String", "masterName", "=", "JournalEntryAssociation", ".", "getMasterForEntry", "(", "entry", ")", ";", "Master", "master", "=", "mastersByName", ".", "get", "(", "masterName", ")", ";", "try", "{", "master", ".", "processJournalEntry", "(", "entry", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "JournalUtils", ".", "handleJournalReplayFailure", "(", "LOG", ",", "t", ",", "\"Failed to process journal entry %s when init from backup\"", ",", "entry", ")", ";", "}", "try", "(", "JournalContext", "jc", "=", "master", ".", "createJournalContext", "(", ")", ")", "{", "jc", ".", "append", "(", "entry", ")", ";", "count", "++", ";", "}", "}", "}", "LOG", ".", "info", "(", "\"Restored {} entries from backup\"", ",", "count", ")", ";", "}" ]
Restores master state from the specified backup. @param is an input stream to read from the backup
[ "Restores", "master", "state", "from", "the", "specified", "backup", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/master/BackupManager.java#L85-L108
18,845
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java
Cache.get
public Optional<V> get(K key) { if (cacheIsFull()) { Entry entry = mMap.get(key); if (entry == null) { return load(key); } return Optional.ofNullable(entry.mValue); } Entry result = mMap.compute(key, (k, entry) -> { if (entry != null) { entry.mReferenced = true; return entry; } Optional<V> value = load(key); if (value.isPresent()) { onCacheUpdate(key, value.get()); Entry newEntry = new Entry(key, value.get()); newEntry.mDirty = false; return newEntry; } return null; }); if (result == null || result.mValue == null) { return Optional.empty(); } wakeEvictionThreadIfNecessary(); return Optional.of(result.mValue); }
java
public Optional<V> get(K key) { if (cacheIsFull()) { Entry entry = mMap.get(key); if (entry == null) { return load(key); } return Optional.ofNullable(entry.mValue); } Entry result = mMap.compute(key, (k, entry) -> { if (entry != null) { entry.mReferenced = true; return entry; } Optional<V> value = load(key); if (value.isPresent()) { onCacheUpdate(key, value.get()); Entry newEntry = new Entry(key, value.get()); newEntry.mDirty = false; return newEntry; } return null; }); if (result == null || result.mValue == null) { return Optional.empty(); } wakeEvictionThreadIfNecessary(); return Optional.of(result.mValue); }
[ "public", "Optional", "<", "V", ">", "get", "(", "K", "key", ")", "{", "if", "(", "cacheIsFull", "(", ")", ")", "{", "Entry", "entry", "=", "mMap", ".", "get", "(", "key", ")", ";", "if", "(", "entry", "==", "null", ")", "{", "return", "load", "(", "key", ")", ";", "}", "return", "Optional", ".", "ofNullable", "(", "entry", ".", "mValue", ")", ";", "}", "Entry", "result", "=", "mMap", ".", "compute", "(", "key", ",", "(", "k", ",", "entry", ")", "->", "{", "if", "(", "entry", "!=", "null", ")", "{", "entry", ".", "mReferenced", "=", "true", ";", "return", "entry", ";", "}", "Optional", "<", "V", ">", "value", "=", "load", "(", "key", ")", ";", "if", "(", "value", ".", "isPresent", "(", ")", ")", "{", "onCacheUpdate", "(", "key", ",", "value", ".", "get", "(", ")", ")", ";", "Entry", "newEntry", "=", "new", "Entry", "(", "key", ",", "value", ".", "get", "(", ")", ")", ";", "newEntry", ".", "mDirty", "=", "false", ";", "return", "newEntry", ";", "}", "return", "null", ";", "}", ")", ";", "if", "(", "result", "==", "null", "||", "result", ".", "mValue", "==", "null", ")", "{", "return", "Optional", ".", "empty", "(", ")", ";", "}", "wakeEvictionThreadIfNecessary", "(", ")", ";", "return", "Optional", ".", "of", "(", "result", ".", "mValue", ")", ";", "}" ]
Retrieves a value from the cache, loading it from the backing store if necessary. If the value needs to be loaded, concurrent calls to get(key) will block while waiting for the first call to finish loading the value. @param key the key to get the value for @return the value, or empty if the key doesn't exist in the cache or in the backing store
[ "Retrieves", "a", "value", "from", "the", "cache", "loading", "it", "from", "the", "backing", "store", "if", "necessary", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java#L100-L127
18,846
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java
Cache.remove
public void remove(K key) { // Set the entry so that it will be removed from the backing store when it is encountered by // the eviction thread. mMap.compute(key, (k, entry) -> { onRemove(key); if (entry == null && cacheIsFull()) { removeFromBackingStore(k); return null; } onCacheUpdate(key, null); if (entry == null) { entry = new Entry(key, null); } else { entry.mValue = null; } entry.mReferenced = false; entry.mDirty = true; return entry; }); wakeEvictionThreadIfNecessary(); }
java
public void remove(K key) { // Set the entry so that it will be removed from the backing store when it is encountered by // the eviction thread. mMap.compute(key, (k, entry) -> { onRemove(key); if (entry == null && cacheIsFull()) { removeFromBackingStore(k); return null; } onCacheUpdate(key, null); if (entry == null) { entry = new Entry(key, null); } else { entry.mValue = null; } entry.mReferenced = false; entry.mDirty = true; return entry; }); wakeEvictionThreadIfNecessary(); }
[ "public", "void", "remove", "(", "K", "key", ")", "{", "// Set the entry so that it will be removed from the backing store when it is encountered by", "// the eviction thread.", "mMap", ".", "compute", "(", "key", ",", "(", "k", ",", "entry", ")", "->", "{", "onRemove", "(", "key", ")", ";", "if", "(", "entry", "==", "null", "&&", "cacheIsFull", "(", ")", ")", "{", "removeFromBackingStore", "(", "k", ")", ";", "return", "null", ";", "}", "onCacheUpdate", "(", "key", ",", "null", ")", ";", "if", "(", "entry", "==", "null", ")", "{", "entry", "=", "new", "Entry", "(", "key", ",", "null", ")", ";", "}", "else", "{", "entry", ".", "mValue", "=", "null", ";", "}", "entry", ".", "mReferenced", "=", "false", ";", "entry", ".", "mDirty", "=", "true", ";", "return", "entry", ";", "}", ")", ";", "wakeEvictionThreadIfNecessary", "(", ")", ";", "}" ]
Removes a key from the cache. The key is not immediately removed from the backing store. Instead, we set the entry's value to null to indicate to the eviction thread that to evict the entry, it must first remove the key from the backing store. However, if the cache is full we must synchronously write to the backing store instead. @param key the key to remove
[ "Removes", "a", "key", "from", "the", "cache", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java#L164-L184
18,847
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java
Cache.flush
public void flush() throws InterruptedException { List<Entry> toFlush = new ArrayList<>(mEvictBatchSize); Iterator<Entry> it = mMap.values().iterator(); while (it.hasNext()) { if (Thread.interrupted()) { throw new InterruptedException(); } while (toFlush.size() < mEvictBatchSize && it.hasNext()) { Entry candidate = it.next(); if (candidate.mDirty) { toFlush.add(candidate); } } flushEntries(toFlush); toFlush.clear(); } }
java
public void flush() throws InterruptedException { List<Entry> toFlush = new ArrayList<>(mEvictBatchSize); Iterator<Entry> it = mMap.values().iterator(); while (it.hasNext()) { if (Thread.interrupted()) { throw new InterruptedException(); } while (toFlush.size() < mEvictBatchSize && it.hasNext()) { Entry candidate = it.next(); if (candidate.mDirty) { toFlush.add(candidate); } } flushEntries(toFlush); toFlush.clear(); } }
[ "public", "void", "flush", "(", ")", "throws", "InterruptedException", "{", "List", "<", "Entry", ">", "toFlush", "=", "new", "ArrayList", "<>", "(", "mEvictBatchSize", ")", ";", "Iterator", "<", "Entry", ">", "it", "=", "mMap", ".", "values", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "it", ".", "hasNext", "(", ")", ")", "{", "if", "(", "Thread", ".", "interrupted", "(", ")", ")", "{", "throw", "new", "InterruptedException", "(", ")", ";", "}", "while", "(", "toFlush", ".", "size", "(", ")", "<", "mEvictBatchSize", "&&", "it", ".", "hasNext", "(", ")", ")", "{", "Entry", "candidate", "=", "it", ".", "next", "(", ")", ";", "if", "(", "candidate", ".", "mDirty", ")", "{", "toFlush", ".", "add", "(", "candidate", ")", ";", "}", "}", "flushEntries", "(", "toFlush", ")", ";", "toFlush", ".", "clear", "(", ")", ";", "}", "}" ]
Flushes all data to the backing store.
[ "Flushes", "all", "data", "to", "the", "backing", "store", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java#L189-L205
18,848
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java
Cache.clear
public void clear() { mMap.forEach((key, value) -> { onCacheUpdate(key, value.mValue); onRemove(key); }); mMap.clear(); }
java
public void clear() { mMap.forEach((key, value) -> { onCacheUpdate(key, value.mValue); onRemove(key); }); mMap.clear(); }
[ "public", "void", "clear", "(", ")", "{", "mMap", ".", "forEach", "(", "(", "key", ",", "value", ")", "->", "{", "onCacheUpdate", "(", "key", ",", "value", ".", "mValue", ")", ";", "onRemove", "(", "key", ")", ";", "}", ")", ";", "mMap", ".", "clear", "(", ")", ";", "}" ]
Clears all entries from the map. This is not threadsafe, and requires external synchronization to prevent concurrent modifications to the cache.
[ "Clears", "all", "entries", "from", "the", "map", ".", "This", "is", "not", "threadsafe", "and", "requires", "external", "synchronization", "to", "prevent", "concurrent", "modifications", "to", "the", "cache", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metastore/caching/Cache.java#L211-L217
18,849
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java
LockedInodePath.removeLastInode
public void removeLastInode() { Preconditions.checkState(fullPathExists()); if (!isImplicitlyLocked()) { // WRITE_EDGE pattern always implicitly locks the list when the full path exists, so the lock // list must end with an inode. mLockList.unlockLastInode(); mLockList.unlockLastEdge(); } mExistingInodes.remove(mExistingInodes.size() - 1); }
java
public void removeLastInode() { Preconditions.checkState(fullPathExists()); if (!isImplicitlyLocked()) { // WRITE_EDGE pattern always implicitly locks the list when the full path exists, so the lock // list must end with an inode. mLockList.unlockLastInode(); mLockList.unlockLastEdge(); } mExistingInodes.remove(mExistingInodes.size() - 1); }
[ "public", "void", "removeLastInode", "(", ")", "{", "Preconditions", ".", "checkState", "(", "fullPathExists", "(", ")", ")", ";", "if", "(", "!", "isImplicitlyLocked", "(", ")", ")", "{", "// WRITE_EDGE pattern always implicitly locks the list when the full path exists, so the lock", "// list must end with an inode.", "mLockList", ".", "unlockLastInode", "(", ")", ";", "mLockList", ".", "unlockLastEdge", "(", ")", ";", "}", "mExistingInodes", ".", "remove", "(", "mExistingInodes", ".", "size", "(", ")", "-", "1", ")", ";", "}" ]
Removes the last inode from the list. This is necessary when the last inode is deleted and we want to continue using the inodepath. This operation is only supported when the path is complete.
[ "Removes", "the", "last", "inode", "from", "the", "list", ".", "This", "is", "necessary", "when", "the", "last", "inode", "is", "deleted", "and", "we", "want", "to", "continue", "using", "the", "inodepath", ".", "This", "operation", "is", "only", "supported", "when", "the", "path", "is", "complete", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java#L256-L266
18,850
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java
LockedInodePath.addNextInode
public void addNextInode(Inode inode) { Preconditions.checkState(mLockPattern == LockPattern.WRITE_EDGE); Preconditions.checkState(!fullPathExists()); Preconditions.checkState(inode.getName().equals(mPathComponents[mExistingInodes.size()])); if (!isImplicitlyLocked() && mExistingInodes.size() < mPathComponents.length - 1) { mLockList.pushWriteLockedEdge(inode, mPathComponents[mExistingInodes.size() + 1]); } mExistingInodes.add(inode); }
java
public void addNextInode(Inode inode) { Preconditions.checkState(mLockPattern == LockPattern.WRITE_EDGE); Preconditions.checkState(!fullPathExists()); Preconditions.checkState(inode.getName().equals(mPathComponents[mExistingInodes.size()])); if (!isImplicitlyLocked() && mExistingInodes.size() < mPathComponents.length - 1) { mLockList.pushWriteLockedEdge(inode, mPathComponents[mExistingInodes.size() + 1]); } mExistingInodes.add(inode); }
[ "public", "void", "addNextInode", "(", "Inode", "inode", ")", "{", "Preconditions", ".", "checkState", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_EDGE", ")", ";", "Preconditions", ".", "checkState", "(", "!", "fullPathExists", "(", ")", ")", ";", "Preconditions", ".", "checkState", "(", "inode", ".", "getName", "(", ")", ".", "equals", "(", "mPathComponents", "[", "mExistingInodes", ".", "size", "(", ")", "]", ")", ")", ";", "if", "(", "!", "isImplicitlyLocked", "(", ")", "&&", "mExistingInodes", ".", "size", "(", ")", "<", "mPathComponents", ".", "length", "-", "1", ")", "{", "mLockList", ".", "pushWriteLockedEdge", "(", "inode", ",", "mPathComponents", "[", "mExistingInodes", ".", "size", "(", ")", "+", "1", "]", ")", ";", "}", "mExistingInodes", ".", "add", "(", "inode", ")", ";", "}" ]
Adds the next inode to the path. This tries to reduce the scope of locking by moving the write lock forward to the new final edge, downgrading the previous write lock to a read lock. If the path is implicitly locked, the inode is added but no downgrade occurs. @param inode the inode to add
[ "Adds", "the", "next", "inode", "to", "the", "path", ".", "This", "tries", "to", "reduce", "the", "scope", "of", "locking", "by", "moving", "the", "write", "lock", "forward", "to", "the", "new", "final", "edge", "downgrading", "the", "previous", "write", "lock", "to", "a", "read", "lock", ".", "If", "the", "path", "is", "implicitly", "locked", "the", "inode", "is", "added", "but", "no", "downgrade", "occurs", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java#L275-L284
18,851
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java
LockedInodePath.downgradeToPattern
public void downgradeToPattern(LockPattern desiredLockPattern) { switch (desiredLockPattern) { case READ: if (mLockPattern == LockPattern.WRITE_INODE) { Preconditions.checkState(!isImplicitlyLocked()); mLockList.downgradeLastInode(); } else if (mLockPattern == LockPattern.WRITE_EDGE) { downgradeEdgeToInode(LockMode.READ); } break; case WRITE_INODE: if (mLockPattern == LockPattern.WRITE_EDGE) { downgradeEdgeToInode(LockMode.WRITE); } else { Preconditions.checkState(mLockPattern == LockPattern.WRITE_INODE); } break; case WRITE_EDGE: Preconditions.checkState(mLockPattern == LockPattern.WRITE_EDGE); break; // Nothing to do default: throw new IllegalStateException("Unknown lock pattern: " + desiredLockPattern); } mLockPattern = desiredLockPattern; }
java
public void downgradeToPattern(LockPattern desiredLockPattern) { switch (desiredLockPattern) { case READ: if (mLockPattern == LockPattern.WRITE_INODE) { Preconditions.checkState(!isImplicitlyLocked()); mLockList.downgradeLastInode(); } else if (mLockPattern == LockPattern.WRITE_EDGE) { downgradeEdgeToInode(LockMode.READ); } break; case WRITE_INODE: if (mLockPattern == LockPattern.WRITE_EDGE) { downgradeEdgeToInode(LockMode.WRITE); } else { Preconditions.checkState(mLockPattern == LockPattern.WRITE_INODE); } break; case WRITE_EDGE: Preconditions.checkState(mLockPattern == LockPattern.WRITE_EDGE); break; // Nothing to do default: throw new IllegalStateException("Unknown lock pattern: " + desiredLockPattern); } mLockPattern = desiredLockPattern; }
[ "public", "void", "downgradeToPattern", "(", "LockPattern", "desiredLockPattern", ")", "{", "switch", "(", "desiredLockPattern", ")", "{", "case", "READ", ":", "if", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_INODE", ")", "{", "Preconditions", ".", "checkState", "(", "!", "isImplicitlyLocked", "(", ")", ")", ";", "mLockList", ".", "downgradeLastInode", "(", ")", ";", "}", "else", "if", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_EDGE", ")", "{", "downgradeEdgeToInode", "(", "LockMode", ".", "READ", ")", ";", "}", "break", ";", "case", "WRITE_INODE", ":", "if", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_EDGE", ")", "{", "downgradeEdgeToInode", "(", "LockMode", ".", "WRITE", ")", ";", "}", "else", "{", "Preconditions", ".", "checkState", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_INODE", ")", ";", "}", "break", ";", "case", "WRITE_EDGE", ":", "Preconditions", ".", "checkState", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_EDGE", ")", ";", "break", ";", "// Nothing to do", "default", ":", "throw", "new", "IllegalStateException", "(", "\"Unknown lock pattern: \"", "+", "desiredLockPattern", ")", ";", "}", "mLockPattern", "=", "desiredLockPattern", ";", "}" ]
Downgrades from the current locking scheme to the desired locking scheme. @param desiredLockPattern the pattern to downgrade to
[ "Downgrades", "from", "the", "current", "locking", "scheme", "to", "the", "desired", "locking", "scheme", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java#L291-L315
18,852
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java
LockedInodePath.lockDescendant
public LockedInodePath lockDescendant(AlluxioURI descendantUri, LockPattern lockPattern) throws InvalidPathException { LockedInodePath path = new LockedInodePath(descendantUri, this, PathUtils.getPathComponents(descendantUri.getPath()), lockPattern); path.traverseOrClose(); return path; }
java
public LockedInodePath lockDescendant(AlluxioURI descendantUri, LockPattern lockPattern) throws InvalidPathException { LockedInodePath path = new LockedInodePath(descendantUri, this, PathUtils.getPathComponents(descendantUri.getPath()), lockPattern); path.traverseOrClose(); return path; }
[ "public", "LockedInodePath", "lockDescendant", "(", "AlluxioURI", "descendantUri", ",", "LockPattern", "lockPattern", ")", "throws", "InvalidPathException", "{", "LockedInodePath", "path", "=", "new", "LockedInodePath", "(", "descendantUri", ",", "this", ",", "PathUtils", ".", "getPathComponents", "(", "descendantUri", ".", "getPath", "(", ")", ")", ",", "lockPattern", ")", ";", "path", ".", "traverseOrClose", "(", ")", ";", "return", "path", ";", "}" ]
Locks a descendant of the current path and returns a new locked inode path. The path is traversed according to the lock pattern. Closing the new path will have no effect on the current path. On failure, all locks taken by this method will be released. @param descendantUri the full descendent uri starting from the root @param lockPattern the lock pattern to lock in @return the new locked path
[ "Locks", "a", "descendant", "of", "the", "current", "path", "and", "returns", "a", "new", "locked", "inode", "path", ".", "The", "path", "is", "traversed", "according", "to", "the", "lock", "pattern", ".", "Closing", "the", "new", "path", "will", "have", "no", "effect", "on", "the", "current", "path", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java#L360-L366
18,853
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java
LockedInodePath.lockChild
public LockedInodePath lockChild(Inode child, LockPattern lockPattern) throws InvalidPathException { return lockChild(child, lockPattern, addComponent(mPathComponents, child.getName())); }
java
public LockedInodePath lockChild(Inode child, LockPattern lockPattern) throws InvalidPathException { return lockChild(child, lockPattern, addComponent(mPathComponents, child.getName())); }
[ "public", "LockedInodePath", "lockChild", "(", "Inode", "child", ",", "LockPattern", "lockPattern", ")", "throws", "InvalidPathException", "{", "return", "lockChild", "(", "child", ",", "lockPattern", ",", "addComponent", "(", "mPathComponents", ",", "child", ".", "getName", "(", ")", ")", ")", ";", "}" ]
Returns a new locked inode path composed of the current path plus the child inode. The path is traversed according to the lock pattern. The original locked inode path is unaffected. childComponentsHint can be used to save the work of computing path components when the path components for the new path are already known. On failure, all locks taken by this method will be released. @param child the child inode @param lockPattern the lock pattern @return the new locked path
[ "Returns", "a", "new", "locked", "inode", "path", "composed", "of", "the", "current", "path", "plus", "the", "child", "inode", ".", "The", "path", "is", "traversed", "according", "to", "the", "lock", "pattern", ".", "The", "original", "locked", "inode", "path", "is", "unaffected", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java#L381-L384
18,854
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java
LockedInodePath.lockFinalEdgeWrite
public LockedInodePath lockFinalEdgeWrite() throws InvalidPathException { Preconditions.checkState(!fullPathExists()); LockedInodePath newPath = new LockedInodePath(mUri, this, mPathComponents, LockPattern.WRITE_EDGE); newPath.traverse(); return newPath; }
java
public LockedInodePath lockFinalEdgeWrite() throws InvalidPathException { Preconditions.checkState(!fullPathExists()); LockedInodePath newPath = new LockedInodePath(mUri, this, mPathComponents, LockPattern.WRITE_EDGE); newPath.traverse(); return newPath; }
[ "public", "LockedInodePath", "lockFinalEdgeWrite", "(", ")", "throws", "InvalidPathException", "{", "Preconditions", ".", "checkState", "(", "!", "fullPathExists", "(", ")", ")", ";", "LockedInodePath", "newPath", "=", "new", "LockedInodePath", "(", "mUri", ",", "this", ",", "mPathComponents", ",", "LockPattern", ".", "WRITE_EDGE", ")", ";", "newPath", ".", "traverse", "(", ")", ";", "return", "newPath", ";", "}" ]
Returns a copy of the path with the final edge write locked. This requires that we haven't already locked the final edge, i.e. the path is incomplete. @return the new locked path
[ "Returns", "a", "copy", "of", "the", "path", "with", "the", "final", "edge", "write", "locked", ".", "This", "requires", "that", "we", "haven", "t", "already", "locked", "the", "final", "edge", "i", ".", "e", ".", "the", "path", "is", "incomplete", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java#L416-L423
18,855
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java
LockedInodePath.traverse
public void traverse() throws InvalidPathException { if (mLockList.getLockMode() == LockMode.WRITE) { traverseWithoutLocking(); return; } // This locks the root edge and inode if necessary. bootstrapTraversal(); // Each iteration either locks a new inode/edge or hits a missing inode and returns. while (!fullPathExists()) { int lastInodeIndex = mLockList.getLockedInodes().size() - 1; String nextComponent = mPathComponents[lastInodeIndex + 1]; boolean isFinalComponent = lastInodeIndex == mPathComponents.length - 2; if (mLockList.endsInInode()) { // Lock an edge next. if (mLockPattern == LockPattern.WRITE_EDGE && isFinalComponent) { mLockList.lockEdge(nextComponent, LockMode.WRITE); } else { mLockList.lockEdge(nextComponent, LockMode.READ); } } else { // Lock an inode next. Inode lastInode = mLockList.getLockedInodes().get(lastInodeIndex); if (!lastInode.isDirectory()) { throw new InvalidPathException(String.format( "Traversal failed for path %s. Component %s(%s) is a file, not a directory.", mUri, lastInodeIndex, lastInode.getName())); } Optional<Inode> nextInodeOpt = mInodeStore.getChild(lastInode.asDirectory(), nextComponent); if (!nextInodeOpt.isPresent() && mLockPattern == LockPattern.WRITE_EDGE && !isFinalComponent) { // This pattern requires that we obtain a write lock on the final edge, so we must // upgrade to a write lock. mLockList.unlockLastEdge(); mLockList.lockEdge(nextComponent, LockMode.WRITE); nextInodeOpt = mInodeStore.getChild(lastInode.asDirectory(), nextComponent); if (nextInodeOpt.isPresent()) { // The component must have been created between releasing the read lock and acquiring // the write lock. Downgrade and continue as normal. mLockList.downgradeLastEdge(); } } if (!nextInodeOpt.isPresent()) { if (mLockPattern != LockPattern.WRITE_EDGE) { // Other lock patterns only lock up to the last existing inode. mLockList.unlockLastEdge(); } return; } Inode nextInode = nextInodeOpt.get(); if (isFinalComponent) { if (mLockPattern == LockPattern.READ) { mLockList.lockInode(nextInode, LockMode.READ); } else if (mLockPattern == LockPattern.WRITE_INODE) { mLockList.lockInode(nextInode, LockMode.WRITE); } else if (mLockPattern == LockPattern.WRITE_EDGE) { if (mLockList.numLockedInodes() == mExistingInodes.size()) { // Add the final inode, which is not locked but does exist. mExistingInodes.add(nextInode); } } } else { mLockList.lockInode(nextInode, LockMode.READ); } // Avoid adding the inode if it is already in mExistingInodes. if (mLockList.numLockedInodes() > mExistingInodes.size()) { mExistingInodes.add(nextInode); } } } }
java
public void traverse() throws InvalidPathException { if (mLockList.getLockMode() == LockMode.WRITE) { traverseWithoutLocking(); return; } // This locks the root edge and inode if necessary. bootstrapTraversal(); // Each iteration either locks a new inode/edge or hits a missing inode and returns. while (!fullPathExists()) { int lastInodeIndex = mLockList.getLockedInodes().size() - 1; String nextComponent = mPathComponents[lastInodeIndex + 1]; boolean isFinalComponent = lastInodeIndex == mPathComponents.length - 2; if (mLockList.endsInInode()) { // Lock an edge next. if (mLockPattern == LockPattern.WRITE_EDGE && isFinalComponent) { mLockList.lockEdge(nextComponent, LockMode.WRITE); } else { mLockList.lockEdge(nextComponent, LockMode.READ); } } else { // Lock an inode next. Inode lastInode = mLockList.getLockedInodes().get(lastInodeIndex); if (!lastInode.isDirectory()) { throw new InvalidPathException(String.format( "Traversal failed for path %s. Component %s(%s) is a file, not a directory.", mUri, lastInodeIndex, lastInode.getName())); } Optional<Inode> nextInodeOpt = mInodeStore.getChild(lastInode.asDirectory(), nextComponent); if (!nextInodeOpt.isPresent() && mLockPattern == LockPattern.WRITE_EDGE && !isFinalComponent) { // This pattern requires that we obtain a write lock on the final edge, so we must // upgrade to a write lock. mLockList.unlockLastEdge(); mLockList.lockEdge(nextComponent, LockMode.WRITE); nextInodeOpt = mInodeStore.getChild(lastInode.asDirectory(), nextComponent); if (nextInodeOpt.isPresent()) { // The component must have been created between releasing the read lock and acquiring // the write lock. Downgrade and continue as normal. mLockList.downgradeLastEdge(); } } if (!nextInodeOpt.isPresent()) { if (mLockPattern != LockPattern.WRITE_EDGE) { // Other lock patterns only lock up to the last existing inode. mLockList.unlockLastEdge(); } return; } Inode nextInode = nextInodeOpt.get(); if (isFinalComponent) { if (mLockPattern == LockPattern.READ) { mLockList.lockInode(nextInode, LockMode.READ); } else if (mLockPattern == LockPattern.WRITE_INODE) { mLockList.lockInode(nextInode, LockMode.WRITE); } else if (mLockPattern == LockPattern.WRITE_EDGE) { if (mLockList.numLockedInodes() == mExistingInodes.size()) { // Add the final inode, which is not locked but does exist. mExistingInodes.add(nextInode); } } } else { mLockList.lockInode(nextInode, LockMode.READ); } // Avoid adding the inode if it is already in mExistingInodes. if (mLockList.numLockedInodes() > mExistingInodes.size()) { mExistingInodes.add(nextInode); } } } }
[ "public", "void", "traverse", "(", ")", "throws", "InvalidPathException", "{", "if", "(", "mLockList", ".", "getLockMode", "(", ")", "==", "LockMode", ".", "WRITE", ")", "{", "traverseWithoutLocking", "(", ")", ";", "return", ";", "}", "// This locks the root edge and inode if necessary.", "bootstrapTraversal", "(", ")", ";", "// Each iteration either locks a new inode/edge or hits a missing inode and returns.", "while", "(", "!", "fullPathExists", "(", ")", ")", "{", "int", "lastInodeIndex", "=", "mLockList", ".", "getLockedInodes", "(", ")", ".", "size", "(", ")", "-", "1", ";", "String", "nextComponent", "=", "mPathComponents", "[", "lastInodeIndex", "+", "1", "]", ";", "boolean", "isFinalComponent", "=", "lastInodeIndex", "==", "mPathComponents", ".", "length", "-", "2", ";", "if", "(", "mLockList", ".", "endsInInode", "(", ")", ")", "{", "// Lock an edge next.", "if", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_EDGE", "&&", "isFinalComponent", ")", "{", "mLockList", ".", "lockEdge", "(", "nextComponent", ",", "LockMode", ".", "WRITE", ")", ";", "}", "else", "{", "mLockList", ".", "lockEdge", "(", "nextComponent", ",", "LockMode", ".", "READ", ")", ";", "}", "}", "else", "{", "// Lock an inode next.", "Inode", "lastInode", "=", "mLockList", ".", "getLockedInodes", "(", ")", ".", "get", "(", "lastInodeIndex", ")", ";", "if", "(", "!", "lastInode", ".", "isDirectory", "(", ")", ")", "{", "throw", "new", "InvalidPathException", "(", "String", ".", "format", "(", "\"Traversal failed for path %s. Component %s(%s) is a file, not a directory.\"", ",", "mUri", ",", "lastInodeIndex", ",", "lastInode", ".", "getName", "(", ")", ")", ")", ";", "}", "Optional", "<", "Inode", ">", "nextInodeOpt", "=", "mInodeStore", ".", "getChild", "(", "lastInode", ".", "asDirectory", "(", ")", ",", "nextComponent", ")", ";", "if", "(", "!", "nextInodeOpt", ".", "isPresent", "(", ")", "&&", "mLockPattern", "==", "LockPattern", ".", "WRITE_EDGE", "&&", "!", "isFinalComponent", ")", "{", "// This pattern requires that we obtain a write lock on the final edge, so we must", "// upgrade to a write lock.", "mLockList", ".", "unlockLastEdge", "(", ")", ";", "mLockList", ".", "lockEdge", "(", "nextComponent", ",", "LockMode", ".", "WRITE", ")", ";", "nextInodeOpt", "=", "mInodeStore", ".", "getChild", "(", "lastInode", ".", "asDirectory", "(", ")", ",", "nextComponent", ")", ";", "if", "(", "nextInodeOpt", ".", "isPresent", "(", ")", ")", "{", "// The component must have been created between releasing the read lock and acquiring", "// the write lock. Downgrade and continue as normal.", "mLockList", ".", "downgradeLastEdge", "(", ")", ";", "}", "}", "if", "(", "!", "nextInodeOpt", ".", "isPresent", "(", ")", ")", "{", "if", "(", "mLockPattern", "!=", "LockPattern", ".", "WRITE_EDGE", ")", "{", "// Other lock patterns only lock up to the last existing inode.", "mLockList", ".", "unlockLastEdge", "(", ")", ";", "}", "return", ";", "}", "Inode", "nextInode", "=", "nextInodeOpt", ".", "get", "(", ")", ";", "if", "(", "isFinalComponent", ")", "{", "if", "(", "mLockPattern", "==", "LockPattern", ".", "READ", ")", "{", "mLockList", ".", "lockInode", "(", "nextInode", ",", "LockMode", ".", "READ", ")", ";", "}", "else", "if", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_INODE", ")", "{", "mLockList", ".", "lockInode", "(", "nextInode", ",", "LockMode", ".", "WRITE", ")", ";", "}", "else", "if", "(", "mLockPattern", "==", "LockPattern", ".", "WRITE_EDGE", ")", "{", "if", "(", "mLockList", ".", "numLockedInodes", "(", ")", "==", "mExistingInodes", ".", "size", "(", ")", ")", "{", "// Add the final inode, which is not locked but does exist.", "mExistingInodes", ".", "add", "(", "nextInode", ")", ";", "}", "}", "}", "else", "{", "mLockList", ".", "lockInode", "(", "nextInode", ",", "LockMode", ".", "READ", ")", ";", "}", "// Avoid adding the inode if it is already in mExistingInodes.", "if", "(", "mLockList", ".", "numLockedInodes", "(", ")", ">", "mExistingInodes", ".", "size", "(", ")", ")", "{", "mExistingInodes", ".", "add", "(", "nextInode", ")", ";", "}", "}", "}", "}" ]
Traverses the inode path according to its lock pattern. If the inode path is already partially traversed, this method will pick up where the previous traversal left off. If the path already ends in a write lock, traverse will populate the inodes list without taking any additional locks. On return, all existing inodes in the path are added to mExistingInodes and the inodes are locked according to to {@link LockPattern}.
[ "Traverses", "the", "inode", "path", "according", "to", "its", "lock", "pattern", ".", "If", "the", "inode", "path", "is", "already", "partially", "traversed", "this", "method", "will", "pick", "up", "where", "the", "previous", "traversal", "left", "off", ".", "If", "the", "path", "already", "ends", "in", "a", "write", "lock", "traverse", "will", "populate", "the", "inodes", "list", "without", "taking", "any", "additional", "locks", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/LockedInodePath.java#L443-L516
18,856
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java
MetricsStore.getFullInstanceId
private static String getFullInstanceId(String hostname, String id) { String str = hostname == null ? "" : hostname; str = str.replace('.', '_'); str += (id == null ? "" : "-" + id); return str; }
java
private static String getFullInstanceId(String hostname, String id) { String str = hostname == null ? "" : hostname; str = str.replace('.', '_'); str += (id == null ? "" : "-" + id); return str; }
[ "private", "static", "String", "getFullInstanceId", "(", "String", "hostname", ",", "String", "id", ")", "{", "String", "str", "=", "hostname", "==", "null", "?", "\"\"", ":", "hostname", ";", "str", "=", "str", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "str", "+=", "(", "id", "==", "null", "?", "\"\"", ":", "\"-\"", "+", "id", ")", ";", "return", "str", ";", "}" ]
Gets the full instance id of the concatenation of hostname and the id. The dots in the hostname replaced by underscores. @param hostname the hostname @param id the instance id @return the full instance id of hostname[:id]
[ "Gets", "the", "full", "instance", "id", "of", "the", "concatenation", "of", "hostname", "and", "the", "id", ".", "The", "dots", "in", "the", "hostname", "replaced", "by", "underscores", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java#L68-L73
18,857
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java
MetricsStore.putWorkerMetrics
public void putWorkerMetrics(String hostname, List<Metric> metrics) { if (metrics.isEmpty()) { return; } synchronized (mWorkerMetrics) { mWorkerMetrics.removeByField(ID_INDEX, getFullInstanceId(hostname, null)); for (Metric metric : metrics) { if (metric.getHostname() == null) { continue; // ignore metrics whose hostname is null } mWorkerMetrics.add(metric); } } }
java
public void putWorkerMetrics(String hostname, List<Metric> metrics) { if (metrics.isEmpty()) { return; } synchronized (mWorkerMetrics) { mWorkerMetrics.removeByField(ID_INDEX, getFullInstanceId(hostname, null)); for (Metric metric : metrics) { if (metric.getHostname() == null) { continue; // ignore metrics whose hostname is null } mWorkerMetrics.add(metric); } } }
[ "public", "void", "putWorkerMetrics", "(", "String", "hostname", ",", "List", "<", "Metric", ">", "metrics", ")", "{", "if", "(", "metrics", ".", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "synchronized", "(", "mWorkerMetrics", ")", "{", "mWorkerMetrics", ".", "removeByField", "(", "ID_INDEX", ",", "getFullInstanceId", "(", "hostname", ",", "null", ")", ")", ";", "for", "(", "Metric", "metric", ":", "metrics", ")", "{", "if", "(", "metric", ".", "getHostname", "(", ")", "==", "null", ")", "{", "continue", ";", "// ignore metrics whose hostname is null", "}", "mWorkerMetrics", ".", "add", "(", "metric", ")", ";", "}", "}", "}" ]
Put the metrics from a worker with a hostname. If all the old metrics associated with this instance will be removed and then replaced by the latest. @param hostname the hostname of the instance @param metrics the new worker metrics
[ "Put", "the", "metrics", "from", "a", "worker", "with", "a", "hostname", ".", "If", "all", "the", "old", "metrics", "associated", "with", "this", "instance", "will", "be", "removed", "and", "then", "replaced", "by", "the", "latest", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java#L91-L104
18,858
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java
MetricsStore.putClientMetrics
public void putClientMetrics(String hostname, String clientId, List<Metric> metrics) { if (metrics.isEmpty()) { return; } LOG.debug("Removing metrics for id {} to replace with {}", clientId, metrics); synchronized (mClientMetrics) { mClientMetrics.removeByField(ID_INDEX, getFullInstanceId(hostname, clientId)); for (Metric metric : metrics) { if (metric.getHostname() == null) { continue; // ignore metrics whose hostname is null } mClientMetrics.add(metric); } } }
java
public void putClientMetrics(String hostname, String clientId, List<Metric> metrics) { if (metrics.isEmpty()) { return; } LOG.debug("Removing metrics for id {} to replace with {}", clientId, metrics); synchronized (mClientMetrics) { mClientMetrics.removeByField(ID_INDEX, getFullInstanceId(hostname, clientId)); for (Metric metric : metrics) { if (metric.getHostname() == null) { continue; // ignore metrics whose hostname is null } mClientMetrics.add(metric); } } }
[ "public", "void", "putClientMetrics", "(", "String", "hostname", ",", "String", "clientId", ",", "List", "<", "Metric", ">", "metrics", ")", "{", "if", "(", "metrics", ".", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "LOG", ".", "debug", "(", "\"Removing metrics for id {} to replace with {}\"", ",", "clientId", ",", "metrics", ")", ";", "synchronized", "(", "mClientMetrics", ")", "{", "mClientMetrics", ".", "removeByField", "(", "ID_INDEX", ",", "getFullInstanceId", "(", "hostname", ",", "clientId", ")", ")", ";", "for", "(", "Metric", "metric", ":", "metrics", ")", "{", "if", "(", "metric", ".", "getHostname", "(", ")", "==", "null", ")", "{", "continue", ";", "// ignore metrics whose hostname is null", "}", "mClientMetrics", ".", "add", "(", "metric", ")", ";", "}", "}", "}" ]
Put the metrics from a client with a hostname and a client id. If all the old metrics associated with this instance will be removed and then replaced by the latest. @param hostname the hostname of the client @param clientId the id of the client @param metrics the new metrics
[ "Put", "the", "metrics", "from", "a", "client", "with", "a", "hostname", "and", "a", "client", "id", ".", "If", "all", "the", "old", "metrics", "associated", "with", "this", "instance", "will", "be", "removed", "and", "then", "replaced", "by", "the", "latest", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java#L114-L129
18,859
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java
MetricsStore.getMetricsByInstanceTypeAndName
public Set<Metric> getMetricsByInstanceTypeAndName( MetricsSystem.InstanceType instanceType, String name) { if (instanceType == InstanceType.MASTER) { return getMasterMetrics(name); } if (instanceType == InstanceType.WORKER) { synchronized (mWorkerMetrics) { return mWorkerMetrics.getByField(NAME_INDEX, name); } } else if (instanceType == InstanceType.CLIENT) { synchronized (mClientMetrics) { return mClientMetrics.getByField(NAME_INDEX, name); } } else { throw new IllegalArgumentException("Unsupported instance type " + instanceType); } }
java
public Set<Metric> getMetricsByInstanceTypeAndName( MetricsSystem.InstanceType instanceType, String name) { if (instanceType == InstanceType.MASTER) { return getMasterMetrics(name); } if (instanceType == InstanceType.WORKER) { synchronized (mWorkerMetrics) { return mWorkerMetrics.getByField(NAME_INDEX, name); } } else if (instanceType == InstanceType.CLIENT) { synchronized (mClientMetrics) { return mClientMetrics.getByField(NAME_INDEX, name); } } else { throw new IllegalArgumentException("Unsupported instance type " + instanceType); } }
[ "public", "Set", "<", "Metric", ">", "getMetricsByInstanceTypeAndName", "(", "MetricsSystem", ".", "InstanceType", "instanceType", ",", "String", "name", ")", "{", "if", "(", "instanceType", "==", "InstanceType", ".", "MASTER", ")", "{", "return", "getMasterMetrics", "(", "name", ")", ";", "}", "if", "(", "instanceType", "==", "InstanceType", ".", "WORKER", ")", "{", "synchronized", "(", "mWorkerMetrics", ")", "{", "return", "mWorkerMetrics", ".", "getByField", "(", "NAME_INDEX", ",", "name", ")", ";", "}", "}", "else", "if", "(", "instanceType", "==", "InstanceType", ".", "CLIENT", ")", "{", "synchronized", "(", "mClientMetrics", ")", "{", "return", "mClientMetrics", ".", "getByField", "(", "NAME_INDEX", ",", "name", ")", ";", "}", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"Unsupported instance type \"", "+", "instanceType", ")", ";", "}", "}" ]
Gets all the metrics by instance type and the metric name. The supported instance types are worker and client. @param instanceType the instance type @param name the metric name @return the set of matched metrics
[ "Gets", "all", "the", "metrics", "by", "instance", "type", "and", "the", "metric", "name", ".", "The", "supported", "instance", "types", "are", "worker", "and", "client", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metrics/MetricsStore.java#L139-L156
18,860
Alluxio/alluxio
core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
AbstractFileSystem.create
@Override public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { LOG.debug("create({}, {}, {}, {}, {}, {}, {})", path, permission, overwrite, bufferSize, replication, blockSize, progress); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); CreateFilePOptions options = CreateFilePOptions.newBuilder().setBlockSizeBytes(blockSize) .setMode(new Mode(permission.toShort()).toProto()).setRecursive(true).build(); FileOutStream outStream; try { outStream = mFileSystem.createFile(uri, options); } catch (AlluxioException e) { //now we should consider the override parameter try { if (mFileSystem.exists(uri)) { if (!overwrite) { throw new IOException(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(uri)); } if (mFileSystem.getStatus(uri).isFolder()) { throw new IOException( ExceptionMessage.FILE_CREATE_IS_DIRECTORY.getMessage(uri)); } mFileSystem.delete(uri); } outStream = mFileSystem.createFile(uri, options); } catch (AlluxioException e2) { throw new IOException(e2); } } return new FSDataOutputStream(outStream, mStatistics); }
java
@Override public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress) throws IOException { LOG.debug("create({}, {}, {}, {}, {}, {}, {})", path, permission, overwrite, bufferSize, replication, blockSize, progress); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); CreateFilePOptions options = CreateFilePOptions.newBuilder().setBlockSizeBytes(blockSize) .setMode(new Mode(permission.toShort()).toProto()).setRecursive(true).build(); FileOutStream outStream; try { outStream = mFileSystem.createFile(uri, options); } catch (AlluxioException e) { //now we should consider the override parameter try { if (mFileSystem.exists(uri)) { if (!overwrite) { throw new IOException(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(uri)); } if (mFileSystem.getStatus(uri).isFolder()) { throw new IOException( ExceptionMessage.FILE_CREATE_IS_DIRECTORY.getMessage(uri)); } mFileSystem.delete(uri); } outStream = mFileSystem.createFile(uri, options); } catch (AlluxioException e2) { throw new IOException(e2); } } return new FSDataOutputStream(outStream, mStatistics); }
[ "@", "Override", "public", "FSDataOutputStream", "create", "(", "Path", "path", ",", "FsPermission", "permission", ",", "boolean", "overwrite", ",", "int", "bufferSize", ",", "short", "replication", ",", "long", "blockSize", ",", "Progressable", "progress", ")", "throws", "IOException", "{", "LOG", ".", "debug", "(", "\"create({}, {}, {}, {}, {}, {}, {})\"", ",", "path", ",", "permission", ",", "overwrite", ",", "bufferSize", ",", "replication", ",", "blockSize", ",", "progress", ")", ";", "if", "(", "mStatistics", "!=", "null", ")", "{", "mStatistics", ".", "incrementWriteOps", "(", "1", ")", ";", "}", "AlluxioURI", "uri", "=", "new", "AlluxioURI", "(", "HadoopUtils", ".", "getPathWithoutScheme", "(", "path", ")", ")", ";", "CreateFilePOptions", "options", "=", "CreateFilePOptions", ".", "newBuilder", "(", ")", ".", "setBlockSizeBytes", "(", "blockSize", ")", ".", "setMode", "(", "new", "Mode", "(", "permission", ".", "toShort", "(", ")", ")", ".", "toProto", "(", ")", ")", ".", "setRecursive", "(", "true", ")", ".", "build", "(", ")", ";", "FileOutStream", "outStream", ";", "try", "{", "outStream", "=", "mFileSystem", ".", "createFile", "(", "uri", ",", "options", ")", ";", "}", "catch", "(", "AlluxioException", "e", ")", "{", "//now we should consider the override parameter", "try", "{", "if", "(", "mFileSystem", ".", "exists", "(", "uri", ")", ")", "{", "if", "(", "!", "overwrite", ")", "{", "throw", "new", "IOException", "(", "ExceptionMessage", ".", "FILE_ALREADY_EXISTS", ".", "getMessage", "(", "uri", ")", ")", ";", "}", "if", "(", "mFileSystem", ".", "getStatus", "(", "uri", ")", ".", "isFolder", "(", ")", ")", "{", "throw", "new", "IOException", "(", "ExceptionMessage", ".", "FILE_CREATE_IS_DIRECTORY", ".", "getMessage", "(", "uri", ")", ")", ";", "}", "mFileSystem", ".", "delete", "(", "uri", ")", ";", "}", "outStream", "=", "mFileSystem", ".", "createFile", "(", "uri", ",", "options", ")", ";", "}", "catch", "(", "AlluxioException", "e2", ")", "{", "throw", "new", "IOException", "(", "e2", ")", ";", "}", "}", "return", "new", "FSDataOutputStream", "(", "outStream", ",", "mStatistics", ")", ";", "}" ]
Attempts to create a file. Overwrite will not succeed if the path exists and is a folder. @param path path to create @param permission permissions of the created file/folder @param overwrite overwrite if file exists @param bufferSize the size in bytes of the buffer to be used @param replication under filesystem replication factor, this is ignored @param blockSize block size in bytes @param progress queryable progress @return an {@link FSDataOutputStream} created at the indicated path of a file
[ "Attempts", "to", "create", "a", "file", ".", "Overwrite", "will", "not", "succeed", "if", "the", "path", "exists", "and", "is", "a", "folder", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java#L157-L192
18,861
Alluxio/alluxio
core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
AbstractFileSystem.delete
@Override public boolean delete(Path path, boolean recursive) throws IOException { LOG.debug("delete({}, {})", path, recursive); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); DeletePOptions options = DeletePOptions.newBuilder().setRecursive(recursive).build(); try { mFileSystem.delete(uri, options); return true; } catch (InvalidPathException | FileDoesNotExistException e) { LOG.warn("delete failed: {}", e.getMessage()); return false; } catch (AlluxioException e) { throw new IOException(e); } }
java
@Override public boolean delete(Path path, boolean recursive) throws IOException { LOG.debug("delete({}, {})", path, recursive); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); DeletePOptions options = DeletePOptions.newBuilder().setRecursive(recursive).build(); try { mFileSystem.delete(uri, options); return true; } catch (InvalidPathException | FileDoesNotExistException e) { LOG.warn("delete failed: {}", e.getMessage()); return false; } catch (AlluxioException e) { throw new IOException(e); } }
[ "@", "Override", "public", "boolean", "delete", "(", "Path", "path", ",", "boolean", "recursive", ")", "throws", "IOException", "{", "LOG", ".", "debug", "(", "\"delete({}, {})\"", ",", "path", ",", "recursive", ")", ";", "if", "(", "mStatistics", "!=", "null", ")", "{", "mStatistics", ".", "incrementWriteOps", "(", "1", ")", ";", "}", "AlluxioURI", "uri", "=", "new", "AlluxioURI", "(", "HadoopUtils", ".", "getPathWithoutScheme", "(", "path", ")", ")", ";", "DeletePOptions", "options", "=", "DeletePOptions", ".", "newBuilder", "(", ")", ".", "setRecursive", "(", "recursive", ")", ".", "build", "(", ")", ";", "try", "{", "mFileSystem", ".", "delete", "(", "uri", ",", "options", ")", ";", "return", "true", ";", "}", "catch", "(", "InvalidPathException", "|", "FileDoesNotExistException", "e", ")", "{", "LOG", ".", "warn", "(", "\"delete failed: {}\"", ",", "e", ".", "getMessage", "(", ")", ")", ";", "return", "false", ";", "}", "catch", "(", "AlluxioException", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "}" ]
Attempts to delete the file or directory with the specified path. @param path path to delete @param recursive if true, will attempt to delete all children of the path @return true if one or more files/directories were deleted; false otherwise
[ "Attempts", "to", "delete", "the", "file", "or", "directory", "with", "the", "specified", "path", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java#L241-L258
18,862
Alluxio/alluxio
core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
AbstractFileSystem.setPermission
@Override public void setPermission(Path path, FsPermission permission) throws IOException { LOG.debug("setMode({},{})", path, permission.toString()); AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); SetAttributePOptions options = SetAttributePOptions.newBuilder() .setMode(new Mode(permission.toShort()).toProto()).setRecursive(false).build(); try { mFileSystem.setAttribute(uri, options); } catch (AlluxioException e) { throw new IOException(e); } }
java
@Override public void setPermission(Path path, FsPermission permission) throws IOException { LOG.debug("setMode({},{})", path, permission.toString()); AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); SetAttributePOptions options = SetAttributePOptions.newBuilder() .setMode(new Mode(permission.toShort()).toProto()).setRecursive(false).build(); try { mFileSystem.setAttribute(uri, options); } catch (AlluxioException e) { throw new IOException(e); } }
[ "@", "Override", "public", "void", "setPermission", "(", "Path", "path", ",", "FsPermission", "permission", ")", "throws", "IOException", "{", "LOG", ".", "debug", "(", "\"setMode({},{})\"", ",", "path", ",", "permission", ".", "toString", "(", ")", ")", ";", "AlluxioURI", "uri", "=", "new", "AlluxioURI", "(", "HadoopUtils", ".", "getPathWithoutScheme", "(", "path", ")", ")", ";", "SetAttributePOptions", "options", "=", "SetAttributePOptions", ".", "newBuilder", "(", ")", ".", "setMode", "(", "new", "Mode", "(", "permission", ".", "toShort", "(", ")", ")", ".", "toProto", "(", ")", ")", ".", "setRecursive", "(", "false", ")", ".", "build", "(", ")", ";", "try", "{", "mFileSystem", ".", "setAttribute", "(", "uri", ",", "options", ")", ";", "}", "catch", "(", "AlluxioException", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "}" ]
Changes permission of a path. @param path path to set permission @param permission permission set to path
[ "Changes", "permission", "of", "a", "path", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java#L404-L415
18,863
Alluxio/alluxio
core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
AbstractFileSystem.getConfigurationFromUri
private Map<String, Object> getConfigurationFromUri(URI uri) { AlluxioURI alluxioUri = new AlluxioURI(uri.toString()); Map<String, Object> alluxioConfProperties = new HashMap<>(); if (alluxioUri.getAuthority() instanceof ZookeeperAuthority) { ZookeeperAuthority authority = (ZookeeperAuthority) alluxioUri.getAuthority(); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), true); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), authority.getZookeeperAddress()); } else if (alluxioUri.getAuthority() instanceof SingleMasterAuthority) { SingleMasterAuthority authority = (SingleMasterAuthority) alluxioUri.getAuthority(); alluxioConfProperties.put(PropertyKey.MASTER_HOSTNAME.getName(), authority.getHost()); alluxioConfProperties.put(PropertyKey.MASTER_RPC_PORT.getName(), authority.getPort()); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), false); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), null); // Unset the embedded journal related configuration // to support alluxio URI has the highest priority alluxioConfProperties.put(PropertyKey.MASTER_EMBEDDED_JOURNAL_ADDRESSES.getName(), null); alluxioConfProperties.put(PropertyKey.MASTER_RPC_ADDRESSES.getName(), null); } else if (alluxioUri.getAuthority() instanceof MultiMasterAuthority) { MultiMasterAuthority authority = (MultiMasterAuthority) alluxioUri.getAuthority(); alluxioConfProperties.put(PropertyKey.MASTER_RPC_ADDRESSES.getName(), authority.getMasterAddresses()); // Unset the zookeeper configuration to support alluxio URI has the highest priority alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), false); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), null); } return alluxioConfProperties; }
java
private Map<String, Object> getConfigurationFromUri(URI uri) { AlluxioURI alluxioUri = new AlluxioURI(uri.toString()); Map<String, Object> alluxioConfProperties = new HashMap<>(); if (alluxioUri.getAuthority() instanceof ZookeeperAuthority) { ZookeeperAuthority authority = (ZookeeperAuthority) alluxioUri.getAuthority(); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), true); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), authority.getZookeeperAddress()); } else if (alluxioUri.getAuthority() instanceof SingleMasterAuthority) { SingleMasterAuthority authority = (SingleMasterAuthority) alluxioUri.getAuthority(); alluxioConfProperties.put(PropertyKey.MASTER_HOSTNAME.getName(), authority.getHost()); alluxioConfProperties.put(PropertyKey.MASTER_RPC_PORT.getName(), authority.getPort()); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), false); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), null); // Unset the embedded journal related configuration // to support alluxio URI has the highest priority alluxioConfProperties.put(PropertyKey.MASTER_EMBEDDED_JOURNAL_ADDRESSES.getName(), null); alluxioConfProperties.put(PropertyKey.MASTER_RPC_ADDRESSES.getName(), null); } else if (alluxioUri.getAuthority() instanceof MultiMasterAuthority) { MultiMasterAuthority authority = (MultiMasterAuthority) alluxioUri.getAuthority(); alluxioConfProperties.put(PropertyKey.MASTER_RPC_ADDRESSES.getName(), authority.getMasterAddresses()); // Unset the zookeeper configuration to support alluxio URI has the highest priority alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), false); alluxioConfProperties.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), null); } return alluxioConfProperties; }
[ "private", "Map", "<", "String", ",", "Object", ">", "getConfigurationFromUri", "(", "URI", "uri", ")", "{", "AlluxioURI", "alluxioUri", "=", "new", "AlluxioURI", "(", "uri", ".", "toString", "(", ")", ")", ";", "Map", "<", "String", ",", "Object", ">", "alluxioConfProperties", "=", "new", "HashMap", "<>", "(", ")", ";", "if", "(", "alluxioUri", ".", "getAuthority", "(", ")", "instanceof", "ZookeeperAuthority", ")", "{", "ZookeeperAuthority", "authority", "=", "(", "ZookeeperAuthority", ")", "alluxioUri", ".", "getAuthority", "(", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "ZOOKEEPER_ENABLED", ".", "getName", "(", ")", ",", "true", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "ZOOKEEPER_ADDRESS", ".", "getName", "(", ")", ",", "authority", ".", "getZookeeperAddress", "(", ")", ")", ";", "}", "else", "if", "(", "alluxioUri", ".", "getAuthority", "(", ")", "instanceof", "SingleMasterAuthority", ")", "{", "SingleMasterAuthority", "authority", "=", "(", "SingleMasterAuthority", ")", "alluxioUri", ".", "getAuthority", "(", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "MASTER_HOSTNAME", ".", "getName", "(", ")", ",", "authority", ".", "getHost", "(", ")", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "MASTER_RPC_PORT", ".", "getName", "(", ")", ",", "authority", ".", "getPort", "(", ")", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "ZOOKEEPER_ENABLED", ".", "getName", "(", ")", ",", "false", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "ZOOKEEPER_ADDRESS", ".", "getName", "(", ")", ",", "null", ")", ";", "// Unset the embedded journal related configuration", "// to support alluxio URI has the highest priority", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "MASTER_EMBEDDED_JOURNAL_ADDRESSES", ".", "getName", "(", ")", ",", "null", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "MASTER_RPC_ADDRESSES", ".", "getName", "(", ")", ",", "null", ")", ";", "}", "else", "if", "(", "alluxioUri", ".", "getAuthority", "(", ")", "instanceof", "MultiMasterAuthority", ")", "{", "MultiMasterAuthority", "authority", "=", "(", "MultiMasterAuthority", ")", "alluxioUri", ".", "getAuthority", "(", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "MASTER_RPC_ADDRESSES", ".", "getName", "(", ")", ",", "authority", ".", "getMasterAddresses", "(", ")", ")", ";", "// Unset the zookeeper configuration to support alluxio URI has the highest priority", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "ZOOKEEPER_ENABLED", ".", "getName", "(", ")", ",", "false", ")", ";", "alluxioConfProperties", ".", "put", "(", "PropertyKey", ".", "ZOOKEEPER_ADDRESS", ".", "getName", "(", ")", ",", "null", ")", ";", "}", "return", "alluxioConfProperties", ";", "}" ]
Gets the connection configuration from the input uri. @param uri a Alluxio Uri that may contain connection configuration
[ "Gets", "the", "connection", "configuration", "from", "the", "input", "uri", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java#L537-L565
18,864
Alluxio/alluxio
core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
AbstractFileSystem.mkdirs
@Override public boolean mkdirs(Path path, FsPermission permission) throws IOException { LOG.debug("mkdirs({}, {})", path, permission); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); CreateDirectoryPOptions options = CreateDirectoryPOptions.newBuilder().setRecursive(true) .setAllowExists(true).setMode(new Mode(permission.toShort()).toProto()).build(); try { mFileSystem.createDirectory(uri, options); return true; } catch (AlluxioException e) { throw new IOException(e); } }
java
@Override public boolean mkdirs(Path path, FsPermission permission) throws IOException { LOG.debug("mkdirs({}, {})", path, permission); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); CreateDirectoryPOptions options = CreateDirectoryPOptions.newBuilder().setRecursive(true) .setAllowExists(true).setMode(new Mode(permission.toShort()).toProto()).build(); try { mFileSystem.createDirectory(uri, options); return true; } catch (AlluxioException e) { throw new IOException(e); } }
[ "@", "Override", "public", "boolean", "mkdirs", "(", "Path", "path", ",", "FsPermission", "permission", ")", "throws", "IOException", "{", "LOG", ".", "debug", "(", "\"mkdirs({}, {})\"", ",", "path", ",", "permission", ")", ";", "if", "(", "mStatistics", "!=", "null", ")", "{", "mStatistics", ".", "incrementWriteOps", "(", "1", ")", ";", "}", "AlluxioURI", "uri", "=", "new", "AlluxioURI", "(", "HadoopUtils", ".", "getPathWithoutScheme", "(", "path", ")", ")", ";", "CreateDirectoryPOptions", "options", "=", "CreateDirectoryPOptions", ".", "newBuilder", "(", ")", ".", "setRecursive", "(", "true", ")", ".", "setAllowExists", "(", "true", ")", ".", "setMode", "(", "new", "Mode", "(", "permission", ".", "toShort", "(", ")", ")", ".", "toProto", "(", ")", ")", ".", "build", "(", ")", ";", "try", "{", "mFileSystem", ".", "createDirectory", "(", "uri", ",", "options", ")", ";", "return", "true", ";", "}", "catch", "(", "AlluxioException", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "}" ]
Attempts to create a folder with the specified path. Parent directories will be created. @param path path to create @param permission permissions to grant the created folder @return true if the indicated folder is created successfully or already exists
[ "Attempts", "to", "create", "a", "folder", "with", "the", "specified", "path", ".", "Parent", "directories", "will", "be", "created", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java#L637-L652
18,865
Alluxio/alluxio
core/base/src/main/java/alluxio/security/authorization/ModeParser.java
ModeParser.parse
public static Mode parse(String value) { if (StringUtils.isBlank(value)) { throw new IllegalArgumentException(ExceptionMessage.INVALID_MODE.getMessage(value)); } try { return parseNumeric(value); } catch (NumberFormatException e) { // Treat as symbolic return parseSymbolic(value); } }
java
public static Mode parse(String value) { if (StringUtils.isBlank(value)) { throw new IllegalArgumentException(ExceptionMessage.INVALID_MODE.getMessage(value)); } try { return parseNumeric(value); } catch (NumberFormatException e) { // Treat as symbolic return parseSymbolic(value); } }
[ "public", "static", "Mode", "parse", "(", "String", "value", ")", "{", "if", "(", "StringUtils", ".", "isBlank", "(", "value", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "ExceptionMessage", ".", "INVALID_MODE", ".", "getMessage", "(", "value", ")", ")", ";", "}", "try", "{", "return", "parseNumeric", "(", "value", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "// Treat as symbolic", "return", "parseSymbolic", "(", "value", ")", ";", "}", "}" ]
Parses the given value as a mode. @param value Value @return Mode
[ "Parses", "the", "given", "value", "as", "a", "mode", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/base/src/main/java/alluxio/security/authorization/ModeParser.java#L39-L50
18,866
Alluxio/alluxio
core/server/worker/src/main/java/alluxio/worker/SessionCleaner.java
SessionCleaner.run
@Override public void run() { long lastCheckMs = System.currentTimeMillis(); while (mRunning) { // Check the time since last check, and wait until it is within check interval long lastIntervalMs = System.currentTimeMillis() - lastCheckMs; long toSleepMs = mCheckIntervalMs - lastIntervalMs; if (toSleepMs > 0) { CommonUtils.sleepMs(LOG, toSleepMs); } else { LOG.warn("Session cleanup took: {}, expected: {}", lastIntervalMs, mCheckIntervalMs); } // Check if any sessions have become zombies, if so clean them up lastCheckMs = System.currentTimeMillis(); for (long session : mSessions.getTimedOutSessions()) { mSessions.removeSession(session); for (SessionCleanable sc : mSessionCleanables) { sc.cleanupSession(session); } } } }
java
@Override public void run() { long lastCheckMs = System.currentTimeMillis(); while (mRunning) { // Check the time since last check, and wait until it is within check interval long lastIntervalMs = System.currentTimeMillis() - lastCheckMs; long toSleepMs = mCheckIntervalMs - lastIntervalMs; if (toSleepMs > 0) { CommonUtils.sleepMs(LOG, toSleepMs); } else { LOG.warn("Session cleanup took: {}, expected: {}", lastIntervalMs, mCheckIntervalMs); } // Check if any sessions have become zombies, if so clean them up lastCheckMs = System.currentTimeMillis(); for (long session : mSessions.getTimedOutSessions()) { mSessions.removeSession(session); for (SessionCleanable sc : mSessionCleanables) { sc.cleanupSession(session); } } } }
[ "@", "Override", "public", "void", "run", "(", ")", "{", "long", "lastCheckMs", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "while", "(", "mRunning", ")", "{", "// Check the time since last check, and wait until it is within check interval", "long", "lastIntervalMs", "=", "System", ".", "currentTimeMillis", "(", ")", "-", "lastCheckMs", ";", "long", "toSleepMs", "=", "mCheckIntervalMs", "-", "lastIntervalMs", ";", "if", "(", "toSleepMs", ">", "0", ")", "{", "CommonUtils", ".", "sleepMs", "(", "LOG", ",", "toSleepMs", ")", ";", "}", "else", "{", "LOG", ".", "warn", "(", "\"Session cleanup took: {}, expected: {}\"", ",", "lastIntervalMs", ",", "mCheckIntervalMs", ")", ";", "}", "// Check if any sessions have become zombies, if so clean them up", "lastCheckMs", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "for", "(", "long", "session", ":", "mSessions", ".", "getTimedOutSessions", "(", ")", ")", "{", "mSessions", ".", "removeSession", "(", "session", ")", ";", "for", "(", "SessionCleanable", "sc", ":", "mSessionCleanables", ")", "{", "sc", ".", "cleanupSession", "(", "session", ")", ";", "}", "}", "}", "}" ]
Main loop for the cleanup, continuously looks for zombie sessions.
[ "Main", "loop", "for", "the", "cleanup", "continuously", "looks", "for", "zombie", "sessions", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/worker/src/main/java/alluxio/worker/SessionCleaner.java#L64-L86
18,867
Alluxio/alluxio
integration/yarn/src/main/java/alluxio/yarn/CommandBuilder.java
CommandBuilder.addArg
public CommandBuilder addArg(String opt, Object arg) { mArgs.add(opt + " " + String.valueOf(arg)); return this; }
java
public CommandBuilder addArg(String opt, Object arg) { mArgs.add(opt + " " + String.valueOf(arg)); return this; }
[ "public", "CommandBuilder", "addArg", "(", "String", "opt", ",", "Object", "arg", ")", "{", "mArgs", ".", "add", "(", "opt", "+", "\" \"", "+", "String", ".", "valueOf", "(", "arg", ")", ")", ";", "return", "this", ";", "}" ]
Adds the string value of the given option argument to the command. For example, to add "-name myFile" to construct the command "find . -name myFile", opt should be "-name" and arg should be "myFile". @param opt the option flag @param arg the argument @return the {@link CommandBuilder} with the argument added
[ "Adds", "the", "string", "value", "of", "the", "given", "option", "argument", "to", "the", "command", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/integration/yarn/src/main/java/alluxio/yarn/CommandBuilder.java#L59-L62
18,868
Alluxio/alluxio
shell/src/main/java/alluxio/cli/fs/FileSystemShell.java
FileSystemShell.main
public static void main(String[] argv) throws IOException { int ret; InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults()); if (!ConfigurationUtils.masterHostConfigured(conf) && argv.length > 0 && !argv[0].equals("help")) { System.out.println(ConfigurationUtils.getMasterHostNotConfiguredMessage("Alluxio fs shell")); System.exit(1); } // Reduce the RPC retry max duration to fall earlier for CLIs conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "5s", Source.DEFAULT); try (FileSystemShell shell = new FileSystemShell(conf)) { ret = shell.run(argv); } System.exit(ret); }
java
public static void main(String[] argv) throws IOException { int ret; InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults()); if (!ConfigurationUtils.masterHostConfigured(conf) && argv.length > 0 && !argv[0].equals("help")) { System.out.println(ConfigurationUtils.getMasterHostNotConfiguredMessage("Alluxio fs shell")); System.exit(1); } // Reduce the RPC retry max duration to fall earlier for CLIs conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "5s", Source.DEFAULT); try (FileSystemShell shell = new FileSystemShell(conf)) { ret = shell.run(argv); } System.exit(ret); }
[ "public", "static", "void", "main", "(", "String", "[", "]", "argv", ")", "throws", "IOException", "{", "int", "ret", ";", "InstancedConfiguration", "conf", "=", "new", "InstancedConfiguration", "(", "ConfigurationUtils", ".", "defaults", "(", ")", ")", ";", "if", "(", "!", "ConfigurationUtils", ".", "masterHostConfigured", "(", "conf", ")", "&&", "argv", ".", "length", ">", "0", "&&", "!", "argv", "[", "0", "]", ".", "equals", "(", "\"help\"", ")", ")", "{", "System", ".", "out", ".", "println", "(", "ConfigurationUtils", ".", "getMasterHostNotConfiguredMessage", "(", "\"Alluxio fs shell\"", ")", ")", ";", "System", ".", "exit", "(", "1", ")", ";", "}", "// Reduce the RPC retry max duration to fall earlier for CLIs", "conf", ".", "set", "(", "PropertyKey", ".", "USER_RPC_RETRY_MAX_DURATION", ",", "\"5s\"", ",", "Source", ".", "DEFAULT", ")", ";", "try", "(", "FileSystemShell", "shell", "=", "new", "FileSystemShell", "(", "conf", ")", ")", "{", "ret", "=", "shell", ".", "run", "(", "argv", ")", ";", "}", "System", ".", "exit", "(", "ret", ")", ";", "}" ]
Main method, starts a new FileSystemShell. @param argv array of arguments given by the user's input from the terminal
[ "Main", "method", "starts", "a", "new", "FileSystemShell", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/shell/src/main/java/alluxio/cli/fs/FileSystemShell.java#L54-L69
18,869
Alluxio/alluxio
core/server/worker/src/main/java/alluxio/worker/block/meta/StorageDirView.java
StorageDirView.getEvictableBlocks
public List<BlockMeta> getEvictableBlocks() { List<BlockMeta> filteredList = new ArrayList<>(); for (BlockMeta blockMeta : mDir.getBlocks()) { long blockId = blockMeta.getBlockId(); if (mManagerView.isBlockEvictable(blockId)) { filteredList.add(blockMeta); } } return filteredList; }
java
public List<BlockMeta> getEvictableBlocks() { List<BlockMeta> filteredList = new ArrayList<>(); for (BlockMeta blockMeta : mDir.getBlocks()) { long blockId = blockMeta.getBlockId(); if (mManagerView.isBlockEvictable(blockId)) { filteredList.add(blockMeta); } } return filteredList; }
[ "public", "List", "<", "BlockMeta", ">", "getEvictableBlocks", "(", ")", "{", "List", "<", "BlockMeta", ">", "filteredList", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "BlockMeta", "blockMeta", ":", "mDir", ".", "getBlocks", "(", ")", ")", "{", "long", "blockId", "=", "blockMeta", ".", "getBlockId", "(", ")", ";", "if", "(", "mManagerView", ".", "isBlockEvictable", "(", "blockId", ")", ")", "{", "filteredList", ".", "add", "(", "blockMeta", ")", ";", "}", "}", "return", "filteredList", ";", "}" ]
Gets a filtered list of block metadata, for blocks that are neither pinned or being blocked. @return a list of metadata for all evictable blocks
[ "Gets", "a", "filtered", "list", "of", "block", "metadata", "for", "blocks", "that", "are", "neither", "pinned", "or", "being", "blocked", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/worker/src/main/java/alluxio/worker/block/meta/StorageDirView.java#L76-L86
18,870
Alluxio/alluxio
core/server/worker/src/main/java/alluxio/worker/block/meta/StorageDirView.java
StorageDirView.getEvitableBytes
public long getEvitableBytes() { long bytes = 0; for (BlockMeta blockMeta : mDir.getBlocks()) { long blockId = blockMeta.getBlockId(); if (mManagerView.isBlockEvictable(blockId)) { bytes += blockMeta.getBlockSize(); } } return bytes; }
java
public long getEvitableBytes() { long bytes = 0; for (BlockMeta blockMeta : mDir.getBlocks()) { long blockId = blockMeta.getBlockId(); if (mManagerView.isBlockEvictable(blockId)) { bytes += blockMeta.getBlockSize(); } } return bytes; }
[ "public", "long", "getEvitableBytes", "(", ")", "{", "long", "bytes", "=", "0", ";", "for", "(", "BlockMeta", "blockMeta", ":", "mDir", ".", "getBlocks", "(", ")", ")", "{", "long", "blockId", "=", "blockMeta", ".", "getBlockId", "(", ")", ";", "if", "(", "mManagerView", ".", "isBlockEvictable", "(", "blockId", ")", ")", "{", "bytes", "+=", "blockMeta", ".", "getBlockSize", "(", ")", ";", "}", "}", "return", "bytes", ";", "}" ]
Gets evictable bytes for this dir, i.e., the total bytes of total evictable blocks. @return evictable bytes for this dir
[ "Gets", "evictable", "bytes", "for", "this", "dir", "i", ".", "e", ".", "the", "total", "bytes", "of", "total", "evictable", "blocks", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/worker/src/main/java/alluxio/worker/block/meta/StorageDirView.java#L120-L129
18,871
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.add
public void add(Supplier<JournalContext> journalContext, AlluxioURI alluxioUri, AlluxioURI ufsUri, long mountId, MountPOptions options) throws FileAlreadyExistsException, InvalidPathException { String alluxioPath = alluxioUri.getPath().isEmpty() ? "/" : alluxioUri.getPath(); LOG.info("Mounting {} at {}", ufsUri, alluxioPath); try (LockResource r = new LockResource(mWriteLock)) { if (mState.getMountTable().containsKey(alluxioPath)) { throw new FileAlreadyExistsException( ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(alluxioPath)); } // Make sure that the ufs path we're trying to mount is not a prefix // or suffix of any existing mount path. for (Map.Entry<String, MountInfo> entry : mState.getMountTable().entrySet()) { AlluxioURI mountedUfsUri = entry.getValue().getUfsUri(); if ((ufsUri.getScheme() == null || ufsUri.getScheme().equals(mountedUfsUri.getScheme())) && (ufsUri.getAuthority().toString().equals(mountedUfsUri.getAuthority().toString()))) { String ufsPath = ufsUri.getPath().isEmpty() ? "/" : ufsUri.getPath(); String mountedUfsPath = mountedUfsUri.getPath().isEmpty() ? "/" : mountedUfsUri.getPath(); if (PathUtils.hasPrefix(ufsPath, mountedUfsPath)) { throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER .getMessage(mountedUfsUri.toString(), ufsUri.toString())); } if (PathUtils.hasPrefix(mountedUfsPath, ufsPath)) { throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER .getMessage(ufsUri.toString(), mountedUfsUri.toString())); } } } Map<String, String> properties = options.getPropertiesMap(); mState.applyAndJournal(journalContext, AddMountPointEntry.newBuilder() .addAllProperties(properties.entrySet().stream() .map(entry -> StringPairEntry.newBuilder() .setKey(entry.getKey()).setValue(entry.getValue()).build()) .collect(Collectors.toList())) .setAlluxioPath(alluxioPath) .setMountId(mountId) .setReadOnly(options.getReadOnly()) .setShared(options.getShared()) .setUfsPath(ufsUri.toString()) .build()); } }
java
public void add(Supplier<JournalContext> journalContext, AlluxioURI alluxioUri, AlluxioURI ufsUri, long mountId, MountPOptions options) throws FileAlreadyExistsException, InvalidPathException { String alluxioPath = alluxioUri.getPath().isEmpty() ? "/" : alluxioUri.getPath(); LOG.info("Mounting {} at {}", ufsUri, alluxioPath); try (LockResource r = new LockResource(mWriteLock)) { if (mState.getMountTable().containsKey(alluxioPath)) { throw new FileAlreadyExistsException( ExceptionMessage.MOUNT_POINT_ALREADY_EXISTS.getMessage(alluxioPath)); } // Make sure that the ufs path we're trying to mount is not a prefix // or suffix of any existing mount path. for (Map.Entry<String, MountInfo> entry : mState.getMountTable().entrySet()) { AlluxioURI mountedUfsUri = entry.getValue().getUfsUri(); if ((ufsUri.getScheme() == null || ufsUri.getScheme().equals(mountedUfsUri.getScheme())) && (ufsUri.getAuthority().toString().equals(mountedUfsUri.getAuthority().toString()))) { String ufsPath = ufsUri.getPath().isEmpty() ? "/" : ufsUri.getPath(); String mountedUfsPath = mountedUfsUri.getPath().isEmpty() ? "/" : mountedUfsUri.getPath(); if (PathUtils.hasPrefix(ufsPath, mountedUfsPath)) { throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER .getMessage(mountedUfsUri.toString(), ufsUri.toString())); } if (PathUtils.hasPrefix(mountedUfsPath, ufsPath)) { throw new InvalidPathException(ExceptionMessage.MOUNT_POINT_PREFIX_OF_ANOTHER .getMessage(ufsUri.toString(), mountedUfsUri.toString())); } } } Map<String, String> properties = options.getPropertiesMap(); mState.applyAndJournal(journalContext, AddMountPointEntry.newBuilder() .addAllProperties(properties.entrySet().stream() .map(entry -> StringPairEntry.newBuilder() .setKey(entry.getKey()).setValue(entry.getValue()).build()) .collect(Collectors.toList())) .setAlluxioPath(alluxioPath) .setMountId(mountId) .setReadOnly(options.getReadOnly()) .setShared(options.getShared()) .setUfsPath(ufsUri.toString()) .build()); } }
[ "public", "void", "add", "(", "Supplier", "<", "JournalContext", ">", "journalContext", ",", "AlluxioURI", "alluxioUri", ",", "AlluxioURI", "ufsUri", ",", "long", "mountId", ",", "MountPOptions", "options", ")", "throws", "FileAlreadyExistsException", ",", "InvalidPathException", "{", "String", "alluxioPath", "=", "alluxioUri", ".", "getPath", "(", ")", ".", "isEmpty", "(", ")", "?", "\"/\"", ":", "alluxioUri", ".", "getPath", "(", ")", ";", "LOG", ".", "info", "(", "\"Mounting {} at {}\"", ",", "ufsUri", ",", "alluxioPath", ")", ";", "try", "(", "LockResource", "r", "=", "new", "LockResource", "(", "mWriteLock", ")", ")", "{", "if", "(", "mState", ".", "getMountTable", "(", ")", ".", "containsKey", "(", "alluxioPath", ")", ")", "{", "throw", "new", "FileAlreadyExistsException", "(", "ExceptionMessage", ".", "MOUNT_POINT_ALREADY_EXISTS", ".", "getMessage", "(", "alluxioPath", ")", ")", ";", "}", "// Make sure that the ufs path we're trying to mount is not a prefix", "// or suffix of any existing mount path.", "for", "(", "Map", ".", "Entry", "<", "String", ",", "MountInfo", ">", "entry", ":", "mState", ".", "getMountTable", "(", ")", ".", "entrySet", "(", ")", ")", "{", "AlluxioURI", "mountedUfsUri", "=", "entry", ".", "getValue", "(", ")", ".", "getUfsUri", "(", ")", ";", "if", "(", "(", "ufsUri", ".", "getScheme", "(", ")", "==", "null", "||", "ufsUri", ".", "getScheme", "(", ")", ".", "equals", "(", "mountedUfsUri", ".", "getScheme", "(", ")", ")", ")", "&&", "(", "ufsUri", ".", "getAuthority", "(", ")", ".", "toString", "(", ")", ".", "equals", "(", "mountedUfsUri", ".", "getAuthority", "(", ")", ".", "toString", "(", ")", ")", ")", ")", "{", "String", "ufsPath", "=", "ufsUri", ".", "getPath", "(", ")", ".", "isEmpty", "(", ")", "?", "\"/\"", ":", "ufsUri", ".", "getPath", "(", ")", ";", "String", "mountedUfsPath", "=", "mountedUfsUri", ".", "getPath", "(", ")", ".", "isEmpty", "(", ")", "?", "\"/\"", ":", "mountedUfsUri", ".", "getPath", "(", ")", ";", "if", "(", "PathUtils", ".", "hasPrefix", "(", "ufsPath", ",", "mountedUfsPath", ")", ")", "{", "throw", "new", "InvalidPathException", "(", "ExceptionMessage", ".", "MOUNT_POINT_PREFIX_OF_ANOTHER", ".", "getMessage", "(", "mountedUfsUri", ".", "toString", "(", ")", ",", "ufsUri", ".", "toString", "(", ")", ")", ")", ";", "}", "if", "(", "PathUtils", ".", "hasPrefix", "(", "mountedUfsPath", ",", "ufsPath", ")", ")", "{", "throw", "new", "InvalidPathException", "(", "ExceptionMessage", ".", "MOUNT_POINT_PREFIX_OF_ANOTHER", ".", "getMessage", "(", "ufsUri", ".", "toString", "(", ")", ",", "mountedUfsUri", ".", "toString", "(", ")", ")", ")", ";", "}", "}", "}", "Map", "<", "String", ",", "String", ">", "properties", "=", "options", ".", "getPropertiesMap", "(", ")", ";", "mState", ".", "applyAndJournal", "(", "journalContext", ",", "AddMountPointEntry", ".", "newBuilder", "(", ")", ".", "addAllProperties", "(", "properties", ".", "entrySet", "(", ")", ".", "stream", "(", ")", ".", "map", "(", "entry", "->", "StringPairEntry", ".", "newBuilder", "(", ")", ".", "setKey", "(", "entry", ".", "getKey", "(", ")", ")", ".", "setValue", "(", "entry", ".", "getValue", "(", ")", ")", ".", "build", "(", ")", ")", ".", "collect", "(", "Collectors", ".", "toList", "(", ")", ")", ")", ".", "setAlluxioPath", "(", "alluxioPath", ")", ".", "setMountId", "(", "mountId", ")", ".", "setReadOnly", "(", "options", ".", "getReadOnly", "(", ")", ")", ".", "setShared", "(", "options", ".", "getShared", "(", ")", ")", ".", "setUfsPath", "(", "ufsUri", ".", "toString", "(", ")", ")", ".", "build", "(", ")", ")", ";", "}", "}" ]
Mounts the given UFS path at the given Alluxio path. The Alluxio path should not be nested under an existing mount point. @param journalContext the journal context @param alluxioUri an Alluxio path URI @param ufsUri a UFS path URI @param mountId the mount id @param options the mount options @throws FileAlreadyExistsException if the mount point already exists @throws InvalidPathException if an invalid path is encountered
[ "Mounts", "the", "given", "UFS", "path", "at", "the", "given", "Alluxio", "path", ".", "The", "Alluxio", "path", "should", "not", "be", "nested", "under", "an", "existing", "mount", "point", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L106-L148
18,872
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.delete
public boolean delete(Supplier<JournalContext> journalContext, AlluxioURI uri) { String path = uri.getPath(); LOG.info("Unmounting {}", path); if (path.equals(ROOT)) { LOG.warn("Cannot unmount the root mount point."); return false; } try (LockResource r = new LockResource(mWriteLock)) { if (mState.getMountTable().containsKey(path)) { // check if the path contains another nested mount point for (String mountPath : mState.getMountTable().keySet()) { try { if (PathUtils.hasPrefix(mountPath, path) && (!path.equals(mountPath))) { LOG.warn("The path to unmount {} contains another nested mountpoint {}", path, mountPath); return false; } } catch (InvalidPathException e) { LOG.warn("Invalid path {} encountered when checking for nested mount point", path); } } mUfsManager.removeMount(mState.getMountTable().get(path).getMountId()); mState.applyAndJournal(journalContext, DeleteMountPointEntry.newBuilder().setAlluxioPath(path).build()); return true; } LOG.warn("Mount point {} does not exist.", path); return false; } }
java
public boolean delete(Supplier<JournalContext> journalContext, AlluxioURI uri) { String path = uri.getPath(); LOG.info("Unmounting {}", path); if (path.equals(ROOT)) { LOG.warn("Cannot unmount the root mount point."); return false; } try (LockResource r = new LockResource(mWriteLock)) { if (mState.getMountTable().containsKey(path)) { // check if the path contains another nested mount point for (String mountPath : mState.getMountTable().keySet()) { try { if (PathUtils.hasPrefix(mountPath, path) && (!path.equals(mountPath))) { LOG.warn("The path to unmount {} contains another nested mountpoint {}", path, mountPath); return false; } } catch (InvalidPathException e) { LOG.warn("Invalid path {} encountered when checking for nested mount point", path); } } mUfsManager.removeMount(mState.getMountTable().get(path).getMountId()); mState.applyAndJournal(journalContext, DeleteMountPointEntry.newBuilder().setAlluxioPath(path).build()); return true; } LOG.warn("Mount point {} does not exist.", path); return false; } }
[ "public", "boolean", "delete", "(", "Supplier", "<", "JournalContext", ">", "journalContext", ",", "AlluxioURI", "uri", ")", "{", "String", "path", "=", "uri", ".", "getPath", "(", ")", ";", "LOG", ".", "info", "(", "\"Unmounting {}\"", ",", "path", ")", ";", "if", "(", "path", ".", "equals", "(", "ROOT", ")", ")", "{", "LOG", ".", "warn", "(", "\"Cannot unmount the root mount point.\"", ")", ";", "return", "false", ";", "}", "try", "(", "LockResource", "r", "=", "new", "LockResource", "(", "mWriteLock", ")", ")", "{", "if", "(", "mState", ".", "getMountTable", "(", ")", ".", "containsKey", "(", "path", ")", ")", "{", "// check if the path contains another nested mount point", "for", "(", "String", "mountPath", ":", "mState", ".", "getMountTable", "(", ")", ".", "keySet", "(", ")", ")", "{", "try", "{", "if", "(", "PathUtils", ".", "hasPrefix", "(", "mountPath", ",", "path", ")", "&&", "(", "!", "path", ".", "equals", "(", "mountPath", ")", ")", ")", "{", "LOG", ".", "warn", "(", "\"The path to unmount {} contains another nested mountpoint {}\"", ",", "path", ",", "mountPath", ")", ";", "return", "false", ";", "}", "}", "catch", "(", "InvalidPathException", "e", ")", "{", "LOG", ".", "warn", "(", "\"Invalid path {} encountered when checking for nested mount point\"", ",", "path", ")", ";", "}", "}", "mUfsManager", ".", "removeMount", "(", "mState", ".", "getMountTable", "(", ")", ".", "get", "(", "path", ")", ".", "getMountId", "(", ")", ")", ";", "mState", ".", "applyAndJournal", "(", "journalContext", ",", "DeleteMountPointEntry", ".", "newBuilder", "(", ")", ".", "setAlluxioPath", "(", "path", ")", ".", "build", "(", ")", ")", ";", "return", "true", ";", "}", "LOG", ".", "warn", "(", "\"Mount point {} does not exist.\"", ",", "path", ")", ";", "return", "false", ";", "}", "}" ]
Unmounts the given Alluxio path. The path should match an existing mount point. @param journalContext journal context @param uri an Alluxio path URI @return whether the operation succeeded or not
[ "Unmounts", "the", "given", "Alluxio", "path", ".", "The", "path", "should", "match", "an", "existing", "mount", "point", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L157-L187
18,873
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.getMountPoint
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; } }
java
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; } }
[ "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", ";", "}", "}" ]
Returns the closest ancestor mount point the given path is nested under. @param uri an Alluxio path URI @return mount point the given Alluxio path is nested under @throws InvalidPathException if an invalid path is encountered
[ "Returns", "the", "closest", "ancestor", "mount", "point", "the", "given", "path", "is", "nested", "under", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L196-L211
18,874
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.getMountTable
public Map<String, MountInfo> getMountTable() { try (LockResource r = new LockResource(mReadLock)) { return new HashMap<>(mState.getMountTable()); } }
java
public Map<String, MountInfo> getMountTable() { try (LockResource r = new LockResource(mReadLock)) { return new HashMap<>(mState.getMountTable()); } }
[ "public", "Map", "<", "String", ",", "MountInfo", ">", "getMountTable", "(", ")", "{", "try", "(", "LockResource", "r", "=", "new", "LockResource", "(", "mReadLock", ")", ")", "{", "return", "new", "HashMap", "<>", "(", "mState", ".", "getMountTable", "(", ")", ")", ";", "}", "}" ]
Returns a copy of the current mount table, the mount table is a map from Alluxio file system URIs to the corresponding mount point information. @return a copy of the current mount table
[ "Returns", "a", "copy", "of", "the", "current", "mount", "table", "the", "mount", "table", "is", "a", "map", "from", "Alluxio", "file", "system", "URIs", "to", "the", "corresponding", "mount", "point", "information", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L219-L223
18,875
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.reverseResolve
public AlluxioURI reverseResolve(AlluxioURI ufsUri) { AlluxioURI returnVal = null; for (Map.Entry<String, MountInfo> mountInfoEntry : getMountTable().entrySet()) { try { if (mountInfoEntry.getValue().getUfsUri().isAncestorOf(ufsUri)) { returnVal = reverseResolve(mountInfoEntry.getValue().getAlluxioUri(), mountInfoEntry.getValue().getUfsUri(), ufsUri); } } catch (InvalidPathException | RuntimeException e) { LOG.info(Throwables.getStackTraceAsString(e)); // expected when ufsUri does not belong to this particular mountPoint } if (returnVal != null) { return returnVal; } } return null; }
java
public AlluxioURI reverseResolve(AlluxioURI ufsUri) { AlluxioURI returnVal = null; for (Map.Entry<String, MountInfo> mountInfoEntry : getMountTable().entrySet()) { try { if (mountInfoEntry.getValue().getUfsUri().isAncestorOf(ufsUri)) { returnVal = reverseResolve(mountInfoEntry.getValue().getAlluxioUri(), mountInfoEntry.getValue().getUfsUri(), ufsUri); } } catch (InvalidPathException | RuntimeException e) { LOG.info(Throwables.getStackTraceAsString(e)); // expected when ufsUri does not belong to this particular mountPoint } if (returnVal != null) { return returnVal; } } return null; }
[ "public", "AlluxioURI", "reverseResolve", "(", "AlluxioURI", "ufsUri", ")", "{", "AlluxioURI", "returnVal", "=", "null", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "MountInfo", ">", "mountInfoEntry", ":", "getMountTable", "(", ")", ".", "entrySet", "(", ")", ")", "{", "try", "{", "if", "(", "mountInfoEntry", ".", "getValue", "(", ")", ".", "getUfsUri", "(", ")", ".", "isAncestorOf", "(", "ufsUri", ")", ")", "{", "returnVal", "=", "reverseResolve", "(", "mountInfoEntry", ".", "getValue", "(", ")", ".", "getAlluxioUri", "(", ")", ",", "mountInfoEntry", ".", "getValue", "(", ")", ".", "getUfsUri", "(", ")", ",", "ufsUri", ")", ";", "}", "}", "catch", "(", "InvalidPathException", "|", "RuntimeException", "e", ")", "{", "LOG", ".", "info", "(", "Throwables", ".", "getStackTraceAsString", "(", "e", ")", ")", ";", "// expected when ufsUri does not belong to this particular mountPoint", "}", "if", "(", "returnVal", "!=", "null", ")", "{", "return", "returnVal", ";", "}", "}", "return", "null", ";", "}" ]
REsolves the given Ufs path. If the given UFs path is mounted in Alluxio space, it returns the associated Alluxio path. @param ufsUri an Ufs path URI @return an Alluxio path URI
[ "REsolves", "the", "given", "Ufs", "path", ".", "If", "the", "given", "UFs", "path", "is", "mounted", "in", "Alluxio", "space", "it", "returns", "the", "associated", "Alluxio", "path", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L272-L289
18,876
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.getUfsClient
public UfsManager.UfsClient getUfsClient(long mountId) { try { return mUfsManager.get(mountId); } catch (NotFoundException | UnavailableException e) { LOG.warn("failed to get ufsclient for mountid {}, exception {}", mountId, e); } return null; }
java
public UfsManager.UfsClient getUfsClient(long mountId) { try { return mUfsManager.get(mountId); } catch (NotFoundException | UnavailableException e) { LOG.warn("failed to get ufsclient for mountid {}, exception {}", mountId, e); } return null; }
[ "public", "UfsManager", ".", "UfsClient", "getUfsClient", "(", "long", "mountId", ")", "{", "try", "{", "return", "mUfsManager", ".", "get", "(", "mountId", ")", ";", "}", "catch", "(", "NotFoundException", "|", "UnavailableException", "e", ")", "{", "LOG", ".", "warn", "(", "\"failed to get ufsclient for mountid {}, exception {}\"", ",", "mountId", ",", "e", ")", ";", "}", "return", "null", ";", "}" ]
Get the associated ufs client with the mount id. @param mountId mount id to look up ufs client @return ufsClient
[ "Get", "the", "associated", "ufs", "client", "with", "the", "mount", "id", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L296-L303
18,877
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.resolve
public Resolution resolve(AlluxioURI uri) throws InvalidPathException { try (LockResource r = new LockResource(mReadLock)) { String path = uri.getPath(); LOG.debug("Resolving {}", path); // This will re-acquire the read lock, but that is allowed. String mountPoint = getMountPoint(uri); if (mountPoint != null) { MountInfo info = mState.getMountTable().get(mountPoint); AlluxioURI ufsUri = info.getUfsUri(); UfsManager.UfsClient ufsClient; AlluxioURI resolvedUri; try { ufsClient = mUfsManager.get(info.getMountId()); try (CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); resolvedUri = ufs.resolveUri(ufsUri, path.substring(mountPoint.length())); } } catch (NotFoundException | UnavailableException e) { throw new RuntimeException( String.format("No UFS information for %s for mount Id %d, we should never reach here", uri, info.getMountId()), e); } return new Resolution(resolvedUri, ufsClient, info.getOptions().getShared(), info.getMountId()); } // TODO(binfan): throw exception as we should never reach here return new Resolution(uri, null, false, IdUtils.INVALID_MOUNT_ID); } }
java
public Resolution resolve(AlluxioURI uri) throws InvalidPathException { try (LockResource r = new LockResource(mReadLock)) { String path = uri.getPath(); LOG.debug("Resolving {}", path); // This will re-acquire the read lock, but that is allowed. String mountPoint = getMountPoint(uri); if (mountPoint != null) { MountInfo info = mState.getMountTable().get(mountPoint); AlluxioURI ufsUri = info.getUfsUri(); UfsManager.UfsClient ufsClient; AlluxioURI resolvedUri; try { ufsClient = mUfsManager.get(info.getMountId()); try (CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); resolvedUri = ufs.resolveUri(ufsUri, path.substring(mountPoint.length())); } } catch (NotFoundException | UnavailableException e) { throw new RuntimeException( String.format("No UFS information for %s for mount Id %d, we should never reach here", uri, info.getMountId()), e); } return new Resolution(resolvedUri, ufsClient, info.getOptions().getShared(), info.getMountId()); } // TODO(binfan): throw exception as we should never reach here return new Resolution(uri, null, false, IdUtils.INVALID_MOUNT_ID); } }
[ "public", "Resolution", "resolve", "(", "AlluxioURI", "uri", ")", "throws", "InvalidPathException", "{", "try", "(", "LockResource", "r", "=", "new", "LockResource", "(", "mReadLock", ")", ")", "{", "String", "path", "=", "uri", ".", "getPath", "(", ")", ";", "LOG", ".", "debug", "(", "\"Resolving {}\"", ",", "path", ")", ";", "// This will re-acquire the read lock, but that is allowed.", "String", "mountPoint", "=", "getMountPoint", "(", "uri", ")", ";", "if", "(", "mountPoint", "!=", "null", ")", "{", "MountInfo", "info", "=", "mState", ".", "getMountTable", "(", ")", ".", "get", "(", "mountPoint", ")", ";", "AlluxioURI", "ufsUri", "=", "info", ".", "getUfsUri", "(", ")", ";", "UfsManager", ".", "UfsClient", "ufsClient", ";", "AlluxioURI", "resolvedUri", ";", "try", "{", "ufsClient", "=", "mUfsManager", ".", "get", "(", "info", ".", "getMountId", "(", ")", ")", ";", "try", "(", "CloseableResource", "<", "UnderFileSystem", ">", "ufsResource", "=", "ufsClient", ".", "acquireUfsResource", "(", ")", ")", "{", "UnderFileSystem", "ufs", "=", "ufsResource", ".", "get", "(", ")", ";", "resolvedUri", "=", "ufs", ".", "resolveUri", "(", "ufsUri", ",", "path", ".", "substring", "(", "mountPoint", ".", "length", "(", ")", ")", ")", ";", "}", "}", "catch", "(", "NotFoundException", "|", "UnavailableException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "String", ".", "format", "(", "\"No UFS information for %s for mount Id %d, we should never reach here\"", ",", "uri", ",", "info", ".", "getMountId", "(", ")", ")", ",", "e", ")", ";", "}", "return", "new", "Resolution", "(", "resolvedUri", ",", "ufsClient", ",", "info", ".", "getOptions", "(", ")", ".", "getShared", "(", ")", ",", "info", ".", "getMountId", "(", ")", ")", ";", "}", "// TODO(binfan): throw exception as we should never reach here", "return", "new", "Resolution", "(", "uri", ",", "null", ",", "false", ",", "IdUtils", ".", "INVALID_MOUNT_ID", ")", ";", "}", "}" ]
Resolves the given Alluxio path. If the given Alluxio path is nested under a mount point, the resolution maps the Alluxio path to the corresponding UFS path. Otherwise, the resolution is a no-op. @param uri an Alluxio path URI @return the {@link Resolution} representing the UFS path @throws InvalidPathException if an invalid path is encountered
[ "Resolves", "the", "given", "Alluxio", "path", ".", "If", "the", "given", "Alluxio", "path", "is", "nested", "under", "a", "mount", "point", "the", "resolution", "maps", "the", "Alluxio", "path", "to", "the", "corresponding", "UFS", "path", ".", "Otherwise", "the", "resolution", "is", "a", "no", "-", "op", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L314-L342
18,878
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java
MountTable.checkUnderWritableMountPoint
public void checkUnderWritableMountPoint(AlluxioURI alluxioUri) throws InvalidPathException, AccessControlException { try (LockResource r = new LockResource(mReadLock)) { // This will re-acquire the read lock, but that is allowed. String mountPoint = getMountPoint(alluxioUri); MountInfo mountInfo = mState.getMountTable().get(mountPoint); if (mountInfo.getOptions().getReadOnly()) { throw new AccessControlException(ExceptionMessage.MOUNT_READONLY, alluxioUri, mountPoint); } } }
java
public void checkUnderWritableMountPoint(AlluxioURI alluxioUri) throws InvalidPathException, AccessControlException { try (LockResource r = new LockResource(mReadLock)) { // This will re-acquire the read lock, but that is allowed. String mountPoint = getMountPoint(alluxioUri); MountInfo mountInfo = mState.getMountTable().get(mountPoint); if (mountInfo.getOptions().getReadOnly()) { throw new AccessControlException(ExceptionMessage.MOUNT_READONLY, alluxioUri, mountPoint); } } }
[ "public", "void", "checkUnderWritableMountPoint", "(", "AlluxioURI", "alluxioUri", ")", "throws", "InvalidPathException", ",", "AccessControlException", "{", "try", "(", "LockResource", "r", "=", "new", "LockResource", "(", "mReadLock", ")", ")", "{", "// This will re-acquire the read lock, but that is allowed.", "String", "mountPoint", "=", "getMountPoint", "(", "alluxioUri", ")", ";", "MountInfo", "mountInfo", "=", "mState", ".", "getMountTable", "(", ")", ".", "get", "(", "mountPoint", ")", ";", "if", "(", "mountInfo", ".", "getOptions", "(", ")", ".", "getReadOnly", "(", ")", ")", "{", "throw", "new", "AccessControlException", "(", "ExceptionMessage", ".", "MOUNT_READONLY", ",", "alluxioUri", ",", "mountPoint", ")", ";", "}", "}", "}" ]
Checks to see if a write operation is allowed for the specified Alluxio path, by determining if it is under a readonly mount point. @param alluxioUri an Alluxio path URI @throws InvalidPathException if the Alluxio path is invalid @throws AccessControlException if the Alluxio path is under a readonly mount point
[ "Checks", "to", "see", "if", "a", "write", "operation", "is", "allowed", "for", "the", "specified", "Alluxio", "path", "by", "determining", "if", "it", "is", "under", "a", "readonly", "mount", "point", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/file/meta/MountTable.java#L352-L362
18,879
Alluxio/alluxio
core/common/src/main/java/alluxio/heartbeat/ScheduledTimer.java
ScheduledTimer.schedule
protected void schedule() { try (LockResource r = new LockResource(mLock)) { Preconditions.checkState(!mScheduled, "Called schedule twice without waiting for any ticks"); mScheduled = true; mTickCondition.signal(); HeartbeatScheduler.removeTimer(this); } }
java
protected void schedule() { try (LockResource r = new LockResource(mLock)) { Preconditions.checkState(!mScheduled, "Called schedule twice without waiting for any ticks"); mScheduled = true; mTickCondition.signal(); HeartbeatScheduler.removeTimer(this); } }
[ "protected", "void", "schedule", "(", ")", "{", "try", "(", "LockResource", "r", "=", "new", "LockResource", "(", "mLock", ")", ")", "{", "Preconditions", ".", "checkState", "(", "!", "mScheduled", ",", "\"Called schedule twice without waiting for any ticks\"", ")", ";", "mScheduled", "=", "true", ";", "mTickCondition", ".", "signal", "(", ")", ";", "HeartbeatScheduler", ".", "removeTimer", "(", "this", ")", ";", "}", "}" ]
Schedules execution of the heartbeat.
[ "Schedules", "execution", "of", "the", "heartbeat", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/heartbeat/ScheduledTimer.java#L71-L78
18,880
Alluxio/alluxio
core/common/src/main/java/alluxio/heartbeat/ScheduledTimer.java
ScheduledTimer.tick
public void tick() throws InterruptedException { try (LockResource r = new LockResource(mLock)) { HeartbeatScheduler.addTimer(this); // Wait in a loop to handle spurious wakeups while (!mScheduled) { mTickCondition.await(); } mScheduled = false; } }
java
public void tick() throws InterruptedException { try (LockResource r = new LockResource(mLock)) { HeartbeatScheduler.addTimer(this); // Wait in a loop to handle spurious wakeups while (!mScheduled) { mTickCondition.await(); } mScheduled = false; } }
[ "public", "void", "tick", "(", ")", "throws", "InterruptedException", "{", "try", "(", "LockResource", "r", "=", "new", "LockResource", "(", "mLock", ")", ")", "{", "HeartbeatScheduler", ".", "addTimer", "(", "this", ")", ";", "// Wait in a loop to handle spurious wakeups", "while", "(", "!", "mScheduled", ")", "{", "mTickCondition", ".", "await", "(", ")", ";", "}", "mScheduled", "=", "false", ";", "}", "}" ]
Waits until the heartbeat is scheduled for execution. @throws InterruptedException if the thread is interrupted while waiting
[ "Waits", "until", "the", "heartbeat", "is", "scheduled", "for", "execution", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/heartbeat/ScheduledTimer.java#L85-L95
18,881
Alluxio/alluxio
core/server/worker/src/main/java/alluxio/worker/block/BlockMetadataManagerView.java
BlockMetadataManagerView.isBlockMarked
public boolean isBlockMarked(long blockId) { for (StorageTierView tierView : mTierViews) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.isMarkedToMoveOut(blockId)) { return true; } } } return false; }
java
public boolean isBlockMarked(long blockId) { for (StorageTierView tierView : mTierViews) { for (StorageDirView dirView : tierView.getDirViews()) { if (dirView.isMarkedToMoveOut(blockId)) { return true; } } } return false; }
[ "public", "boolean", "isBlockMarked", "(", "long", "blockId", ")", "{", "for", "(", "StorageTierView", "tierView", ":", "mTierViews", ")", "{", "for", "(", "StorageDirView", "dirView", ":", "tierView", ".", "getDirViews", "(", ")", ")", "{", "if", "(", "dirView", ".", "isMarkedToMoveOut", "(", "blockId", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Tests if the block is marked to move out of its current dir in this view. @param blockId the id of the block @return boolean, true if the block is marked to move out
[ "Tests", "if", "the", "block", "is", "marked", "to", "move", "out", "of", "its", "current", "dir", "in", "this", "view", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/worker/src/main/java/alluxio/worker/block/BlockMetadataManagerView.java#L135-L144
18,882
Alluxio/alluxio
core/server/worker/src/main/java/alluxio/worker/block/BlockMetadataManagerView.java
BlockMetadataManagerView.getNextTier
@Nullable public StorageTierView getNextTier(StorageTierView tierView) { int nextOrdinal = tierView.getTierViewOrdinal() + 1; if (nextOrdinal < mTierViews.size()) { return mTierViews.get(nextOrdinal); } return null; }
java
@Nullable public StorageTierView getNextTier(StorageTierView tierView) { int nextOrdinal = tierView.getTierViewOrdinal() + 1; if (nextOrdinal < mTierViews.size()) { return mTierViews.get(nextOrdinal); } return null; }
[ "@", "Nullable", "public", "StorageTierView", "getNextTier", "(", "StorageTierView", "tierView", ")", "{", "int", "nextOrdinal", "=", "tierView", ".", "getTierViewOrdinal", "(", ")", "+", "1", ";", "if", "(", "nextOrdinal", "<", "mTierViews", ".", "size", "(", ")", ")", "{", "return", "mTierViews", ".", "get", "(", "nextOrdinal", ")", ";", "}", "return", "null", ";", "}" ]
Gets the next storage tier view. @param tierView the storage tier view @return the next storage tier view, null if this is the last tier view
[ "Gets", "the", "next", "storage", "tier", "view", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/worker/src/main/java/alluxio/worker/block/BlockMetadataManagerView.java#L190-L197
18,883
Alluxio/alluxio
core/client/fs/src/main/java/alluxio/client/block/stream/GrpcDataWriter.java
GrpcDataWriter.writeFallbackInitRequest
public void writeFallbackInitRequest(long pos) throws IOException { Preconditions.checkState(mPartialRequest.getType() == RequestType.UFS_FALLBACK_BLOCK); Protocol.CreateUfsBlockOptions ufsBlockOptions = mPartialRequest.getCreateUfsBlockOptions() .toBuilder().setBytesInBlockStore(pos).build(); WriteRequest writeRequest = WriteRequest.newBuilder().setCommand( mPartialRequest.toBuilder().setOffset(0).setCreateUfsBlockOptions(ufsBlockOptions)) .build(); mPosToQueue = pos; mStream.send(writeRequest, mDataTimeoutMs); }
java
public void writeFallbackInitRequest(long pos) throws IOException { Preconditions.checkState(mPartialRequest.getType() == RequestType.UFS_FALLBACK_BLOCK); Protocol.CreateUfsBlockOptions ufsBlockOptions = mPartialRequest.getCreateUfsBlockOptions() .toBuilder().setBytesInBlockStore(pos).build(); WriteRequest writeRequest = WriteRequest.newBuilder().setCommand( mPartialRequest.toBuilder().setOffset(0).setCreateUfsBlockOptions(ufsBlockOptions)) .build(); mPosToQueue = pos; mStream.send(writeRequest, mDataTimeoutMs); }
[ "public", "void", "writeFallbackInitRequest", "(", "long", "pos", ")", "throws", "IOException", "{", "Preconditions", ".", "checkState", "(", "mPartialRequest", ".", "getType", "(", ")", "==", "RequestType", ".", "UFS_FALLBACK_BLOCK", ")", ";", "Protocol", ".", "CreateUfsBlockOptions", "ufsBlockOptions", "=", "mPartialRequest", ".", "getCreateUfsBlockOptions", "(", ")", ".", "toBuilder", "(", ")", ".", "setBytesInBlockStore", "(", "pos", ")", ".", "build", "(", ")", ";", "WriteRequest", "writeRequest", "=", "WriteRequest", ".", "newBuilder", "(", ")", ".", "setCommand", "(", "mPartialRequest", ".", "toBuilder", "(", ")", ".", "setOffset", "(", "0", ")", ".", "setCreateUfsBlockOptions", "(", "ufsBlockOptions", ")", ")", ".", "build", "(", ")", ";", "mPosToQueue", "=", "pos", ";", "mStream", ".", "send", "(", "writeRequest", ",", "mDataTimeoutMs", ")", ";", "}" ]
Notifies the server UFS fallback endpoint to start writing a new block by resuming the given number of bytes from block store. @param pos number of bytes already written to block store
[ "Notifies", "the", "server", "UFS", "fallback", "endpoint", "to", "start", "writing", "a", "new", "block", "by", "resuming", "the", "given", "number", "of", "bytes", "from", "block", "store", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/client/fs/src/main/java/alluxio/client/block/stream/GrpcDataWriter.java#L208-L217
18,884
Alluxio/alluxio
core/common/src/main/java/alluxio/wire/WorkerWebUIBlockInfo.java
WorkerWebUIBlockInfo.setFileBlocksOnTier
public WorkerWebUIBlockInfo setFileBlocksOnTier( List<ImmutablePair<String, List<UIFileBlockInfo>>> FileBlocksOnTier) { mFileBlocksOnTier = FileBlocksOnTier; return this; }
java
public WorkerWebUIBlockInfo setFileBlocksOnTier( List<ImmutablePair<String, List<UIFileBlockInfo>>> FileBlocksOnTier) { mFileBlocksOnTier = FileBlocksOnTier; return this; }
[ "public", "WorkerWebUIBlockInfo", "setFileBlocksOnTier", "(", "List", "<", "ImmutablePair", "<", "String", ",", "List", "<", "UIFileBlockInfo", ">", ">", ">", "FileBlocksOnTier", ")", "{", "mFileBlocksOnTier", "=", "FileBlocksOnTier", ";", "return", "this", ";", "}" ]
Sets file blocks on tier. @param FileBlocksOnTier the file blocks on tier @return the file blocks on tier
[ "Sets", "file", "blocks", "on", "tier", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/wire/WorkerWebUIBlockInfo.java#L147-L151
18,885
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.startSinksFromConfig
public static synchronized void startSinksFromConfig(MetricsConfig config) { if (sSinks != null) { LOG.info("Sinks have already been started."); return; } LOG.info("Starting sinks with config: {}.", config); sSinks = new ArrayList<>(); Map<String, Properties> sinkConfigs = MetricsConfig.subProperties(config.getProperties(), SINK_REGEX); for (Map.Entry<String, Properties> entry : sinkConfigs.entrySet()) { String classPath = entry.getValue().getProperty("class"); if (classPath != null) { LOG.info("Starting sink {}.", classPath); try { Sink sink = (Sink) Class.forName(classPath).getConstructor(Properties.class, MetricRegistry.class) .newInstance(entry.getValue(), METRIC_REGISTRY); sink.start(); sSinks.add(sink); } catch (Exception e) { LOG.error("Sink class {} cannot be instantiated", classPath, e); } } } }
java
public static synchronized void startSinksFromConfig(MetricsConfig config) { if (sSinks != null) { LOG.info("Sinks have already been started."); return; } LOG.info("Starting sinks with config: {}.", config); sSinks = new ArrayList<>(); Map<String, Properties> sinkConfigs = MetricsConfig.subProperties(config.getProperties(), SINK_REGEX); for (Map.Entry<String, Properties> entry : sinkConfigs.entrySet()) { String classPath = entry.getValue().getProperty("class"); if (classPath != null) { LOG.info("Starting sink {}.", classPath); try { Sink sink = (Sink) Class.forName(classPath).getConstructor(Properties.class, MetricRegistry.class) .newInstance(entry.getValue(), METRIC_REGISTRY); sink.start(); sSinks.add(sink); } catch (Exception e) { LOG.error("Sink class {} cannot be instantiated", classPath, e); } } } }
[ "public", "static", "synchronized", "void", "startSinksFromConfig", "(", "MetricsConfig", "config", ")", "{", "if", "(", "sSinks", "!=", "null", ")", "{", "LOG", ".", "info", "(", "\"Sinks have already been started.\"", ")", ";", "return", ";", "}", "LOG", ".", "info", "(", "\"Starting sinks with config: {}.\"", ",", "config", ")", ";", "sSinks", "=", "new", "ArrayList", "<>", "(", ")", ";", "Map", "<", "String", ",", "Properties", ">", "sinkConfigs", "=", "MetricsConfig", ".", "subProperties", "(", "config", ".", "getProperties", "(", ")", ",", "SINK_REGEX", ")", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "Properties", ">", "entry", ":", "sinkConfigs", ".", "entrySet", "(", ")", ")", "{", "String", "classPath", "=", "entry", ".", "getValue", "(", ")", ".", "getProperty", "(", "\"class\"", ")", ";", "if", "(", "classPath", "!=", "null", ")", "{", "LOG", ".", "info", "(", "\"Starting sink {}.\"", ",", "classPath", ")", ";", "try", "{", "Sink", "sink", "=", "(", "Sink", ")", "Class", ".", "forName", "(", "classPath", ")", ".", "getConstructor", "(", "Properties", ".", "class", ",", "MetricRegistry", ".", "class", ")", ".", "newInstance", "(", "entry", ".", "getValue", "(", ")", ",", "METRIC_REGISTRY", ")", ";", "sink", ".", "start", "(", ")", ";", "sSinks", ".", "add", "(", "sink", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "LOG", ".", "error", "(", "\"Sink class {} cannot be instantiated\"", ",", "classPath", ",", "e", ")", ";", "}", "}", "}", "}" ]
Starts sinks from a given metrics configuration. This is made public for unit test. @param config the metrics config
[ "Starts", "sinks", "from", "a", "given", "metrics", "configuration", ".", "This", "is", "made", "public", "for", "unit", "test", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L150-L174
18,886
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.stopSinks
public static synchronized void stopSinks() { if (sSinks != null) { for (Sink sink : sSinks) { sink.stop(); } } sSinks = null; }
java
public static synchronized void stopSinks() { if (sSinks != null) { for (Sink sink : sSinks) { sink.stop(); } } sSinks = null; }
[ "public", "static", "synchronized", "void", "stopSinks", "(", ")", "{", "if", "(", "sSinks", "!=", "null", ")", "{", "for", "(", "Sink", "sink", ":", "sSinks", ")", "{", "sink", ".", "stop", "(", ")", ";", "}", "}", "sSinks", "=", "null", ";", "}" ]
Stops all the sinks.
[ "Stops", "all", "the", "sinks", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L179-L186
18,887
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.getMetricName
public static String getMetricName(String name) { switch (CommonUtils.PROCESS_TYPE.get()) { case CLIENT: return getClientMetricName(name); case MASTER: return getMasterMetricName(name); case PROXY: return getProxyMetricName(name); case WORKER: return getWorkerMetricName(name); case JOB_MASTER: return getJobMasterMetricName(name); case JOB_WORKER: return getJobWorkerMetricName(name); default: throw new IllegalStateException("Unknown process type"); } }
java
public static String getMetricName(String name) { switch (CommonUtils.PROCESS_TYPE.get()) { case CLIENT: return getClientMetricName(name); case MASTER: return getMasterMetricName(name); case PROXY: return getProxyMetricName(name); case WORKER: return getWorkerMetricName(name); case JOB_MASTER: return getJobMasterMetricName(name); case JOB_WORKER: return getJobWorkerMetricName(name); default: throw new IllegalStateException("Unknown process type"); } }
[ "public", "static", "String", "getMetricName", "(", "String", "name", ")", "{", "switch", "(", "CommonUtils", ".", "PROCESS_TYPE", ".", "get", "(", ")", ")", "{", "case", "CLIENT", ":", "return", "getClientMetricName", "(", "name", ")", ";", "case", "MASTER", ":", "return", "getMasterMetricName", "(", "name", ")", ";", "case", "PROXY", ":", "return", "getProxyMetricName", "(", "name", ")", ";", "case", "WORKER", ":", "return", "getWorkerMetricName", "(", "name", ")", ";", "case", "JOB_MASTER", ":", "return", "getJobMasterMetricName", "(", "name", ")", ";", "case", "JOB_WORKER", ":", "return", "getJobWorkerMetricName", "(", "name", ")", ";", "default", ":", "throw", "new", "IllegalStateException", "(", "\"Unknown process type\"", ")", ";", "}", "}" ]
Converts a simple string to a qualified metric name based on the process type. @param name the name of the metric @return the metric with instance and id tags
[ "Converts", "a", "simple", "string", "to", "a", "qualified", "metric", "name", "based", "on", "the", "process", "type", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L205-L222
18,888
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.getMasterMetricName
private static String getMasterMetricName(String name) { String result = CACHED_METRICS.get(name); if (result != null) { return result; } return CACHED_METRICS.computeIfAbsent(name, n -> InstanceType.MASTER.toString() + "." + name); }
java
private static String getMasterMetricName(String name) { String result = CACHED_METRICS.get(name); if (result != null) { return result; } return CACHED_METRICS.computeIfAbsent(name, n -> InstanceType.MASTER.toString() + "." + name); }
[ "private", "static", "String", "getMasterMetricName", "(", "String", "name", ")", "{", "String", "result", "=", "CACHED_METRICS", ".", "get", "(", "name", ")", ";", "if", "(", "result", "!=", "null", ")", "{", "return", "result", ";", "}", "return", "CACHED_METRICS", ".", "computeIfAbsent", "(", "name", ",", "n", "->", "InstanceType", ".", "MASTER", ".", "toString", "(", ")", "+", "\".\"", "+", "name", ")", ";", "}" ]
Builds metric registry names for master instance. The pattern is instance.metricName. @param name the metric name @return the metric registry name
[ "Builds", "metric", "registry", "names", "for", "master", "instance", ".", "The", "pattern", "is", "instance", ".", "metricName", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L230-L236
18,889
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.getWorkerMetricName
private static String getWorkerMetricName(String name) { String result = CACHED_METRICS.get(name); if (result != null) { return result; } return CACHED_METRICS.computeIfAbsent(name, n -> getMetricNameWithUniqueId(InstanceType.WORKER, name)); }
java
private static String getWorkerMetricName(String name) { String result = CACHED_METRICS.get(name); if (result != null) { return result; } return CACHED_METRICS.computeIfAbsent(name, n -> getMetricNameWithUniqueId(InstanceType.WORKER, name)); }
[ "private", "static", "String", "getWorkerMetricName", "(", "String", "name", ")", "{", "String", "result", "=", "CACHED_METRICS", ".", "get", "(", "name", ")", ";", "if", "(", "result", "!=", "null", ")", "{", "return", "result", ";", "}", "return", "CACHED_METRICS", ".", "computeIfAbsent", "(", "name", ",", "n", "->", "getMetricNameWithUniqueId", "(", "InstanceType", ".", "WORKER", ",", "name", ")", ")", ";", "}" ]
Builds metric registry name for worker instance. The pattern is instance.uniqueId.metricName. @param name the metric name @return the metric registry name
[ "Builds", "metric", "registry", "name", "for", "worker", "instance", ".", "The", "pattern", "is", "instance", ".", "uniqueId", ".", "metricName", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L244-L251
18,890
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.getClientMetricName
private static String getClientMetricName(String name) { String result = CACHED_METRICS.get(name); if (result != null) { return result; } return CACHED_METRICS.computeIfAbsent(name, n -> getMetricNameWithUniqueId(InstanceType.CLIENT, name)); }
java
private static String getClientMetricName(String name) { String result = CACHED_METRICS.get(name); if (result != null) { return result; } return CACHED_METRICS.computeIfAbsent(name, n -> getMetricNameWithUniqueId(InstanceType.CLIENT, name)); }
[ "private", "static", "String", "getClientMetricName", "(", "String", "name", ")", "{", "String", "result", "=", "CACHED_METRICS", ".", "get", "(", "name", ")", ";", "if", "(", "result", "!=", "null", ")", "{", "return", "result", ";", "}", "return", "CACHED_METRICS", ".", "computeIfAbsent", "(", "name", ",", "n", "->", "getMetricNameWithUniqueId", "(", "InstanceType", ".", "CLIENT", ",", "name", ")", ")", ";", "}" ]
Builds metric registry name for client instance. The pattern is instance.uniqueId.metricName. @param name the metric name @return the metric registry name
[ "Builds", "metric", "registry", "name", "for", "client", "instance", ".", "The", "pattern", "is", "instance", ".", "uniqueId", ".", "metricName", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L259-L266
18,891
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.getJobMasterMetricName
private static String getJobMasterMetricName(String name) { return Joiner.on(".").join(InstanceType.JOB_MASTER, name); }
java
private static String getJobMasterMetricName(String name) { return Joiner.on(".").join(InstanceType.JOB_MASTER, name); }
[ "private", "static", "String", "getJobMasterMetricName", "(", "String", "name", ")", "{", "return", "Joiner", ".", "on", "(", "\".\"", ")", ".", "join", "(", "InstanceType", ".", "JOB_MASTER", ",", "name", ")", ";", "}" ]
Builds metric registry names for the job master instance. The pattern is instance.metricName. @param name the metric name @return the metric registry name
[ "Builds", "metric", "registry", "names", "for", "the", "job", "master", "instance", ".", "The", "pattern", "is", "instance", ".", "metricName", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L294-L296
18,892
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.checkMinimalPollingPeriod
public static void checkMinimalPollingPeriod(TimeUnit pollUnit, int pollPeriod) throws IllegalArgumentException { int period = (int) MINIMAL_POLL_UNIT.convert(pollPeriod, pollUnit); Preconditions.checkArgument(period >= MINIMAL_POLL_PERIOD, "Polling period %d %d is below the minimal polling period", pollPeriod, pollUnit); }
java
public static void checkMinimalPollingPeriod(TimeUnit pollUnit, int pollPeriod) throws IllegalArgumentException { int period = (int) MINIMAL_POLL_UNIT.convert(pollPeriod, pollUnit); Preconditions.checkArgument(period >= MINIMAL_POLL_PERIOD, "Polling period %d %d is below the minimal polling period", pollPeriod, pollUnit); }
[ "public", "static", "void", "checkMinimalPollingPeriod", "(", "TimeUnit", "pollUnit", ",", "int", "pollPeriod", ")", "throws", "IllegalArgumentException", "{", "int", "period", "=", "(", "int", ")", "MINIMAL_POLL_UNIT", ".", "convert", "(", "pollPeriod", ",", "pollUnit", ")", ";", "Preconditions", ".", "checkArgument", "(", "period", ">=", "MINIMAL_POLL_PERIOD", ",", "\"Polling period %d %d is below the minimal polling period\"", ",", "pollPeriod", ",", "pollUnit", ")", ";", "}" ]
Checks if the poll period is smaller that the minimal poll period which is 1 second. @param pollUnit the polling unit @param pollPeriod the polling period @throws IllegalArgumentException if the polling period is invalid
[ "Checks", "if", "the", "poll", "period", "is", "smaller", "that", "the", "minimal", "poll", "period", "which", "is", "1", "second", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L331-L336
18,893
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.stripInstanceAndHost
public static String stripInstanceAndHost(String metricsName) { String[] pieces = metricsName.split("\\."); Preconditions.checkArgument(pieces.length > 1, "Incorrect metrics name: %s.", metricsName); // Master metrics doesn't have hostname included. if (!pieces[0].equals(MetricsSystem.InstanceType.MASTER.toString())) { pieces[1] = null; } pieces[0] = null; return Joiner.on(".").skipNulls().join(pieces); }
java
public static String stripInstanceAndHost(String metricsName) { String[] pieces = metricsName.split("\\."); Preconditions.checkArgument(pieces.length > 1, "Incorrect metrics name: %s.", metricsName); // Master metrics doesn't have hostname included. if (!pieces[0].equals(MetricsSystem.InstanceType.MASTER.toString())) { pieces[1] = null; } pieces[0] = null; return Joiner.on(".").skipNulls().join(pieces); }
[ "public", "static", "String", "stripInstanceAndHost", "(", "String", "metricsName", ")", "{", "String", "[", "]", "pieces", "=", "metricsName", ".", "split", "(", "\"\\\\.\"", ")", ";", "Preconditions", ".", "checkArgument", "(", "pieces", ".", "length", ">", "1", ",", "\"Incorrect metrics name: %s.\"", ",", "metricsName", ")", ";", "// Master metrics doesn't have hostname included.", "if", "(", "!", "pieces", "[", "0", "]", ".", "equals", "(", "MetricsSystem", ".", "InstanceType", ".", "MASTER", ".", "toString", "(", ")", ")", ")", "{", "pieces", "[", "1", "]", "=", "null", ";", "}", "pieces", "[", "0", "]", "=", "null", ";", "return", "Joiner", ".", "on", "(", "\".\"", ")", ".", "skipNulls", "(", ")", ".", "join", "(", "pieces", ")", ";", "}" ]
Removes the instance and host from the given metric name, returning the result. @param metricsName the long metrics name with instance and host name @return the metrics name without instance and host name
[ "Removes", "the", "instance", "and", "host", "from", "the", "given", "metric", "name", "returning", "the", "result", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L344-L354
18,894
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.registerGaugeIfAbsent
public static synchronized <T> void registerGaugeIfAbsent(String name, Gauge<T> metric) { if (!METRIC_REGISTRY.getGauges().containsKey(name)) { METRIC_REGISTRY.register(name, metric); } }
java
public static synchronized <T> void registerGaugeIfAbsent(String name, Gauge<T> metric) { if (!METRIC_REGISTRY.getGauges().containsKey(name)) { METRIC_REGISTRY.register(name, metric); } }
[ "public", "static", "synchronized", "<", "T", ">", "void", "registerGaugeIfAbsent", "(", "String", "name", ",", "Gauge", "<", "T", ">", "metric", ")", "{", "if", "(", "!", "METRIC_REGISTRY", ".", "getGauges", "(", ")", ".", "containsKey", "(", "name", ")", ")", "{", "METRIC_REGISTRY", ".", "register", "(", "name", ",", "metric", ")", ";", "}", "}" ]
Registers a gauge if it has not been registered. @param name the gauge name @param metric the gauge @param <T> the type
[ "Registers", "a", "gauge", "if", "it", "has", "not", "been", "registered", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L400-L404
18,895
Alluxio/alluxio
core/common/src/main/java/alluxio/metrics/MetricsSystem.java
MetricsSystem.resetAllCounters
public static void resetAllCounters() { for (Map.Entry<String, Counter> entry : METRIC_REGISTRY.getCounters().entrySet()) { entry.getValue().dec(entry.getValue().getCount()); } }
java
public static void resetAllCounters() { for (Map.Entry<String, Counter> entry : METRIC_REGISTRY.getCounters().entrySet()) { entry.getValue().dec(entry.getValue().getCount()); } }
[ "public", "static", "void", "resetAllCounters", "(", ")", "{", "for", "(", "Map", ".", "Entry", "<", "String", ",", "Counter", ">", "entry", ":", "METRIC_REGISTRY", ".", "getCounters", "(", ")", ".", "entrySet", "(", ")", ")", "{", "entry", ".", "getValue", "(", ")", ".", "dec", "(", "entry", ".", "getValue", "(", ")", ".", "getCount", "(", ")", ")", ";", "}", "}" ]
Resets all the counters to 0 for testing.
[ "Resets", "all", "the", "counters", "to", "0", "for", "testing", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/common/src/main/java/alluxio/metrics/MetricsSystem.java#L409-L413
18,896
Alluxio/alluxio
core/base/src/main/java/alluxio/security/authorization/DefaultAccessControlList.java
DefaultAccessControlList.generateChildFileACL
public AccessControlList generateChildFileACL(Short umask) { Mode defaultMode = new Mode(umask); AccessControlList acl = new AccessControlList(); acl.mOwningUser = mOwningUser; acl.mOwningGroup = mOwningGroup; acl.mMode = mMode; if (mExtendedEntries == null) { acl.mExtendedEntries = null; // minimal acl so we use defaultMode to filter user/group/other acl.mMode = Mode.and(new Mode(mMode), defaultMode).toShort(); } else { // Rules for having extended entries, we need to modify user, mask and others' // permission to be filtered by the defaultMode acl.mExtendedEntries = new ExtendedACLEntries(mExtendedEntries); // mask is filtered by the group bits from the umask parameter AclActions mask = acl.mExtendedEntries.getMask(); AclActions groupAction = new AclActions(); groupAction.updateByModeBits(defaultMode.getGroupBits()); mask.mask(groupAction); // user is filtered by the user bits from the umask parameter // other is filtered by the other bits from the umask parameter Mode updateMode = new Mode(mMode); updateMode.setOwnerBits(updateMode.getOwnerBits().and(defaultMode.getOwnerBits())); updateMode.setOtherBits(updateMode.getOtherBits().and(defaultMode.getOtherBits())); acl.mMode = updateMode.toShort(); } return acl; }
java
public AccessControlList generateChildFileACL(Short umask) { Mode defaultMode = new Mode(umask); AccessControlList acl = new AccessControlList(); acl.mOwningUser = mOwningUser; acl.mOwningGroup = mOwningGroup; acl.mMode = mMode; if (mExtendedEntries == null) { acl.mExtendedEntries = null; // minimal acl so we use defaultMode to filter user/group/other acl.mMode = Mode.and(new Mode(mMode), defaultMode).toShort(); } else { // Rules for having extended entries, we need to modify user, mask and others' // permission to be filtered by the defaultMode acl.mExtendedEntries = new ExtendedACLEntries(mExtendedEntries); // mask is filtered by the group bits from the umask parameter AclActions mask = acl.mExtendedEntries.getMask(); AclActions groupAction = new AclActions(); groupAction.updateByModeBits(defaultMode.getGroupBits()); mask.mask(groupAction); // user is filtered by the user bits from the umask parameter // other is filtered by the other bits from the umask parameter Mode updateMode = new Mode(mMode); updateMode.setOwnerBits(updateMode.getOwnerBits().and(defaultMode.getOwnerBits())); updateMode.setOtherBits(updateMode.getOtherBits().and(defaultMode.getOtherBits())); acl.mMode = updateMode.toShort(); } return acl; }
[ "public", "AccessControlList", "generateChildFileACL", "(", "Short", "umask", ")", "{", "Mode", "defaultMode", "=", "new", "Mode", "(", "umask", ")", ";", "AccessControlList", "acl", "=", "new", "AccessControlList", "(", ")", ";", "acl", ".", "mOwningUser", "=", "mOwningUser", ";", "acl", ".", "mOwningGroup", "=", "mOwningGroup", ";", "acl", ".", "mMode", "=", "mMode", ";", "if", "(", "mExtendedEntries", "==", "null", ")", "{", "acl", ".", "mExtendedEntries", "=", "null", ";", "// minimal acl so we use defaultMode to filter user/group/other", "acl", ".", "mMode", "=", "Mode", ".", "and", "(", "new", "Mode", "(", "mMode", ")", ",", "defaultMode", ")", ".", "toShort", "(", ")", ";", "}", "else", "{", "// Rules for having extended entries, we need to modify user, mask and others'", "// permission to be filtered by the defaultMode", "acl", ".", "mExtendedEntries", "=", "new", "ExtendedACLEntries", "(", "mExtendedEntries", ")", ";", "// mask is filtered by the group bits from the umask parameter", "AclActions", "mask", "=", "acl", ".", "mExtendedEntries", ".", "getMask", "(", ")", ";", "AclActions", "groupAction", "=", "new", "AclActions", "(", ")", ";", "groupAction", ".", "updateByModeBits", "(", "defaultMode", ".", "getGroupBits", "(", ")", ")", ";", "mask", ".", "mask", "(", "groupAction", ")", ";", "// user is filtered by the user bits from the umask parameter", "// other is filtered by the other bits from the umask parameter", "Mode", "updateMode", "=", "new", "Mode", "(", "mMode", ")", ";", "updateMode", ".", "setOwnerBits", "(", "updateMode", ".", "getOwnerBits", "(", ")", ".", "and", "(", "defaultMode", ".", "getOwnerBits", "(", ")", ")", ")", ";", "updateMode", ".", "setOtherBits", "(", "updateMode", ".", "getOtherBits", "(", ")", ".", "and", "(", "defaultMode", ".", "getOtherBits", "(", ")", ")", ")", ";", "acl", ".", "mMode", "=", "updateMode", ".", "toShort", "(", ")", ";", "}", "return", "acl", ";", "}" ]
create a child file 's accessACL based on the default ACL. @param umask file's umask @return child file's access ACL
[ "create", "a", "child", "file", "s", "accessACL", "based", "on", "the", "default", "ACL", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/base/src/main/java/alluxio/security/authorization/DefaultAccessControlList.java#L64-L92
18,897
Alluxio/alluxio
core/base/src/main/java/alluxio/security/authorization/DefaultAccessControlList.java
DefaultAccessControlList.generateChildDirACL
public Pair<AccessControlList, DefaultAccessControlList> generateChildDirACL(Short umask) { AccessControlList acl = generateChildFileACL(umask); DefaultAccessControlList dAcl = new DefaultAccessControlList(acl); dAcl.setEmpty(false); dAcl.mOwningUser = mOwningUser; dAcl.mOwningGroup = mOwningGroup; dAcl.mMode = mMode; if (mExtendedEntries == null) { dAcl.mExtendedEntries = null; } else { dAcl.mExtendedEntries = new ExtendedACLEntries(mExtendedEntries); } return new Pair<>(acl, dAcl); }
java
public Pair<AccessControlList, DefaultAccessControlList> generateChildDirACL(Short umask) { AccessControlList acl = generateChildFileACL(umask); DefaultAccessControlList dAcl = new DefaultAccessControlList(acl); dAcl.setEmpty(false); dAcl.mOwningUser = mOwningUser; dAcl.mOwningGroup = mOwningGroup; dAcl.mMode = mMode; if (mExtendedEntries == null) { dAcl.mExtendedEntries = null; } else { dAcl.mExtendedEntries = new ExtendedACLEntries(mExtendedEntries); } return new Pair<>(acl, dAcl); }
[ "public", "Pair", "<", "AccessControlList", ",", "DefaultAccessControlList", ">", "generateChildDirACL", "(", "Short", "umask", ")", "{", "AccessControlList", "acl", "=", "generateChildFileACL", "(", "umask", ")", ";", "DefaultAccessControlList", "dAcl", "=", "new", "DefaultAccessControlList", "(", "acl", ")", ";", "dAcl", ".", "setEmpty", "(", "false", ")", ";", "dAcl", ".", "mOwningUser", "=", "mOwningUser", ";", "dAcl", ".", "mOwningGroup", "=", "mOwningGroup", ";", "dAcl", ".", "mMode", "=", "mMode", ";", "if", "(", "mExtendedEntries", "==", "null", ")", "{", "dAcl", ".", "mExtendedEntries", "=", "null", ";", "}", "else", "{", "dAcl", ".", "mExtendedEntries", "=", "new", "ExtendedACLEntries", "(", "mExtendedEntries", ")", ";", "}", "return", "new", "Pair", "<>", "(", "acl", ",", "dAcl", ")", ";", "}" ]
Creates a child directory's access ACL and default ACL based on the default ACL. @param umask child's umask @return child directory's access ACL and default ACL
[ "Creates", "a", "child", "directory", "s", "access", "ACL", "and", "default", "ACL", "based", "on", "the", "default", "ACL", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/base/src/main/java/alluxio/security/authorization/DefaultAccessControlList.java#L99-L112
18,898
Alluxio/alluxio
core/server/common/src/main/java/alluxio/ProcessUtils.java
ProcessUtils.stopProcessOnShutdown
public static void stopProcessOnShutdown(final Process process) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { process.stop(); } catch (Throwable t) { LOG.error("Failed to stop process", t); } }, "alluxio-process-shutdown-hook")); }
java
public static void stopProcessOnShutdown(final Process process) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { process.stop(); } catch (Throwable t) { LOG.error("Failed to stop process", t); } }, "alluxio-process-shutdown-hook")); }
[ "public", "static", "void", "stopProcessOnShutdown", "(", "final", "Process", "process", ")", "{", "Runtime", ".", "getRuntime", "(", ")", ".", "addShutdownHook", "(", "new", "Thread", "(", "(", ")", "->", "{", "try", "{", "process", ".", "stop", "(", ")", ";", "}", "catch", "(", "Throwable", "t", ")", "{", "LOG", ".", "error", "(", "\"Failed to stop process\"", ",", "t", ")", ";", "}", "}", ",", "\"alluxio-process-shutdown-hook\"", ")", ")", ";", "}" ]
Adds a shutdown hook that will be invoked when a signal is sent to this process. The process may be utilizing some resources, and this shutdown hook will be invoked by JVM when a SIGTERM is sent to the process by "kill" command. The shutdown hook calls {@link Process#stop()} method to cleanly release the resources and exit. @param process the data structure representing the process to terminate
[ "Adds", "a", "shutdown", "hook", "that", "will", "be", "invoked", "when", "a", "signal", "is", "sent", "to", "this", "process", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/common/src/main/java/alluxio/ProcessUtils.java#L90-L98
18,899
Alluxio/alluxio
core/server/master/src/main/java/alluxio/master/metastore/rocks/RocksStore.java
RocksStore.writeToCheckpoint
public synchronized void writeToCheckpoint(OutputStream output) throws IOException, InterruptedException { LOG.info("Creating rocksdb checkpoint at {}", mDbCheckpointPath); long startNano = System.nanoTime(); CheckpointOutputStream out = new CheckpointOutputStream(output, CheckpointType.ROCKS); try { // createCheckpoint requires that the directory not already exist. FileUtils.deletePathRecursively(mDbCheckpointPath); mCheckpoint.createCheckpoint(mDbCheckpointPath); } catch (RocksDBException e) { throw new IOException(e); } LOG.info("Checkpoint complete, creating tarball"); TarUtils.writeTarGz(Paths.get(mDbCheckpointPath), out); LOG.info("Completed rocksdb checkpoint in {}ms", (System.nanoTime() - startNano) / 1_000_000); // Checkpoint is no longer needed, delete to save space. FileUtils.deletePathRecursively(mDbCheckpointPath); }
java
public synchronized void writeToCheckpoint(OutputStream output) throws IOException, InterruptedException { LOG.info("Creating rocksdb checkpoint at {}", mDbCheckpointPath); long startNano = System.nanoTime(); CheckpointOutputStream out = new CheckpointOutputStream(output, CheckpointType.ROCKS); try { // createCheckpoint requires that the directory not already exist. FileUtils.deletePathRecursively(mDbCheckpointPath); mCheckpoint.createCheckpoint(mDbCheckpointPath); } catch (RocksDBException e) { throw new IOException(e); } LOG.info("Checkpoint complete, creating tarball"); TarUtils.writeTarGz(Paths.get(mDbCheckpointPath), out); LOG.info("Completed rocksdb checkpoint in {}ms", (System.nanoTime() - startNano) / 1_000_000); // Checkpoint is no longer needed, delete to save space. FileUtils.deletePathRecursively(mDbCheckpointPath); }
[ "public", "synchronized", "void", "writeToCheckpoint", "(", "OutputStream", "output", ")", "throws", "IOException", ",", "InterruptedException", "{", "LOG", ".", "info", "(", "\"Creating rocksdb checkpoint at {}\"", ",", "mDbCheckpointPath", ")", ";", "long", "startNano", "=", "System", ".", "nanoTime", "(", ")", ";", "CheckpointOutputStream", "out", "=", "new", "CheckpointOutputStream", "(", "output", ",", "CheckpointType", ".", "ROCKS", ")", ";", "try", "{", "// createCheckpoint requires that the directory not already exist.", "FileUtils", ".", "deletePathRecursively", "(", "mDbCheckpointPath", ")", ";", "mCheckpoint", ".", "createCheckpoint", "(", "mDbCheckpointPath", ")", ";", "}", "catch", "(", "RocksDBException", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "LOG", ".", "info", "(", "\"Checkpoint complete, creating tarball\"", ")", ";", "TarUtils", ".", "writeTarGz", "(", "Paths", ".", "get", "(", "mDbCheckpointPath", ")", ",", "out", ")", ";", "LOG", ".", "info", "(", "\"Completed rocksdb checkpoint in {}ms\"", ",", "(", "System", ".", "nanoTime", "(", ")", "-", "startNano", ")", "/", "1_000_000", ")", ";", "// Checkpoint is no longer needed, delete to save space.", "FileUtils", ".", "deletePathRecursively", "(", "mDbCheckpointPath", ")", ";", "}" ]
Writes a checkpoint of the database's content to the given output stream. @param output the stream to write to
[ "Writes", "a", "checkpoint", "of", "the", "database", "s", "content", "to", "the", "given", "output", "stream", "." ]
af38cf3ab44613355b18217a3a4d961f8fec3a10
https://github.com/Alluxio/alluxio/blob/af38cf3ab44613355b18217a3a4d961f8fec3a10/core/server/master/src/main/java/alluxio/master/metastore/rocks/RocksStore.java#L159-L177