commitLog:单文件默认1G
consumeQueue:单topic单queue的单文件20*30w=600w byte,commitLog offset(8) + size(4) + tag hashcode(8)
IndexFile: header(40) + slot(500w4) + index(2000w20) header(起始截止timestamp,commitLog offset等),slot(indexNo),index(keyHash,commitLog offset,timeDiff,preIndexNo),timeDiff为当前消息和第一条消息的时间差
StoreCheckPoint: 记录上面三类文件的刷盘时间
这些文件都是定长的,创建时就零字节填充好了
this.fileChannel = new RandomAccessFile(this.file, “rw”).getChannel();//文件创建
this.mappedByteBuffer = this.fileChannel.map(MapMode.READ_WRITE, 0, fileSize);//文件扩充到fileSize,零填充
启动:
commitLog 各MappedFile pageCache(MappedByteBuffer) 加载
各consumeQueue 的各MappedFile加载,StoreCheckPoint加载,各IndexFile加载
consumeQueue恢复(确定flush和commit的位置等)
commitLog恢复(若异常退出,无abort文件,恢复时需考虑转发到consumeQueue和IndexFile),
flush commitLog,flush consumeQueue,commit commitLog,reput 转发,haService启动,创建abort文件,定时删除三类文件(commitLog是4点删除,文件保留72h,空间快满了或手动也可删除,其他两类文件根据commitLog的最小offset进行删除)
TransientStorePool : 5个,每个1G(commitLog大小),DirectByteBuffer, 强制锁定在内存(避免交换到磁盘,考虑到效率),可用于commitLog的写入
读写分离,读一定走MappedByteBuffer(pageCache),master且配置开启且异步刷盘可用其进行写入,此时writePos>commitPos,否则writePos=commitPos