Revert "HBASE-22820 Do not need to persist default rs group now (#482)"

This reverts commit 97ec5d53c0.
This commit is contained in:
Duo Zhang 2019-09-10 11:14:04 +08:00
parent 64581fa33b
commit 4a22c74b3c
2 changed files with 16 additions and 49 deletions

View File

@ -396,13 +396,11 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
} }
// populate puts // populate puts
for (RSGroupInfo gi : groupMap.values()) { for (RSGroupInfo RSGroupInfo : groupMap.values()) {
if (!gi.getName().equals(RSGroupInfo.DEFAULT_GROUP)) { RSGroupProtos.RSGroupInfo proto = ProtobufUtil.toProtoGroupInfo(RSGroupInfo);
RSGroupProtos.RSGroupInfo proto = ProtobufUtil.toProtoGroupInfo(gi); Put p = new Put(Bytes.toBytes(RSGroupInfo.getName()));
Put p = new Put(Bytes.toBytes(gi.getName())); p.addColumn(META_FAMILY_BYTES, META_QUALIFIER_BYTES, proto.toByteArray());
p.addColumn(META_FAMILY_BYTES, META_QUALIFIER_BYTES, proto.toByteArray()); mutations.add(p);
mutations.add(p);
}
} }
if (mutations.size() > 0) { if (mutations.size() > 0) {
@ -451,12 +449,7 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
// Make changes visible after having been persisted to the source of truth // Make changes visible after having been persisted to the source of truth
resetRSGroupMap(newGroupMap); resetRSGroupMap(newGroupMap);
saveRSGroupMapToZK(newGroupMap);
updateCacheOfRSGroups(newGroupMap.keySet());
}
private void saveRSGroupMapToZK(Map<String, RSGroupInfo> newGroupMap) throws IOException {
try { try {
String groupBasePath = String groupBasePath =
ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, RS_GROUP_ZNODE); ZNodePaths.joinZNode(watcher.getZNodePaths().baseZNode, RS_GROUP_ZNODE);
@ -470,16 +463,14 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
} }
} }
for (RSGroupInfo gi : newGroupMap.values()) { for (RSGroupInfo RSGroupInfo : newGroupMap.values()) {
if (!gi.getName().equals(RSGroupInfo.DEFAULT_GROUP)) { String znode = ZNodePaths.joinZNode(groupBasePath, RSGroupInfo.getName());
String znode = ZNodePaths.joinZNode(groupBasePath, gi.getName()); RSGroupProtos.RSGroupInfo proto = ProtobufUtil.toProtoGroupInfo(RSGroupInfo);
RSGroupProtos.RSGroupInfo proto = ProtobufUtil.toProtoGroupInfo(gi); LOG.debug("Updating znode: " + znode);
LOG.debug("Updating znode: " + znode); ZKUtil.createAndFailSilent(watcher, znode);
ZKUtil.createAndFailSilent(watcher, znode); zkOps.add(ZKUtil.ZKUtilOp.deleteNodeFailSilent(znode));
zkOps.add(ZKUtil.ZKUtilOp.deleteNodeFailSilent(znode)); zkOps.add(ZKUtil.ZKUtilOp.createAndFailSilent(znode,
zkOps.add(ZKUtil.ZKUtilOp.createAndFailSilent(znode, ProtobufUtil.prependPBMagic(proto.toByteArray())));
ProtobufUtil.prependPBMagic(proto.toByteArray())));
}
} }
LOG.debug("Writing ZK GroupInfo count: " + zkOps.size()); LOG.debug("Writing ZK GroupInfo count: " + zkOps.size());
@ -489,6 +480,7 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
masterServices.abort("Failed to write to rsGroupZNode", e); masterServices.abort("Failed to write to rsGroupZNode", e);
throw new IOException("Failed to write to rsGroupZNode", e); throw new IOException("Failed to write to rsGroupZNode", e);
} }
updateCacheOfRSGroups(newGroupMap.keySet());
} }
/** /**
@ -548,12 +540,12 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
// Called by ServerEventsListenerThread. Synchronize on this because redoing // Called by ServerEventsListenerThread. Synchronize on this because redoing
// the rsGroupMap then writing it out. // the rsGroupMap then writing it out.
private synchronized void updateDefaultServers(SortedSet<Address> servers) { private synchronized void updateDefaultServers(SortedSet<Address> servers) throws IOException {
RSGroupInfo info = rsGroupMap.get(RSGroupInfo.DEFAULT_GROUP); RSGroupInfo info = rsGroupMap.get(RSGroupInfo.DEFAULT_GROUP);
RSGroupInfo newInfo = new RSGroupInfo(info.getName(), servers); RSGroupInfo newInfo = new RSGroupInfo(info.getName(), servers);
HashMap<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap); HashMap<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
newGroupMap.put(newInfo.getName(), newInfo); newGroupMap.put(newInfo.getName(), newInfo);
resetRSGroupMap(newGroupMap); flushConfig(newGroupMap);
} }
/** /**

View File

@ -26,11 +26,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet;
import java.util.regex.Pattern;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
@ -136,13 +133,6 @@ public class VerifyingRSGroupAdminClient extends RSGroupAdminClient {
tds.addAll(admin.listTableDescriptors()); tds.addAll(admin.listTableDescriptors());
tds.addAll(admin.listTableDescriptorsByNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME)); tds.addAll(admin.listTableDescriptorsByNamespace(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME));
} }
SortedSet<Address> lives = Sets.newTreeSet();
for (ServerName sn : conn.getAdmin().getClusterMetrics().getLiveServerMetrics().keySet()) {
lives.add(sn.getAddress());
}
for (ServerName sn : conn.getAdmin().listDecommissionedRegionServers()) {
lives.remove(sn.getAddress());
}
try (Table table = conn.getTable(RSGroupInfoManagerImpl.RSGROUP_TABLE_NAME); try (Table table = conn.getTable(RSGroupInfoManagerImpl.RSGROUP_TABLE_NAME);
ResultScanner scanner = table.getScanner(new Scan())) { ResultScanner scanner = table.getScanner(new Scan())) {
for (;;) { for (;;) {
@ -154,22 +144,8 @@ public class VerifyingRSGroupAdminClient extends RSGroupAdminClient {
RSGroupInfoManagerImpl.META_FAMILY_BYTES, RSGroupInfoManagerImpl.META_QUALIFIER_BYTES)); RSGroupInfoManagerImpl.META_FAMILY_BYTES, RSGroupInfoManagerImpl.META_QUALIFIER_BYTES));
RSGroupInfo rsGroupInfo = ProtobufUtil.toGroupInfo(proto); RSGroupInfo rsGroupInfo = ProtobufUtil.toGroupInfo(proto);
groupMap.put(proto.getName(), RSGroupUtil.fillTables(rsGroupInfo, tds)); groupMap.put(proto.getName(), RSGroupUtil.fillTables(rsGroupInfo, tds));
for(Address address : rsGroupInfo.getServers()){
lives.remove(address);
}
} }
} }
SortedSet<TableName> tables = Sets.newTreeSet();
for (TableDescriptor td : conn.getAdmin().listTableDescriptors(Pattern.compile(".*"),
true)){
String groupName = td.getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP);
if (groupName.equals(RSGroupInfo.DEFAULT_GROUP)) {
tables.add(td.getTableName());
}
}
groupMap.put(RSGroupInfo.DEFAULT_GROUP,
new RSGroupInfo(RSGroupInfo.DEFAULT_GROUP, lives, tables));
assertEquals(Sets.newHashSet(groupMap.values()), Sets.newHashSet(wrapped.listRSGroups())); assertEquals(Sets.newHashSet(groupMap.values()), Sets.newHashSet(wrapped.listRSGroups()));
try { try {
String groupBasePath = ZNodePaths.joinZNode(zkw.getZNodePaths().baseZNode, "rsgroup"); String groupBasePath = ZNodePaths.joinZNode(zkw.getZNodePaths().baseZNode, "rsgroup");
@ -184,7 +160,6 @@ public class VerifyingRSGroupAdminClient extends RSGroupAdminClient {
zList.add(RSGroupUtil.fillTables(rsGroupInfo, tds)); zList.add(RSGroupUtil.fillTables(rsGroupInfo, tds));
} }
} }
groupMap.remove(RSGroupInfo.DEFAULT_GROUP);
assertEquals(zList.size(), groupMap.size()); assertEquals(zList.size(), groupMap.size());
for (RSGroupInfo rsGroupInfo : zList) { for (RSGroupInfo rsGroupInfo : zList) {
assertTrue(groupMap.get(rsGroupInfo.getName()).equals(rsGroupInfo)); assertTrue(groupMap.get(rsGroupInfo.getName()).equals(rsGroupInfo));