Boyi Dai created HBASE-30581:
--------------------------------
Summary: Removing an RSGroup can race with creating a namespace
that uses it
Key: HBASE-30581
URL: https://issues.apache.org/jira/browse/HBASE-30581
Project: HBase
Issue Type: Bug
Components: rsgroup
Affects Versions: 3.0.0, 4.0.0-alpha-1
Reporter: Boyi Dai
A namespace can be created with {{hbase.rsgroup.name}} pointing at an RSGroup
that was removed while the namespace was being created.
{{CreateNamespaceProcedure}} checks the group in {{CREATE_NAMESPACE_PREPARE}}
({{checkNamespaceRSGroup}}: the group exists and has servers), and writes the
namespace two states later in {{CREATE_NAMESPACE_INSERT_INTO_NS_TABLE}} without
checking again. The procedure holds the namespace lock, not anything on the
group. {{RSGroupInfoManagerImpl.removeRSGroup}} refuses to remove a group that
has servers, or that a table or an existing namespace references, but a
namespace that is still being created is not in
{{getClusterSchema().getNamespaces()}} yet, so it is not seen:
# {{CreateNamespaceProcedure}} for namespace N with group G passes
{{CREATE_NAMESPACE_PREPARE}}.
# Another admin moves the last server out of G and removes G. Both succeed.
# The procedure writes N with {{hbase.rsgroup.name=G}} and finishes
successfully.
# Creating a table in N then fails in {{MasterProcedureUtil.checkGroupExists}}
because G does not exist, and that stays so across restarts until G is
recreated with at least one server or N is modified.
{{ModifyNamespaceProcedure}} has the same gap when it changes the namespace's
group. Creating or modifying a table that uses a group has a similar gap, which
I'll file separately since the fix is different.
This was found through code analysis, and I reproduced it with a test that
holds a {{CreateNamespaceProcedure}} after {{CREATE_NAMESPACE_PREPARE}} (and a
{{ModifyNamespaceProcedure}} after its prepare state), empties and removes the
group, and lets the procedure finish: the namespace is written referencing a
group that does not exist.
*Expected:* removing a group fails while a namespace that uses it is being
created or modified, as it does for a namespace that already exists.
*Proposed fix:* in {{removeRSGroup}}, also refuse when an unfinished
{{CreateNamespaceProcedure}} or {{ModifyNamespaceProcedure}} references the
group. For that to cover a procedure that checks its group while the removal is
running, the procedures check the group through a new
{{RSGroupInfoManager.getRSGroupAfterPendingChanges}}, which takes the same lock
as {{removeRSGroup}}: either the procedure checks first and {{removeRSGroup}}
sees it, or the removal finishes first and the check fails.
I have a patch with a test and will open a PR.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)