run_sync_thread
// 元数据同步(同步配置)
meta_sync_processor_thread = new RGWMetaSyncProcessorThread(this->store, async_processor);
ret = meta_sync_processor_thread->init();
meta_sync_processor_thread->start();
// trim log
rgw::BucketTrimConfig config;
rgw::configure_bucket_trim(cct, config);
bucket_trim.emplace(this->store, config);
ret = bucket_trim->init();
svc.datalog_rados->set_observer(&*bucket_trim);
// 数据同步
for (auto source_zone : svc.zone->get_data_sync_source_zones()) {
// 如果有N个站点,则需要启动N-1个线程,分别从不同的站点同步数据
auto *thread = new RGWDataSyncProcessorThread(this->store, svc.rados->get_async_processor(), source_zone);
ret = thread->init();
thread->start(); // 启动一个线程 RGWRadosThread::start ---> RGWRadosThread::Worker::entry ---> RGWDataSyncProcessorThread:: process
data_sync_processor_threads[rgw_zone_id(source_zone->id)] = thread;
}
RGWDataSyncProcessorThread::process {
while (!initialized) {
int ret = sync.init(); // RGWDataSyncStatusManager sync; sync(_store, async_rados, source_zone->id, counters.get())
if (ret >= 0) {initialized = true; break;}
return 0; // 初始化失败则一直重试
}
sync.run();
}
int RGWDataSyncStatusManager::init() {
RGWZone *zone_def;
sync_module = store->getRados()->get_sync_module();
conn = store->svc()->zone->get_zone_conn(source_zone);
error_logger = new RGWSyncErrorLogger(store, RGW_SYNC_ERROR_LOG_SHARD_PREFIX, ERROR_LOGGER_SHARDS);
// RGWRemoteDataLog source_log; source_log(this, store, async_rados) this为 RGWDataSyncStatusManager
int r = source_log.init(source_zone, conn, error_logger, store->getRados()->get_sync_tracer(), sync_module, counters);
sync_env.init、sc.init(&sync_env, _conn, _source_zone);、ret = http_manager.start();
tn = sync_env.sync_tracer->add_node(sync_env.sync_tracer->root_node, "data"); initialized = true;
rgw_datalog_info datalog_info;
// 发送消息:request_uri=/admin/log?type=data&rgwx-zonegroup=zonegroup的Id
r = source_log.read_log_info(&datalog_info); //读取对端zone的 rgw_data_log_num_shards
num_shards = datalog_info.num_shards;
for (int i = 0; i < num_shards; i++)
// log_pool_name : 站点名.rgw.log "datalog.sync-status.shard.<src_zoneId>.<i>"
// 本端记录的从src_zone的同步进度
shard_objs[i] = rgw_raw_obj(zone_params.log_pool, shard_obj_name(source_zone, i));
}
// num_shards = 128
int RGWRemoteDataLog::run_sync(int num_shards) {
lock.lock();
// 数据同步入口
data_sync_cr = new RGWDataSyncControlCR(&sc, num_shards, tn);
data_sync_cr->get();
lock.unlock();
int r = run(data_sync_cr);
lock.lock();
data_sync_cr->put();
data_sync_cr = NULL;
lock.unlock();
return 0;
}
01 rgw multisite 同步数据 初始化进程
最新推荐文章于 2021-06-15 16:21:04 发布
本文详细介绍了数据同步的具体流程,包括元数据同步、trimlog配置及数据同步线程的启动过程。通过对RGWMetaSyncProcessorThread和RGWDataSyncProcessorThread等关键组件的解析,展示了如何实现跨站点的数据同步。
摘要由CSDN通过智能技术生成