Boyi Dai created HBASE-30583:
--------------------------------

             Summary: Removing, emptying or renaming an RSGroup can race with 
creating a table that uses it
                 Key: HBASE-30583
                 URL: https://issues.apache.org/jira/browse/HBASE-30583
             Project: HBase
          Issue Type: Bug
          Components: rsgroup
    Affects Versions: 4.0.0-alpha-1, 3.0.0
            Reporter: Boyi Dai


A table can be created with its RSGroup pointing at a group that was removed, 
emptied or renamed while the table was being created.

{{CreateTableProcedure}} checks the table's group in {{prepareCreate}}, in 
{{CREATE_TABLE_PRE_OPERATION}} (the group exists and has servers), and the 
descriptor is written later in {{CREATE_TABLE_WRITE_FS_LAYOUT}} without 
checking again. In between, nothing stops the group from changing, because 
{{RSGroupInfoManagerImpl}} only looks at tables that already have a descriptor:
* {{moveServers}} refuses to move the last servers out of a group only if an 
existing table references it 
({{masterServices.getTableDescriptors().getAll()}}).
* {{removeRSGroup}} refuses to remove a group only if an existing table or 
namespace references it.
* {{renameRSGroup}} only updates the descriptors of existing tables.

So for example:
# {{CreateTableProcedure}} for table T with group G passes 
{{CREATE_TABLE_PRE_OPERATION}}.
# Another admin moves the last server out of G and removes G. Both succeed.
# The procedure writes T's descriptor with group G and finishes successfully, 
and T now references a group that does not exist.

If G is only emptied, or renamed, T ends up in a group with no servers, or in a 
group that no longer exists under that name.

{{ModifyTableProcedure}} has the same gap when it changes a table's group: it 
checks the new group in {{MODIFY_TABLE_PREPARE}} and writes the descriptor in 
{{MODIFY_TABLE_UPDATE_TABLE_DESCRIPTOR}}.

This was found through code analysis while working on HBASE-30581, which is the 
same race for namespaces. I reproduced the create case with a test that holds a 
{{CreateTableProcedure}} before {{CREATE_TABLE_WRITE_FS_LAYOUT}}, moves the 
group's only server to default and removes the group: both calls succeed, the 
procedure finishes successfully, and the table's descriptor references the 
removed group. The modify case is from reading the code.

*Expected:* moving the last servers out of a group, removing it or renaming it 
fails (or the table procedure fails) while a table that uses the group is being 
created or modified, as it does for a table that already exists.

*Possible fix:* the same approach as HBASE-30581, where {{moveServers}}, 
{{removeRSGroup}} and {{renameRSGroup}} also look at unfinished 
{{CreateTableProcedure}} and {{ModifyTableProcedure}} instances, and the 
procedures check the group under the same lock. Unlike the namespace case this 
also involves {{moveServers}}, which holds that lock while it moves regions, so 
table creation could wait on a server move. I'm happy to work on a patch once 
HBASE-30581 is settled, in case the approach there changes.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to