You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@distributedlog.apache.org by si...@apache.org on 2016/12/21 08:00:22 UTC
[14/29] incubator-distributedlog git commit: Assign host ip client id
if the client id is undefined
Assign host ip client id if the client id is undefined
RB_ID=843132
Project: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/commit/f4f633fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/tree/f4f633fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/diff/f4f633fe
Branch: refs/heads/merge/DL-98
Commit: f4f633fe655e7146d5aad89c24f7e7107ab65ab2
Parents: f18fe17
Author: Leigh Stewart <ls...@twitter.com>
Authored: Mon Dec 12 16:59:38 2016 -0800
Committer: Sijie Guo <si...@twitter.com>
Committed: Mon Dec 12 16:59:38 2016 -0800
----------------------------------------------------------------------
.../distributedlog/BKDistributedLogNamespace.java | 15 ++++++++++++++-
.../com/twitter/distributedlog/BKLogHandler.java | 16 +---------------
2 files changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/f4f633fe/distributedlog-core/src/main/java/com/twitter/distributedlog/BKDistributedLogNamespace.java
----------------------------------------------------------------------
diff --git a/distributedlog-core/src/main/java/com/twitter/distributedlog/BKDistributedLogNamespace.java b/distributedlog-core/src/main/java/com/twitter/distributedlog/BKDistributedLogNamespace.java
index 7a4fd7f..2df1046 100644
--- a/distributedlog-core/src/main/java/com/twitter/distributedlog/BKDistributedLogNamespace.java
+++ b/distributedlog-core/src/main/java/com/twitter/distributedlog/BKDistributedLogNamespace.java
@@ -75,6 +75,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.URI;
import java.util.Collection;
import java.util.HashMap;
@@ -252,6 +253,14 @@ public class BKDistributedLogNamespace implements DistributedLogNamespace {
}
}
+ private static String getHostIpLockClientId() {
+ try {
+ return InetAddress.getLocalHost().toString();
+ } catch(Exception ex) {
+ return DistributedLogConstants.UNKNOWN_CLIENT_ID;
+ }
+ }
+
private final String clientId;
private final int regionId;
private final DistributedLogConfiguration conf;
@@ -326,9 +335,13 @@ public class BKDistributedLogNamespace implements DistributedLogNamespace {
this.featureProvider = featureProvider;
this.statsLogger = statsLogger;
this.perLogStatsLogger = perLogStatsLogger;
- this.clientId = clientId;
this.regionId = regionId;
this.bkdlConfig = bkdlConfig;
+ if (clientId.equals(DistributedLogConstants.UNKNOWN_CLIENT_ID)) {
+ this.clientId = getHostIpLockClientId();
+ } else {
+ this.clientId = clientId;
+ }
// Build resources
StatsLogger schedulerStatsLogger = statsLogger.scope("factory").scope("thread_pool");
http://git-wip-us.apache.org/repos/asf/incubator-distributedlog/blob/f4f633fe/distributedlog-core/src/main/java/com/twitter/distributedlog/BKLogHandler.java
----------------------------------------------------------------------
diff --git a/distributedlog-core/src/main/java/com/twitter/distributedlog/BKLogHandler.java b/distributedlog-core/src/main/java/com/twitter/distributedlog/BKLogHandler.java
index a84261a..3b991e2 100644
--- a/distributedlog-core/src/main/java/com/twitter/distributedlog/BKLogHandler.java
+++ b/distributedlog-core/src/main/java/com/twitter/distributedlog/BKLogHandler.java
@@ -56,7 +56,6 @@ import scala.runtime.AbstractFunction0;
import scala.runtime.BoxedUnit;
import java.io.IOException;
-import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -274,12 +273,7 @@ public abstract class BKLogHandler implements Watcher, AsyncCloseable, AsyncAbor
LOG.debug("Using ZK Path {}", logMetadata.getLogRootPath());
this.bookKeeperClient = bkcBuilder.build();
this.metadataStore = metadataStore;
-
- if (lockClientId.equals(DistributedLogConstants.UNKNOWN_CLIENT_ID)) {
- this.lockClientId = getHostIpLockClientId();
- } else {
- this.lockClientId = lockClientId;
- }
+ this.lockClientId = lockClientId;
this.getChildrenWatcher = this.zooKeeperClient.getWatcherManager()
.registerChildWatcher(logMetadata.getLogSegmentsPath(), this);
@@ -316,14 +310,6 @@ public abstract class BKLogHandler implements Watcher, AsyncCloseable, AsyncAbor
return lockClientId;
}
- private String getHostIpLockClientId() {
- try {
- return InetAddress.getLocalHost().toString();
- } catch(Exception ex) {
- return DistributedLogConstants.UNKNOWN_CLIENT_ID;
- }
- }
-
protected void registerListener(LogSegmentListener listener) {
listeners.add(listener);
}