Skip to content

Commit

Permalink
Solve #1416, Complete disable SmartClient on node
Browse files Browse the repository at this point in the history
  • Loading branch information
littlezhou committed Nov 20, 2017
1 parent 96ae0e2 commit 6887fd2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions smart-common/src/main/java/org/smartdata/SmartConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ public class SmartConstants {

public static final String SMART_ADMIN_PROTOCOL_NAME =
"org.smartdata.protocol.SmartAdminProtocol";

public static final String SMART_CLIENT_DISABLED_ID_FILE =
"/tmp/SMART_CLIENT_DISABLED_ID_FILE";
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import org.apache.hadoop.hdfs.DFSInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartdata.SmartConstants;
import org.smartdata.client.SmartClient;
import org.smartdata.metrics.FileAccessEvent;

import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
Expand All @@ -39,6 +41,9 @@ public class SmartDFSClient extends DFSClient {
public SmartDFSClient(InetSocketAddress nameNodeAddress, Configuration conf,
InetSocketAddress smartServerAddress) throws IOException {
super(nameNodeAddress, conf);
if (isSmartClientDisabled()) {
return;
}
try {
smartClient = new SmartClient(conf, smartServerAddress);
healthy = true;
Expand All @@ -51,7 +56,9 @@ public SmartDFSClient(InetSocketAddress nameNodeAddress, Configuration conf,
public SmartDFSClient(final URI nameNodeUri, final Configuration conf,
final InetSocketAddress smartServerAddress) throws IOException {
super(nameNodeUri, conf);

if (isSmartClientDisabled()) {
return;
}
try {
smartClient = new SmartClient(conf, smartServerAddress);
healthy = true;
Expand All @@ -65,6 +72,9 @@ public SmartDFSClient(URI nameNodeUri, Configuration conf,
FileSystem.Statistics stats, InetSocketAddress smartServerAddress)
throws IOException {
super(nameNodeUri, conf, stats);
if (isSmartClientDisabled()) {
return;
}
try {
smartClient = new SmartClient(conf, smartServerAddress);
healthy = true;
Expand All @@ -77,6 +87,9 @@ public SmartDFSClient(URI nameNodeUri, Configuration conf,
public SmartDFSClient(Configuration conf,
InetSocketAddress smartServerAddress) throws IOException {
super(conf);
if (isSmartClientDisabled()) {
return;
}
try {
smartClient = new SmartClient(conf, smartServerAddress);
healthy = true;
Expand All @@ -88,6 +101,9 @@ public SmartDFSClient(Configuration conf,

public SmartDFSClient(Configuration conf) throws IOException {
super(conf);
if (isSmartClientDisabled()) {
return;
}
try {
smartClient = new SmartClient(conf);
healthy = true;
Expand Down Expand Up @@ -146,9 +162,14 @@ public synchronized void close() throws IOException {
if (smartClient != null) {
smartClient.close();
}
}finally {
} finally {
healthy = false;
}
}
}

private boolean isSmartClientDisabled() {
File idFile = new File(SmartConstants.SMART_CLIENT_DISABLED_ID_FILE);
return idFile.exists();
}
}

0 comments on commit 6887fd2

Please sign in to comment.