亞穩定機房hbase集羣配置

背景

在某些項目中,因爲一些特殊緣由,機房環境不是特別穩定,存在可能忽然斷電的狀況,在這種狀況下,咱們須要一些額外的配置來儘可能避免hbase集羣數據丟失。node

風險

  • HLog 沒有及時落地到磁盤,斷電致使wal日誌丟失
  • HFile刷寫完成,可是文件HFileclose調用後,數據沒有及時落地到磁盤,斷電致使HFile文件損壞,region open失敗。

相關知識

linux 磁盤數據同步apilinux

  • sync: POSIX標準中,sync把寫操做加入到調度隊列中,但不會等到實際磁盤寫完成才返回。linux 1.3.20版本以後,sync會等待寫完成才返回和遍歷調用fsync(fd)語義相同.
  • fsync:fsync的功能是確保文件fd全部已修改的內容已經正確同步到硬盤上,該調用會阻塞等待直到設備報告IO完成。
  • fdatasync:fdatasync的功能與fsync相似,可是僅僅在必要的狀況下才會同步metadata,所以能夠減小一次IO寫操做,什麼是「必要的狀況」呢?例來講,文件的尺寸(st_size)若是變化,是須要當即同步的,不然OS一旦崩潰,即便文件的數據部分已同步,因爲metadata沒有同步,依然讀不到修改的內容。而最後訪問時間(atime)/修改時間(mtime)是不須要每次都同步的,只要應用程序對這兩個時間戳沒有苛刻的要求,基本無傷大雅。

hdfs 數據同步apiapi

public interface Syncable {
  /**
   * @deprecated As of HADOOP 0.21.0, replaced by hflush
   * @see #hflush()
   */
  @Deprecated  public void sync() throws IOException;
  
  /** Flush out the data in client's user buffer. After the return of
   * this call, new readers will see the data.
   * @throws IOException if any error occurs
   */
  public void hflush() throws IOException;
  
  /** Similar to posix fsync, flush out the data in client's user buffer 
   * all the way to the disk device (but the disk may have it in its cache).
   * @throws IOException if error occurs
   */
  public void hsync() throws IOException;
}
  • flush: 把數據從client的緩存刷寫到socket後直接返回,並不等待數據到達datanode
  • sync: 被hflush代替,直接調用了hflush
  • hflush:刷寫全部副本的塊,數據會寫入到全部datanode的緩存中,該api返回後,全部新的reader能夠讀取到數據最新的數據。
  • hsync: 全部副本完成 posix對應的fsync操做

ProtobufLogWriter緩存

@Override
  public void sync(boolean forceSync) throws IOException {
    FSDataOutputStream fsdos = this.output;
    if (fsdos == null) {
      return; // Presume closed
    }
    fsdos.flush();
    if (forceSync) {
      fsdos.hsync();
    } else {
      fsdos.hflush();
    }
  }

默認hbase.wal.hsync值爲SYNC_WAL,即會調用hflush進行同步,斷電前不能保證數據被寫入到磁盤。socket

相關配置項

hdfs-site.xmlasync

dfs.datanode.synconclose:trueide

hbase-site.xmlthis

hbase.wal.hsync:FSYNC_WAL.net

參考連接

https://blog.csdn.net/cywosp/article/details/8767327日誌

相關文章
相關標籤/搜索