664行 CliDriver main启动
public static void main(String[] args) throws Exception {
int ret = new CliDriver().run(args);
System.exit(ret);
}
646行
public int run(String[] args) throws Exception {
OptionsProcessor oproc = new OptionsProcessor();
if (!oproc.process_stage1(args)) {
return 1;
}
OptionsProcessor oproc = new OptionsProcessor();
OptionsProcessor 初始化 所有options
解析 options args
if (!oproc.process_stage1(args)) {
在new CliDriver()
public CliDriver() {
SessionState ss = SessionState.get();
conf = (ss != null) ? ss.getConf() : new Configuration();
Logger LOG = LoggerFactory.getLogger("CliDriver");
if (LOG.isDebugEnabled()) {
LOG.debug("CliDriver inited with classpath {}", System.getProperty("java.class.path"));
}
console = new LogHelper(LOG);
}
SessionState.get();
看 SessionState.get
public static SessionState get() {
return tss.get().state;
}
tss.是threadlocal ,threadlocal我想大家都知道,解决多线程共享问题。 threadlocal 包装了一个hashmap 其中key 是this 当前线程。
private static ThreadLocal<SessionStates> tss = new ThreadLocal<SessionStates>() {
@Override
protected SessionStates initialValue() {
return new SessionStates();
}
};
重新 initialValue 当值不存在 new 一个 看看SessionStates
private static class SessionStates {
private SessionState state;
private HiveConf conf;
private void attach(SessionState state) {
this.state = state;
attach(state.getConf());
}
private void attach(HiveConf conf) {
this.conf = conf; ClassLoader classLoader = conf.getClassLoader();
if (classLoader != null) {
Thread.currentThread().setContextClassLoader(classLoader);
}
}
}
看到
SessionStates 大家明白了
SessionStates 包含两部分
HiveConf
SessionState
看看
SessionState 代码
private static final Logger LOG = LoggerFactory.getLogger(SessionState.class); private static final String TMP_PREFIX = "_tmp_space.db";
private static final String LOCAL_SESSION_PATH_KEY = "_hive.local.session.path";
private static final String HDFS_SESSION_PATH_KEY = "_hive.hdfs.session.path";
private static final String TMP_TABLE_SPACE_KEY = "_hive.tmp_table_space";
static final String LOCK_FILE_NAME = "inuse.lck";
static final String INFO_FILE_NAME = "inuse.info"; private final Map<String, Map<String, Table>> tempTables = new HashMap<String, Map<String, Table>>();
private final Map<String, Map<String, ColumnStatisticsObj>> tempTableColStats =
new HashMap<String, Map<String, ColumnStatisticsObj>>(); protected ClassLoader parentLoader; // Session-scope compile lock.
private final ReentrantLock compileLock = new ReentrantLock(); /**
* current configuration.
*/
private final HiveConf sessionConf; /**
* silent mode.
*/
protected boolean isSilent; /**
* verbose mode
*/
protected boolean isVerbose; /**
* The flag to indicate if the session serves the queries from HiveServer2 or not.
*/
private boolean isHiveServerQuery = false; /**
* The flag to indicate if the session using thrift jdbc binary serde or not.
*/
private boolean isUsingThriftJDBCBinarySerDe = false; /**
* The flag to indicate if the session already started so we can skip the init
*/
private boolean isStarted = false;
/*
* HiveHistory Object
*/
protected HiveHistory hiveHist; /**
* Streams to read/write from.
*/
public InputStream in;
public PrintStream out;
public PrintStream info;
public PrintStream err;
上面部分代码 可以看出部分命令行的
的值。
可