HBASE-12434 Add a command to compact all the regions in a regionserver (Liu Shaohui)

This commit is contained in:
stack 2014-11-11 09:32:55 -08:00
parent df8859d5a5
commit e287741388
5 changed files with 71 additions and 0 deletions

View File

@ -593,6 +593,16 @@ public interface Admin extends Abortable, Closeable {
void majorCompactRegion(final byte[] regionName, final byte[] columnFamily)
throws IOException, InterruptedException;
/**
* Compact all regions on the region server
* @param regionserver the region server name
* @param major if it's major compaction
* @throws IOException
* @throws InterruptedException
*/
public void compactRegionServer(final ServerName sn, boolean major)
throws IOException, InterruptedException;
/**
* Move the region <code>r</code> to <code>dest</code>.
*

View File

@ -83,6 +83,7 @@ import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.RollWALWriterReque
import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.RollWALWriterResponse;
import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.StopServerRequest;
import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.UpdateConfigurationRequest;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair;
import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ProcedureDescription;
@ -1605,6 +1606,17 @@ public class HBaseAdmin implements Admin {
}
}
/**
* {@inheritDoc}
*/
@Override
public void compactRegionServer(final ServerName sn, boolean major)
throws IOException, InterruptedException {
for (HRegionInfo region : getOnlineRegions(sn)) {
compact(sn, region, major, null);
}
}
/**
* {@inheritDoc}
*/

View File

@ -65,6 +65,11 @@ module Hbase
end
end
# Requests to compact all regions on the regionserver
def compact_regionserver(servername, major = false)
@admin.compactRegionServer(ServerName.valueOf(servername), major)
end
#----------------------------------------------------------------------------------------------
# Requests a table or region or column family major compaction
def major_compact(table_or_region_name, family = nil)

View File

@ -325,6 +325,7 @@ Shell.load_command_group(
catalogjanitor_run
catalogjanitor_switch
catalogjanitor_enabled
compact_rs
trace
]
)

View File

@ -0,0 +1,43 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Shell
module Commands
class CompactRs < Command
def help
return <<-EOF
Compact all regions on passed regionserver.
Examples:
Compact all regions on a regionserver:
hbase> compact_rs 'host187.example.com,60020'
or
hbase> compact_rs 'host187.example.com,60020,1289493121758'
Major compact all regions on a regionserver:
hbase> compact_rs 'host187.example.com,60020,1289493121758', true
EOF
end
def command(regionserver, major = false)
format_simple_command do
admin.compact_regionserver(regionserver, major)
end
end
end
end
end