HLog 코드 분석 및 HBase replication 지연

replication 을 공유 할 때 동료 가 replication 지연 시간 을 제시 하 는 것 이 어 떻 습 니까? (0.94.3 기반)
본 고 는 주로 Hlog 생 성 및 relication 에 미 친 영향 을 분석 하고 자 한다.구체 적 인 복제 참고 바 랍 니 다
http://brianf.iteye.com/blog/1776936
먼저 hlog 가 언제 발생 하 는 지 분석 합 니 다.
HLog 대상 을 생 성 할 때 HLog 의 rollWriter () 를 호출 합 니 다. 이때 this. writer 는 null 이기 때문에 rollWriter 방법 을 통 해 첫 번 째 hlog 파일 을 만 들 고 그 다음 에 replicaton 과 관련 된 참 조 를 호출 합 니 다.http://brianf.iteye.com/blog/1776936
    // rollWriter sets this.hdfs_out if it can.
    rollWriter();

    // handle the reflection necessary to call getNumCurrentReplicas()
    this.getNumCurrentReplicas = getGetNumCurrentReplicas(this.hdfs_out);

    logSyncerThread = new LogSyncer(this.optionalFlushInterval);

-----------------
 public byte [][] rollWriter(boolean force)
      throws FailedLogCloseException, IOException {
    // Return if nothing to flush.
    if (!force && this.writer != null && this.numEntries.get() <= 0) {
      return null;
    }

-------------
LogRoller. run 중      
  public void run() {
    while (!server.isStopped()) {
      long now = System.currentTimeMillis();
      boolean periodic = false;
      if (!rollLog.get()) {
        periodic = (now - this.lastrolltime) > this.rollperiod;
        if (!periodic) {
          synchronized (rollLog) {
            try {
              rollLog.wait(this.threadWakeFrequency);
            } catch (InterruptedException e) {
              // Fall through
            }
          }
          continue;
        }
        // Time for periodic roll
        if (LOG.isDebugEnabled()) {
          LOG.debug("Hlog roll period " + this.rollperiod + "ms elapsed");
        }
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("HLog roll requested");
      }
      rollLock.lock(); // FindBugs UL_UNRELEASED_LOCK_EXCEPTION_PATH
      try {
        this.lastrolltime = now;
        // This is array of actual region names.
        byte [][] regionsToFlush = this.services.getWAL().rollWriter(rollLog.get());

LogRoller 스 레 드 는 기본적으로 1 시간 을 기다 리 고 있 습 니 다. 즉, 기본 값 은 1 시간 에 한 log 입 니 다.
    this.rollperiod = this.server.getConfiguration().
      getLong("hbase.regionserver.logroll.period", 3600000);

rollLog 는 Atomic Boolean 입 니 다. true 일 때 rollWriter 를 호출 하면 새 log 를 만 듭 니 다. 언제 rollLog 를 true 로 만 듭 니까?
  public void logRollRequested() {
    synchronized (rollLog) {
      rollLog.set(true);
      rollLog.notifyAll();
    }
  }

Hlog. syncer 방법 에서 호출 되 었 습 니 다.
hbase 에 데 이 터 를 기록 할 때 put 와 같이 Hlog 의 append 를 호출 합 니 다. 이 방법 은 데 이 터 를 Hlog 의 캐 시 (List) 에 기록 하고 sync 데 이 터 를 HDSF 에 동기 화 합 니 다. 그리고 LogSyncer 스 레 드 는 1000 ms 에서 Hlog. syncer 방법 을 실행 합 니 다.
  private long append(HRegionInfo info, byte [] tableName, WALEdit edits, UUID clusterId,
      final long now, HTableDescriptor htd, boolean doSync)
    throws IOException {
      if (edits.isEmpty()) return this.unflushedEntries.get();;
      if (this.closed) {
        throw new IOException("Cannot append; log is closed");
      }
      long txid = 0;
      synchronized (this.updateLock) {
        long seqNum = obtainSeqNum();
        // The 'lastSeqWritten' map holds the sequence number of the oldest
        // write for each region (i.e. the first edit added to the particular
        // memstore). . When the cache is flushed, the entry for the
        // region being flushed is removed if the sequence number of the flush
        // is greater than or equal to the value in lastSeqWritten.
        // Use encoded name.  Its shorter, guaranteed unique and a subset of
        // actual  name.
        byte [] encodedRegionName = info.getEncodedNameAsBytes();
        this.lastSeqWritten.putIfAbsent(encodedRegionName, seqNum);
        HLogKey logKey = makeKey(encodedRegionName, tableName, seqNum, now, clusterId);
        doWrite(info, logKey, edits, htd);
        this.numEntries.incrementAndGet();
        txid = this.unflushedEntries.incrementAndGet();
        if (htd.isDeferredLogFlush()) {
          lastDeferredTxid = txid;
        }
      }
      // Sync if catalog region, and if not then check if that table supports
      // deferred log flushing
      if (doSync && 
          (info.isMetaRegion() ||
          !htd.isDeferredLogFlush())) {
        // sync txn to file system
        this.sync(txid);
      }
      return txid;
    }

그 중에서 Hlog. syncer 방법 에서 checkLowReplication 방법 을 호출 하여 hlog 가 hdfs 에 있 는 복사 본 수가 설정 항목 보다 적 는 지 판단 합 니 다. 낮 으 면 requestLogRoll, 최종 적 으로 logRoll Requestion 방법 을 호출 하지만 호출 횟수 는 기본 5 회 를 초과 하지 않 습 니 다 (  
 this.lowReplicationRollLimit = conf.getInt(
        "hbase.regionserver.hlog.lowreplication.rolllimit", 5);

그 다음 에 쓰 고 있 는 hlog 가 하나의 size (64MB * 0.95) 보다 큰 지 판단 하고 크 면 설명 도 새로운 Hlog 를 생 성 해 야 합 니 다.
    this.blocksize = conf.getLong("hbase.regionserver.hlog.blocksize",
        getDefaultBlockSize());
    // Roll at 95% of block size.
    float multi = conf.getFloat("hbase.regionserver.logroll.multiplier", 0.95f);
    this.logrollsize = (long)(this.blocksize * multi);
--------------------
          if (tempWriter.getLength() > this.logrollsize) {
            requestLogRoll();
          }

replication 의 경우 지연 시간 은 주로 ZK 와 의 통신 및 RPC 에서 slave RS 시간 을 호출 합 니 다.
hbase.regionserver.optionallogflushinterval
HDFS 간격 으로 Hlog 를 동기 화 합 니 다.Hlog 가 일정 수량 까지 쌓 이지 않 으 면 시간 이 되면 동기 화 를 촉발 합 니 다.기본 값 은 1 초, 단위 밀리초 입 니 다.
기본 값: 1000
hbase.regionserver.logroll.period
commt log 를 제출 하 는 간격 입 니 다. 충분 한 값 을 쓰 든 말 든.
기본 값: 3600000
hbase.master.logcleaner.ttl
Hlog 는. oldlogdir 폴 더 에 가장 오래 존재 합 니 다. 초과 하면 Master 의 스 레 드 에 의 해 삭 제 됩 니 다.
기본 값: 600000
hbase.master.logcleaner.plugins
값 은 쉼표 간격 텍스트 로 표 시 됩 니 다.이 WAL / HLog 들  cleaners 는 순서대로 호출 됩 니 다.먼저 호출 한 것 을 앞 에 놓 을 수 있다.자신의 LogCleaner Delegat 를 실현 하고 Classpath 에 추가 한 다음 클래스 의 전체 경 로 를 쓰 면 됩 니 다.보통 기본 값 앞 에 추가 합 니 다.
구체 적 인 초기 단 계 는 Cleaner Chore 의 initCleaner Chain 방법 으로 HFile 의 cleaner 초기 화 를 실현 했다.
기본 값: org. apache. hadop. hbase. master. TimeToLiveLogCleaner
hbase.regionserver.hlog.blocksize
hbase.regionserver.maxlogs
WAL 의 최대 값 은 hbase. regionserver. maxlogs * hbase. regionserver. hlog. blocksize (2GB by default) 에 의 해 결 정 됩 니 다.이 값 에 도달 하면 Memstore flush 가 실 행 됩 니 다.WAL 제한 을 통 해 Memstore 의 flush 를 촉발 하 는 것 은 최선 의 방법 이 아니다. 이렇게 하면 한 번 에 flush 많은 지역 에서 flush 눈사태 가 발생 할 수 있다.
hbase. regionserver. hlog. blocksize * hbase. regionserver. maxlogs 를 hbase. regionserver. global. memstore. lowerLimit * HBASE 보다 약간 큰 것 으로 설정 하 는 것 이 좋 습 니 다.HEAPSIZE.

좋은 웹페이지 즐겨찾기