Skip to content

Commit 20b7c8b

Browse files
authored
HBASE-26089 Support RegionCoprocessor on CompactionServer (#3580)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 68800b5 commit 20b7c8b

18 files changed

+1420
-150
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/AbstractServer.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
*/
1818
package org.apache.hadoop.hbase;
1919

20+
import static org.apache.hadoop.hbase.compactionserver.HCompactionServer.COMPACTIONSERVER;
21+
import static org.apache.hadoop.hbase.master.HMaster.MASTER;
22+
import static org.apache.hadoop.hbase.regionserver.HRegionServer.REGIONSERVER;
23+
2024
import java.io.IOException;
2125
import java.lang.reflect.Constructor;
2226
import java.lang.reflect.InvocationTargetException;
@@ -431,4 +435,18 @@ public FileSystem getFileSystem() {
431435
protected abstract AbstractRpcServices getRpcService();
432436

433437
protected abstract String getProcessName();
438+
439+
public ServerType getServerType() {
440+
String processName = getProcessName();
441+
if (processName.equals(MASTER)) {
442+
return ServerType.Master;
443+
}
444+
if (processName.equals(REGIONSERVER)) {
445+
return ServerType.RegionServer;
446+
}
447+
if (processName.equals(COMPACTIONSERVER)) {
448+
return ServerType.CompactionServer;
449+
}
450+
return ServerType.ReplicationServer;
451+
}
434452
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.hbase;
20+
21+
import org.apache.yetus.audience.InterfaceAudience;
22+
23+
/**
24+
* Enum describing Server Type
25+
*/
26+
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
27+
public enum ServerType {
28+
Master, RegionServer, CompactionServer, ReplicationServer
29+
}

hbase-server/src/main/java/org/apache/hadoop/hbase/compactionserver/CompactionThreadManager.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22-
import java.util.Collection;
2322
import java.util.Collections;
2423
import java.util.Comparator;
2524
import java.util.HashSet;
@@ -240,7 +239,7 @@ Optional<CompactionContext> selectCompaction(HStore store, RegionInfo regionInfo
240239
excludeFiles.addAll(compactedFiles);
241240
// Convert files names to store files
242241
status.setStatus("Convert current compacting and compacted files to store files");
243-
List<HStoreFile> excludeStoreFiles = getExcludedStoreFiles(store, excludeFiles);
242+
List<HStoreFile> excludeStoreFiles = store.getStoreFilesBaseOnFileNames(excludeFiles);
244243
LOG.info(
245244
"Start select store: {}, excludeFileNames: {}, excluded: {}, compacting: {}, compacted: {}",
246245
logStr, excludeFiles.size(), excludeStoreFiles.size(), compactingFiles.size(),
@@ -354,23 +353,11 @@ private void reportCompactionCompleted(CompactionTask task, List<String> newFile
354353
}
355354
}
356355

357-
private List<HStoreFile> getExcludedStoreFiles(HStore store, Set<String> excludeFileNames) {
358-
Collection<HStoreFile> storefiles = store.getStorefiles();
359-
List<HStoreFile> storeFiles = new ArrayList<>();
360-
for (HStoreFile storefile : storefiles) {
361-
String name = storefile.getPath().getName();
362-
if (excludeFileNames.contains(name)) {
363-
storeFiles.add(storefile);
364-
}
365-
}
366-
return storeFiles;
367-
}
368-
369356
private HStore getStore(final Configuration conf, final FileSystem fs, final Path rootDir,
370357
final TableDescriptor htd, final RegionInfo hri, final String familyName) throws IOException {
371358
HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs,
372359
CommonFSUtils.getTableDir(rootDir, htd.getTableName()), hri);
373-
HRegion region = new HRegion(regionFs, null, conf, htd, null);
360+
HRegion region = new HRegion(regionFs, conf, htd, server);
374361
ColumnFamilyDescriptor columnFamilyDescriptor = htd.getColumnFamily(Bytes.toBytes(familyName));
375362
HStore store;
376363
if (columnFamilyDescriptor.isMobEnabled()) {

hbase-server/src/main/java/org/apache/hadoop/hbase/compactionserver/HCompactionServer.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.util.Collection;
22+
import java.util.List;
2223
import java.util.concurrent.atomic.LongAdder;
2324

2425
import org.apache.hadoop.conf.Configuration;
@@ -28,9 +29,12 @@
2829
import org.apache.hadoop.hbase.HBaseConfiguration;
2930
import org.apache.hadoop.hbase.HConstants;
3031
import org.apache.hadoop.hbase.ServerName;
32+
import org.apache.hadoop.hbase.TableName;
3133
import org.apache.hadoop.hbase.YouAreDeadException;
34+
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorService;
3235
import org.apache.hadoop.hbase.fs.HFileSystem;
3336
import org.apache.hadoop.hbase.log.HBaseMarkers;
37+
import org.apache.hadoop.hbase.regionserver.HRegion;
3438
import org.apache.hadoop.hbase.regionserver.compactions.CompactionProgress;
3539
import org.apache.hadoop.hbase.security.SecurityConstants;
3640
import org.apache.hadoop.hbase.security.Superusers;
@@ -54,7 +58,7 @@
5458
import org.apache.hadoop.hbase.shaded.protobuf.generated.CompactionServerStatusProtos.CompactionServerStatusService;
5559

5660
@InterfaceAudience.Private
57-
public class HCompactionServer extends AbstractServer {
61+
public class HCompactionServer extends AbstractServer implements RegionCoprocessorService {
5862

5963
/** compaction server process name */
6064
public static final String COMPACTIONSERVER = "compactionserver";
@@ -312,4 +316,21 @@ static HCompactionServer constructCompactionServer(
312316
}
313317
}
314318

319+
@Override
320+
public HRegion getRegion(final String encodedRegionName) {
321+
throw new UnsupportedOperationException(
322+
"Method getRegion is not supported in HCompactionServer");
323+
}
324+
325+
@Override
326+
public List<HRegion> getRegions(TableName tableName) {
327+
throw new UnsupportedOperationException(
328+
"Method getRegions is not supported in HCompactionServer");
329+
}
330+
331+
@Override
332+
public List<HRegion> getRegions() {
333+
throw new UnsupportedOperationException(
334+
"Method getRegions is not supported in HCompactionServer");
335+
}
315336
}

0 commit comments

Comments
 (0)