Oplog 分析

OpLog 实现了 CompactableOplog, Flushable

有三种类型的oplog文件, crf, drf,krf

  private final OplogFile crf = new OplogFile();
  private final OplogFile drf = new OplogFile();
  private final KRFile krf = new KRFile();

OpLog被 DiskStore拥有

 /** The store that owns this Oplog* */
  private final DiskStoreImpl parent;

opLogSet 包含一个diskStoreImple下面的所有opLog

/**
   * The oplog set this oplog is part of
   */
  private final PersistentOplogSet oplogSet;

Region初始化

LocalRegion在构造函数中 会创建 diskSoreImpl 
this.diskStoreImpl = findDiskStore(attrs, internalRegionArgs);

GemfireCacheImpl.getOrCreateDefaultDiskStore

LocalRegion.createDiskRegion
DiskRegion.create
DiskInitFile.createDiskRegion

初始化 AbstractDiskRegion的时候   protected AbstractDiskRegion(DiskStoreImpl ds, String name)
DiskRegionView drv = ds.getDiskInitFile().takeDiskRegionByName(name);

oplogSet.parent = DiskStoreImpl
opLog.parent = DiskStoreImpl
DisStoreImpl 在 初始化的时候 loadFiles , 此时加载opLog到oplogSet

重要的属性

 /**
   * This system property instructs that writes be synchronously written to disk and not to file
   * system. (Use rwd instead of rw - RandomAccessFile property)
   * 同步写
   */
  private static final boolean SYNC_WRITES =
      Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "syncWrites");

/**
   * The HighWaterMark of recentValues.
   * 最近数量
   */
  private final AtomicLong totalCount = new AtomicLong(0);

  /**
   * The number of records in this oplog that contain the most recent value of the entry.
   * 最近活跃数量
   */
  private final AtomicLong totalLiveCount = new AtomicLong(0);

/**
   * Set to true once compact is called on this oplog.
   * 做压缩的时候设置标记
   * @since GemFire prPersistSprint1
   */
  private volatile boolean compacting = false;

DiskStoreImpl

DistributedRegion 在初始化的时候,如果是从磁盘恢复数据, 会执行如下路径

DiskRegion dskRgn = getDiskRegion();

dskRgn.initializeOwner(this); // do recovery

DiskStoreImpl.initializeOwner(LocalRegion lr)

DiskStoreImpl.recoverRegionsThatAreReady()

PersistentOplogSet.recoverRegionsThatAreReady()

PersistentOplogSet.recoverOplogs(long byteCount)

OpLog.initAfterRecovery(boolean offline)

 void initAfterRecovery(boolean offline) {
   //删除crf
   else if (!offline) {
        // drf exists but crf has been deleted (because it was empty).
        // I don't think the drf needs to be opened. It is only used during
        // recovery.
        // At some point the compacter my identify that it can be deleted.
        this.crf.RAFClosed = true;
        deleteCRF();
        this.closed = true;
        this.deleted.set(true);
      }
      this.drf.RAFClosed = true; // since we never open it on a recovered oplog


//删除drf
if (hasNoLiveValues() && !offline) {
      getOplogSet().removeOplog(getOplogId(), true, getHasDeletes() ? this : null);
      if (!getHasDeletes()) {
        getOplogSet().drfDelete(this.oplogId);
        deleteFile(this.drf);
      }
    }
  }
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

打赏
文章很值,打赏犒劳作者一下
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页

打赏

愤怒的天空

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者