在FSNamesystem中,有这么一个成员变量,定义如下:
/**
* Used when this NN is in standby state to read from the shared edit log.
* 当NameNode处于standby状态时用于从共享的edit log读取数据
*/
private EditLogTailer editLogTailer = null;
editLogTailer是一个编辑日志edit log的追踪器,它的主要作用就是当NameNode处于standby状态时用于从共享的edit log读取数据。它的构造是在FSNamesystem的startStandbyServices()方法中,代码如下:
editLogTailer = new EditLogTailer(this, conf);
editLogTailer.start();
利用当前FSNamesystem实例this和配置信息conf实例化一个EditLogTailer对象,然后调用其start()方法启动它。
接下来我们看看EditLogTailer的实现,先来看下其成员变量,代码如下:
// 编辑日志跟踪线程EditLogTailerThread实例tailerThread
private final EditLogTailerThread tailerThread;
// HDFS配置信息Configuration实例conf
private final Configuration conf;
// 文件系统命名空间FSNamesystem实例namesystem
private final FSNamesystem namesystem;
// 文件系统编辑日志FSEditLog实例editLog
private FSEditLog editLog;
// Active NameNode地址InetSocketAddress
private InetSocketAddress activeAddr;
// 名字节点通信接口NamenodeProtocol
private NamenodeProtocol cachedActiveProxy = null;
/**
* The last transaction ID at which an edit log roll was initiated.
* 一次编辑日志滚动开始时的最新事务ID
*/
private long lastRollTriggerTxId = HdfsConstants.INVALID_TXID;
/**
* The highest transaction ID loaded by the Standby.
* StandBy NameNode加载的最高事务ID
*/
private long lastLoadedTxnId = HdfsConstants.INVALID_TXID;
/**
* The last time we successfully loaded a non-zero number of edits from the
* shared directory.
* 最后一次我们从共享目录成功加载一个非零编辑的时间
*/
private long lastLoadTimestamp;
/**
* How often the Standby should roll edit logs. Since the Standby only reads
* from finalized log segments, the Standby will only be as up-to-date as how
* often the logs are rolled.
* StandBy NameNode滚动编辑日志的时间间隔。
*/
private final long logRollPeriodMs;
/**
* How often the Standby should check if there are new finalized segment(s)
* available to be read from.
* StandBy NameNode检查是否存在可以读取的新的最终日志段的时间间隔
*/
private final long sleepTimeMs;
其中,比较重要的几个变量如下:
1、EditLogTailerThread tailerThread:它是编辑日志跟踪线程,
我们再来看下EditLogTailer的构造方法,如下:
public EditLog