Skip to content

Commit

Permalink
HBASE-27030 Fix undefined local variable error in draining_servers.rb (
Browse files Browse the repository at this point in the history
…apache#4427)

HBASE-21812 replaced a for-loop with an each block.
Each block introduces a new scope, so a local variable defined inside it
cannot be accessed afterwards.

  NameError: undefined local variable or method `admin' for main:Object
    getServerNames at /opt/khp/hbase/bin/draining_servers.rb:81
        addServers at /opt/khp/hbase/bin/draining_servers.rb:88
            <main> at /opt/khp/hbase/bin/draining_servers.rb:146

This commit defines the admin local variable in the current scope beforehand,
so that we can still access it after the block.

Signed-off-by: Duo Zhang <[email protected]>
(cherry picked from commit 2b573ae)
Change-Id: Id7026f6f46e2149d458d1b69db82143fea5ba9aa
  • Loading branch information
junegunn authored and Stephen Wu committed Jun 28, 2022
1 parent f4f6387 commit 09209fb
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions bin/draining_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def getServers(admin)
def getServerNames(hostOrServers, config)
ret = []
connection = ConnectionFactory.createConnection(config)
admin = nil

hostOrServers.each do |host_or_server|
# check whether it is already serverName. No need to connect to cluster
Expand Down

0 comments on commit 09209fb

Please sign in to comment.