Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.hadoop.conf.Configuration;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.wal.RegionGroupingProvider.RegionGroupingStrategy;
import org.apache.yetus.audience.InterfaceAudience;

/**
* A WAL grouping strategy that limits the number of wal groups to
Expand All @@ -43,9 +43,8 @@ public class BoundedGroupingStrategy implements RegionGroupingStrategy{
private String[] groupNames;

@Override
public String group(byte[] identifier, byte[] namespace) {
String idStr = Bytes.toString(identifier);
return computeIfAbsent(groupNameCache, idStr,
public String group(RegionInfo region) {
return computeIfAbsent(groupNameCache, region.getEncodedName(),
() -> groupNames[getAndIncrAtomicInteger(counter, groupNames.length)]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
package org.apache.hadoop.hbase.wal;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.wal.RegionGroupingProvider.RegionGroupingStrategy;
import org.apache.yetus.audience.InterfaceAudience;

/**
* A WAL grouping strategy based on namespace.
Expand All @@ -34,14 +33,8 @@ public class NamespaceGroupingStrategy implements RegionGroupingStrategy {
String providerId;

@Override
public String group(byte[] identifier, byte[] namespace) {
String namespaceString;
if (namespace == null || namespace.length == 0) {
namespaceString = NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR;
} else {
namespaceString = Bytes.toString(namespace);
}
return providerId + GROUP_NAME_DELIMITER + namespaceString;
public String group(RegionInfo region) {
return providerId + GROUP_NAME_DELIMITER + region.getTable().getNamespaceAsString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL;
// imports for classes still in regionserver.wal
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.KeyLocker;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
Expand All @@ -55,6 +53,8 @@
* "bounded".</li>
* <li><em>identity</em> : each region belongs to its own group.</li>
* <li><em>bounded</em> : bounded number of groups and region evenly assigned to each group.</li>
* <li><em>namespace</em> : region of the same namespace assigned to the same group.</li>
* <li><em>table</em> : region of the same table assigned to the same group.</li>
* </ul>
* Optionally, a FQCN to a custom implementation may be given.
*/
Expand All @@ -69,9 +69,9 @@ public static interface RegionGroupingStrategy {
String GROUP_NAME_DELIMITER = ".";

/**
* Given an identifier and a namespace, pick a group.
* Given an region, pick a group.
*/
String group(final byte[] identifier, byte[] namespace);
String group(RegionInfo region);
void init(Configuration config, String providerId);
}

Expand All @@ -82,7 +82,8 @@ static enum Strategies {
defaultStrategy(BoundedGroupingStrategy.class),
identity(IdentityGroupingStrategy.class),
bounded(BoundedGroupingStrategy.class),
namespace(NamespaceGroupingStrategy.class);
namespace(NamespaceGroupingStrategy.class),
table(TableGroupingStrategy.class);

final Class<? extends RegionGroupingStrategy> clazz;
Strategies(Class<? extends RegionGroupingStrategy> clazz) {
Expand Down Expand Up @@ -210,16 +211,10 @@ public WAL getWAL(RegionInfo region) throws IOException {
if (META_WAL_PROVIDER_ID.equals(this.providerId)) {
group = META_WAL_GROUP_NAME;
} else {
byte[] id;
byte[] namespace;
if (region != null) {
id = region.getEncodedNameAsBytes();
namespace = region.getTable().getNamespace();
} else {
id = HConstants.EMPTY_BYTE_ARRAY;
namespace = null;
if (region == null) {
return getWAL("");
}
group = strategy.group(id, namespace);
group = strategy.group(region);
}
return getWAL(group);
}
Expand Down Expand Up @@ -268,8 +263,8 @@ static class IdentityGroupingStrategy implements RegionGroupingStrategy {
@Override
public void init(Configuration config, String providerId) {}
@Override
public String group(final byte[] identifier, final byte[] namespace) {
return Bytes.toString(identifier);
public String group(RegionInfo region) {
return region.getEncodedName();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
*
* 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.
*/
package org.apache.hadoop.hbase.wal;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.wal.RegionGroupingProvider.RegionGroupingStrategy;
import org.apache.yetus.audience.InterfaceAudience;

/**
* A WAL grouping strategy based on table.
*/
@InterfaceAudience.Private
public class TableGroupingStrategy implements RegionGroupingStrategy {
String providerId;

@Override
public String group(RegionInfo region) {
TableName tableName = region.getTable();
return new StringBuilder(providerId).append(GROUP_NAME_DELIMITER)
.append(tableName.getNamespaceAsString()).append(GROUP_NAME_DELIMITER)
.append(tableName.getQualifierAsString()).toString();
}

@Override
public void init(Configuration config, String providerId) {
this.providerId = providerId;
}

}