Skip to content

Commit

Permalink
Fixed issue of table-config-version not increasing during table cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
jzgithub1 committed Nov 19, 2019
1 parent a6fd57d commit 9a6d726
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void process(WatchedEvent event) {
if (log.isTraceEnabled()) {
log.trace("{}", event);
}
setWatcherForTableConfigVersion(event);
setWatcherForTableConfigVersion(event.getPath());

switch (event.getType()) {
case NodeDataChanged:
Expand All @@ -177,7 +177,7 @@ public void process(WatchedEvent event) {
"ZCacheWatcher::processTableConfigurationItem failed to process a table configuration change");
updateAllTableConfigurations();
tableConfigWatcherSet = false;
setWatcherForTableConfigVersion(event);
setWatcherForTableConfigVersion(event.getPath());
}
break;
}
Expand Down Expand Up @@ -315,18 +315,18 @@ private synchronized void updateAllTableConfigurations() {
* worked when we watched all table configurations and we are just emulating it now using only
* one watched node for all the configuration items - the "table-config-version node".
*
* @param event
* @param zPath
* Contains a Zpath which the will be used to extract the accumulo instance id which
* will be used to create the Zpath to the table_config_version znode so a initial
* watcher can be put on it.
*/
private synchronized void setWatcherForTableConfigVersion(WatchedEvent event) {
private synchronized void setWatcherForTableConfigVersion(String zPath) {

if (event.getPath() == null || event.getPath().isEmpty())
if (zPath == null || zPath.isEmpty())
return;

if (!tableConfigWatcherSet) {
Matcher znodeMatcher = ZNODE_PATTERN.matcher(event.getPath());
Matcher znodeMatcher = ZNODE_PATTERN.matcher(zPath);
if (znodeMatcher.matches()) {
String pathPrefix = znodeMatcher.group(1);
try {
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;

import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
Expand Down Expand Up @@ -400,6 +401,8 @@ public static boolean exists(ZooKeeperConnectionInfo info, String zPath)
public static void recursiveCopyPersistent(ZooKeeperConnectionInfo info, String source,
String destination, NodeExistsPolicy policy) throws KeeperException, InterruptedException {
Stat stat = null;
Matcher tableConfigMatcher;

if (!exists(info, source))
throw KeeperException.create(Code.NONODE, source);
if (exists(info, destination)) {
Expand All @@ -420,7 +423,16 @@ public static void recursiveCopyPersistent(ZooKeeperConnectionInfo info, String
if (stat.getEphemeralOwner() == 0) {
if (data == null)
throw KeeperException.create(Code.NONODE, source);

putPersistentData(info, destination, data, policy);

// The clone table operation doesn't use TablePropUtil.setTableProperty but we still need to
// update the table-config-version znode.
tableConfigMatcher = ZooCache.TABLE_SETTING_CONFIG_PATTERN.matcher(destination);
if (tableConfigMatcher.matches())
putPersistentData(info, tableConfigMatcher.group(1) + Constants.ZTABLE_CONFIG_VERSION,
destination.getBytes(), policy);

if (stat.getNumChildren() > 0) {
List<String> children;
final Retry retry = RETRY_FACTORY.createRetry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static String getTablePath(String zkRoot, TableId tableId) {
* If the putPersistant data call this exception may be thrown
*/

private static void updateTableConfigTrackingZnode(String zPath, ZooReaderWriter zoo)
public static void updateTableConfigTrackingZnode(String zPath, ZooReaderWriter zoo)
throws KeeperException, InterruptedException {

String pathPrefix;
Expand Down

0 comments on commit 9a6d726

Please sign in to comment.