Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix(backup): use existing block_service_manager when add backup policy #661

Merged
merged 6 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 38 additions & 43 deletions src/block_service/block_service_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,49 @@ block_service_manager::block_service_manager()
{
}

block_service_manager::~block_service_manager()
{
zauto_write_lock l(_fs_lock);
_fs_map.clear();
ddebug("close block service manager.");
}

block_filesystem *block_service_manager::get_block_filesystem(const std::string &provider)
zhangyifan27 marked this conversation as resolved.
Show resolved Hide resolved
{
{
zauto_read_lock l(_fs_lock);
auto iter = _fs_map.find(provider);
if (iter != _fs_map.end())
return iter->second.get();
zauto_write_lock l(_fs_lock);
zhangyifan27 marked this conversation as resolved.
Show resolved Hide resolved
auto iter = _fs_map.find(provider);
if (iter != _fs_map.end()) {
return iter->second.get();
}

{
zauto_write_lock l(_fs_lock);
auto iter = _fs_map.find(provider);
if (iter != _fs_map.end())
return iter->second.get();

const char *provider_type = dsn_config_get_value_string(
(std::string("block_service.") + provider).c_str(), "type", "", "block service type");

block_filesystem *fs =
utils::factory_store<block_filesystem>::create(provider_type, PROVIDER_TYPE_MAIN);
if (fs == nullptr) {
derror("acquire block filesystem failed, provider = %s, provider_type = %s",
provider.c_str(),
provider_type);
return nullptr;
}
const char *provider_type = dsn_config_get_value_string(
(std::string("block_service.") + provider).c_str(), "type", "", "block service type");

const char *arguments =
dsn_config_get_value_string((std::string("block_service.") + provider).c_str(),
"args",
"",
"args for block_service");

std::vector<std::string> args;
utils::split_args(arguments, args);
dsn::error_code err = fs->initialize(args);

if (dsn::ERR_OK == err) {
ddebug("create block filesystem ok for provider(%s)", provider.c_str());
_fs_map.emplace(provider, std::unique_ptr<block_filesystem>(fs));
return fs;
} else {
derror("create block file system err(%s) for provider(%s)",
err.to_string(),
provider.c_str());
delete fs;
return nullptr;
}
block_filesystem *fs =
neverchanje marked this conversation as resolved.
Show resolved Hide resolved
utils::factory_store<block_filesystem>::create(provider_type, PROVIDER_TYPE_MAIN);
if (fs == nullptr) {
derror("acquire block filesystem failed, provider = %s, provider_type = %s",
zhangyifan27 marked this conversation as resolved.
Show resolved Hide resolved
provider.c_str(),
provider_type);
return nullptr;
}

const char *arguments = dsn_config_get_value_string(
(std::string("block_service.") + provider).c_str(), "args", "", "args for block_service");

std::vector<std::string> args;
utils::split_args(arguments, args);
dsn::error_code err = fs->initialize(args);

if (dsn::ERR_OK == err) {
ddebug("create block filesystem ok for provider(%s)", provider.c_str());
zhangyifan27 marked this conversation as resolved.
Show resolved Hide resolved
_fs_map.emplace(provider, std::unique_ptr<block_filesystem>(fs));
zhangyifan27 marked this conversation as resolved.
Show resolved Hide resolved
return fs;
} else {
derror(
"create block file system err(%s) for provider(%s)", err.to_string(), provider.c_str());
delete fs;
return nullptr;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/block_service/block_service_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class block_service_manager
{
public:
block_service_manager();
~block_service_manager();
block_filesystem *get_block_filesystem(const std::string &provider);

// download files from remote file system
Expand Down
29 changes: 5 additions & 24 deletions src/meta/meta_backup_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,22 +865,6 @@ bool policy_context::is_under_backuping()
return false;
}

void policy_context::set_policy(policy &&p)
{
zauto_lock l(_lock);

const std::string old_backup_provider_type = _policy.backup_provider_type;
_policy = std::move(p);
if (_policy.backup_provider_type != old_backup_provider_type) {
_block_service =
_backup_service->get_meta_service()->get_block_service_manager().get_block_filesystem(
_policy.backup_provider_type);
}
dassert(_block_service,
"can't initialize block filesystem by provider (%s)",
_policy.backup_provider_type.c_str());
}

void policy_context::set_policy(const policy &p)
{
zauto_lock l(_lock);
Expand Down Expand Up @@ -1279,14 +1263,11 @@ void backup_service::add_backup_policy(dsn::message_ex *msg)
}
}

{
dist::block_service::block_service_manager _block_service_manager;
if (_block_service_manager.get_block_filesystem(request.backup_provider_type) ==
nullptr) {
derror("invalid backup_provider_type(%s)", request.backup_provider_type.c_str());
response.err = ERR_INVALID_PARAMETERS;
should_create_new_policy = false;
}
if (_meta_svc->get_block_service_manager().get_block_filesystem(
request.backup_provider_type) == nullptr) {
derror("invalid backup_provider_type(%s)", request.backup_provider_type.c_str());
response.err = ERR_INVALID_PARAMETERS;
should_create_new_policy = false;
}

if (should_create_new_policy) {
Expand Down
1 change: 0 additions & 1 deletion src/meta/meta_backup_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class policy_context
}
mock_virtual ~policy_context() {}

void set_policy(policy &&p);
void set_policy(const policy &p);
policy get_policy();
void add_backup_history(const backup_info &info);
Expand Down