Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Solve #1732, fix YARN and MapReduce fails caused by getFileState #1733

Merged
merged 4 commits into from
May 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion smart-client/src/main/java/org/smartdata/client/SmartClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@
import org.smartdata.conf.SmartConfKeys;
import org.smartdata.metrics.FileAccessEvent;
import org.smartdata.model.FileState;
import org.smartdata.model.NormalFileState;
import org.smartdata.protocol.SmartClientProtocol;
import org.smartdata.protocol.protobuffer.ClientProtocolClientSideTranslator;
import org.smartdata.protocol.protobuffer.ClientProtocolProtoBuffer;

import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SmartClient implements java.io.Closeable, SmartClientProtocol {
private static final long VERSION = 1;
private Configuration conf;
private SmartClientProtocol server;
private volatile boolean running = true;
private List<String> ignoreAccessEventDirs;
private Map<String, Integer> singleIgnoreList;

public SmartClient(Configuration conf) throws IOException {
this.conf = conf;
Expand Down Expand Up @@ -76,6 +81,7 @@ private void initialize(InetSocketAddress address) throws IOException {
Collection<String> dirs = conf.getTrimmedStringCollection(
SmartConfKeys.SMART_IGNORE_DIRS_KEY);
ignoreAccessEventDirs = new ArrayList<>();
singleIgnoreList = new ConcurrentHashMap<>(200);
for (String s : dirs) {
ignoreAccessEventDirs.add(s + (s.endsWith("/") ? "" : "/"));
}
Expand All @@ -92,10 +98,23 @@ public void reportFileAccessEvent(FileAccessEvent event)

@Override
public FileState getFileState(String filePath) throws IOException {
return server.getFileState(filePath);
checkOpen();
try {
return server.getFileState(filePath);
} catch (ConnectException e) {
// client cannot connect to server
// don't report access event for this file this time
singleIgnoreList.put(filePath, 0);
return new NormalFileState(filePath);
}
}

private boolean shouldIgnore(String path) {
if (singleIgnoreList.containsKey(path)) {
// this report should be ignored
singleIgnoreList.remove(path);
return true;
}
String toCheck = path.endsWith("/") ? path : path + "/";
for (String s : ignoreAccessEventDirs) {
if (toCheck.startsWith(s)) {
Expand Down