bluestore到rocksdb流程

4 篇文章 0 订阅
3 篇文章 0 订阅
文章详细描述了CephOSD的初始化过程,包括调用`mkfs`创建文件系统,BlueStore如何设置块设备,以及后续的`mount`操作。在BlueStore内部,涉及到了RocksDB的创建、打开、读写和事务处理等关键步骤,展示了Ceph存储集群内部的数据管理机制。
摘要由CSDN通过智能技术生成

初始化过程
[ceph_osd.cc]

int main(int argc, const char **argv)
OSD::mkfs(g_ceph_context, store, g_conf->osd_data, mc.monmap.fsid, whoami);

[OSD.cc]

int OSD::mkfs(CephContext *cct, ObjectStore *store, const string &dev, uuid_d fsid, 
  int whoami)
store->mkfs();
 store->mount();

[BlueStore.cc]

int BlueStore::mkfs()
>> _setup_block_symlink_or_file("block", cct->_conf->bluestore_block_path,
>> cct->_conf->bluestore_block_size, cct->_conf->bluestore_block_create);
>> _setup_block_symlink_or_file("block.wal", cct->_conf->bluestore_block_wal_path,
>> cct->_conf->bluestore_block_wal_size, cct->_conf->bluestore_block_wal_create);
>> _setup_block_symlink_or_file("block.db", cct->_conf->bluestore_block_db_path,
>> cct->_conf->bluestore_block_db_size, cct->_conf->bluestore_block_db_create);
>> _open_db(true);
>> _open_fm(true);  初始化FreelistManager

[BlueStore.cc]

int BlueStore::_open_db(bool create)
>> if (do_bluefs):
>> bluefs = new BlueFS(cct);
>> bluefs->add_block_device(BlueFS::BDEV_DB, bfn);
>> if (create): bluefs->add_block_extent(BlueFS::BDEV_DB, SUPER_RESERVED, 
>>             bluefs->get_block_device_size(BlueFS::BDEV_DB) - SUPER_RESERVED);
>> if (create):
>> bluefs->add_block_extent(bluefs_shared_bdev, start, initial);
>> bluefs_extents.insert(start, initial);
>> if (create):
>> bluefs->add_block_extent(BlueFS::BDEV_WAL, BDEV_LABEL_BLOCK_SIZE, 
>>   bluefs->get_block_device_size(BlueFS::BDEV_WAL) - BDEV_LABEL_BLOCK_SIZE);
>> if (create): bluefs->mkfs(fsid);
>> bluefs->mount();

[BlueFS.cc]

int BlueFS::mkfs(uuid_d osd_uuid)
>> _init_alloc();
>> 设置superblock信息
>> 初始化log_file

[BlueFS.cc]

int BlueFS::mount()
>> _init_alloc();
>> _replay(false);
>> for (auto& p : file_map):
>> for (auto& q : p.second->fnode.extents):
>> alloc[q.bdev]->init_rm_free(q.offset, q.length);
>> log_writer = _create_writer(_get_file(1));

[BlueFS.cc]

int BlueFS::_replay(bool noop)
>> 逐个回放事务op
>> BlueStore调用rocksdb相关接口
>> RocksDBStore实现KeyValueDB接口,BlueStore通过RocksDBStore实现对rocksdb操作。

open操作

[BlueStore.cc]
int BlueStore::_open_db(bool create)
>> db = KeyValueDB::create(cct, kv_backend, fn, static_cast<void*>(env));
>> if (create): db->create_and_open(err);

[RocksDBStore.cc]
int RocksDBStore::create_and_open(ostream &out)
>> do_open(out, true);

[RocksDBStore.cc]
int RocksDBStore::do_open(ostream &out, bool create_if_missing)
>> rocksdb::DB::Open(opt, path, &db);

read操作

>> [BlueStore.cc]
>> int BlueStore::read(const coll_t& cid, const ghobject_t& oid,
>> uint64_t offset, size_t length, bufferlist& bl, uint32_t op_flags)
>> read(c, oid, offset, length, bl, op_flags);

[BlueStore.cc]
int BlueStore::read(CollectionHandle &c_, const ghobject_t& oid,
  uint64_t offset, size_t length, bufferlist& bl, uint32_t op_flags)
>> OnodeRef o = c->get_onode(oid, false);
>> _do_read(c, o, offset, length, bl, op_flags);
>> [注]
>> 每个Onode包含一个ExtentMap,每个ExtentMap包含若干个Extent,
>> 每个Extent负责管理一段逻辑范围内的数据并管理一个Blob,
>> 由Blob通过若干个pextent负责将数据映射到磁盘

[BlueStore.cc]
BlueStore::OnodeRef BlueStore::Collection::get_onode(const ghobject_t& oid, bool create)
>> store->db->get(PREFIX_OBJ, key.c_str(), key.size(), &v);

[KeyValueDB.h]
virtual int get(const string &prefix,const char *key, size_t keylen, bufferlist *value)
>> get(prefix, string(key, keylen), value);

[KeyValueDB.h]
virtual int get(const std::string &prefix, const std::string &key, bufferlist *value)
>> get(prefix, ks, &om);

[RocksDBStore.cc]
int RocksDBStore::get(const string &prefix,
    const string &key, bufferlist *out)
>> db->Get(rocksdb::ReadOptions(), rocksdb::Slice(k), &value);

write操作

[BlueStore.cc]
void BlueStore::_kv_sync_thread()
>> db->submit_transaction_sync(synct);

[KeyValueDB.h]
virtual int submit_transaction_sync(Transaction t)
>> submit_transaction(t);

[RocksDBStore.cc]
int RocksDBStore::submit_transaction(KeyValueDB::Transaction t)
>> db->Write(woptions, &_t->bat);

remove操作

数据库中删除指定元数据键值对

[BlueStore.cc]
int BlueStore::_remove(TransContext *txc, CollectionRef& c, OnodeRef &o)
>> _do_remove(txc, c, o);

[BlueStore.cc]
int BlueStore::_do_remove(TransContext *txc,
  CollectionRef& c, OnodeRef o)
>> txc->t->rmkey(PREFIX_OBJ, o->key.c_str(), o->key.size());

[KeyValueDB.h]
virtual void rmkey(const std::string &prefix,   
  const char *k, size_t keylen)
>> rmkey(prefix, string(k, keylen));

[RocksDBStore.cc]
void RocksDBStore::RocksDBTransactionImpl::rmkey(const string &prefix, const string &k)
>> bat.Delete(combine_strings(prefix, k));

compact操作

可通过客户端命令行中对OSD相关指令(asok_command)

[BlueStore.h]
void compact() override
>> db->compact();

[RocksDBStore.cc]
void RocksDBStore::compact()
>> db->CompactRange(options, nullptr, nullptr);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值