HBASE-16446 append_peer_tableCFs failed when there already have this table's partial cfs in the peer (Guanghao Zhang)
This commit is contained in:
parent
2f7b9b5423
commit
77a7394f17
|
@ -289,13 +289,12 @@ public class ReplicationAdmin implements Closeable {
|
|||
Collection<String> appendCfs = entry.getValue();
|
||||
if (preTableCfs.containsKey(table)) {
|
||||
List<String> cfs = preTableCfs.get(table);
|
||||
if (cfs == null || appendCfs == null) {
|
||||
if (cfs == null || appendCfs == null || appendCfs.isEmpty()) {
|
||||
preTableCfs.put(table, null);
|
||||
} else {
|
||||
Set<String> cfSet = new HashSet<String>(cfs);
|
||||
cfSet.addAll(appendCfs);
|
||||
preTableCfs.put(table, Lists.newArrayList(cfSet));
|
||||
|
||||
}
|
||||
} else {
|
||||
if (appendCfs == null || appendCfs.isEmpty()) {
|
||||
|
@ -342,9 +341,9 @@ public class ReplicationAdmin implements Closeable {
|
|||
Collection<String> removeCfs = entry.getValue();
|
||||
if (preTableCfs.containsKey(table)) {
|
||||
List<String> cfs = preTableCfs.get(table);
|
||||
if (cfs == null && removeCfs == null) {
|
||||
if (cfs == null && (removeCfs == null || removeCfs.isEmpty())) {
|
||||
preTableCfs.remove(table);
|
||||
} else if (cfs != null && removeCfs != null) {
|
||||
} else if (cfs != null && (removeCfs != null && !removeCfs.isEmpty())) {
|
||||
Set<String> cfSet = new HashSet<String>(cfs);
|
||||
cfSet.removeAll(removeCfs);
|
||||
if (cfSet.isEmpty()) {
|
||||
|
@ -352,10 +351,10 @@ public class ReplicationAdmin implements Closeable {
|
|||
} else {
|
||||
preTableCfs.put(table, Lists.newArrayList(cfSet));
|
||||
}
|
||||
} else if (cfs == null && removeCfs != null) {
|
||||
} else if (cfs == null && (removeCfs != null && !removeCfs.isEmpty())) {
|
||||
throw new ReplicationException("Cannot remove cf of table: " + table
|
||||
+ " which doesn't specify cfs from table-cfs config in peer: " + id);
|
||||
} else if (cfs != null && removeCfs == null) {
|
||||
} else if (cfs != null && (removeCfs == null || removeCfs.isEmpty())) {
|
||||
throw new ReplicationException("Cannot remove table: " + table
|
||||
+ " which has specified cfs from table-cfs config in peer: " + id);
|
||||
}
|
||||
|
|
|
@ -216,6 +216,8 @@ public class TestReplicationAdmin {
|
|||
TableName tab2 = TableName.valueOf("t2");
|
||||
TableName tab3 = TableName.valueOf("t3");
|
||||
TableName tab4 = TableName.valueOf("t4");
|
||||
TableName tab5 = TableName.valueOf("t5");
|
||||
TableName tab6 = TableName.valueOf("t6");
|
||||
|
||||
// Add a valid peer
|
||||
admin.addPeer(ID_ONE, rpc1, null);
|
||||
|
@ -275,6 +277,34 @@ public class TestReplicationAdmin {
|
|||
assertEquals("f1", result.get(tab4).get(0));
|
||||
assertEquals("f2", result.get(tab4).get(1));
|
||||
|
||||
// append "table5" => [], then append "table5" => ["f1"]
|
||||
tableCFs.clear();
|
||||
tableCFs.put(tab5, new ArrayList<String>());
|
||||
admin.appendPeerTableCFs(ID_ONE, tableCFs);
|
||||
tableCFs.clear();
|
||||
tableCFs.put(tab5, new ArrayList<String>());
|
||||
tableCFs.get(tab5).add("f1");
|
||||
admin.appendPeerTableCFs(ID_ONE, tableCFs);
|
||||
result = ReplicationSerDeHelper.parseTableCFsFromConfig(admin.getPeerTableCFs(ID_ONE));
|
||||
assertEquals(5, result.size());
|
||||
assertTrue("Should contain t5", result.containsKey(tab5));
|
||||
// null means replication all cfs of tab5
|
||||
assertNull(result.get(tab5));
|
||||
|
||||
// append "table6" => ["f1"], then append "table6" => []
|
||||
tableCFs.clear();
|
||||
tableCFs.put(tab6, new ArrayList<String>());
|
||||
tableCFs.get(tab6).add("f1");
|
||||
admin.appendPeerTableCFs(ID_ONE, tableCFs);
|
||||
tableCFs.clear();
|
||||
tableCFs.put(tab6, new ArrayList<String>());
|
||||
admin.appendPeerTableCFs(ID_ONE, tableCFs);
|
||||
result = ReplicationSerDeHelper.parseTableCFsFromConfig(admin.getPeerTableCFs(ID_ONE));
|
||||
assertEquals(6, result.size());
|
||||
assertTrue("Should contain t6", result.containsKey(tab6));
|
||||
// null means replication all cfs of tab6
|
||||
assertNull(result.get(tab6));
|
||||
|
||||
admin.removePeer(ID_ONE);
|
||||
}
|
||||
|
||||
|
@ -285,6 +315,7 @@ public class TestReplicationAdmin {
|
|||
TableName tab1 = TableName.valueOf("t1");
|
||||
TableName tab2 = TableName.valueOf("t2");
|
||||
TableName tab3 = TableName.valueOf("t3");
|
||||
TableName tab4 = TableName.valueOf("t4");
|
||||
// Add a valid peer
|
||||
admin.addPeer(ID_ONE, rpc1, null);
|
||||
Map<TableName, List<String>> tableCFs = new HashMap<>();
|
||||
|
@ -345,6 +376,13 @@ public class TestReplicationAdmin {
|
|||
tableCFs.get(tab2).add("cf1");
|
||||
admin.removePeerTableCFs(ID_ONE, tableCFs);
|
||||
assertNull(admin.getPeerTableCFs(ID_ONE));
|
||||
|
||||
tableCFs.clear();
|
||||
tableCFs.put(tab4, new ArrayList<String>());
|
||||
admin.setPeerTableCFs(ID_ONE, tableCFs);
|
||||
admin.removePeerTableCFs(ID_ONE, tableCFs);
|
||||
assertNull(admin.getPeerTableCFs(ID_ONE));
|
||||
|
||||
admin.removePeer(ID_ONE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue