Skip to content

Commit 45f926d

Browse files
committed
HDFS-16535: SlotReleaser should reuse the domain socket based on socket paths
1 parent d5e97fe commit 45f926d

File tree

1 file changed

+15
-6
lines changed
  • hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit

1 file changed

+15
-6
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/shortcircuit/ShortCircuitCache.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,18 @@ public void run() {
189189
final DfsClientShm shm = (DfsClientShm)slot.getShm();
190190
final DomainSocket shmSock = shm.getPeer().getDomainSocket();
191191
final String path = shmSock.getPath();
192+
DomainSocket domainSocket = pathToDomainSocket.get(path);
192193
DataOutputStream out = null;
193194
boolean success = false;
194195
int retries = 2;
195196
try {
196197
while (retries > 0) {
197198
try {
198199
if (domainSocket == null || !domainSocket.isOpen()) {
199-
// we are running in single thread mode, no protection needed for
200-
// domainSocket
201200
domainSocket = DomainSocket.connect(path);
201+
// we are running in single thread mode, no protection needed for
202+
// pathToDomainSocket
203+
pathToDomainSocket.put(path, domainSocket);
202204
}
203205

204206
out = new DataOutputStream(
@@ -221,8 +223,11 @@ public void run() {
221223
} catch (SocketException se) {
222224
// the domain socket on datanode may be timed out, we retry once
223225
retries--;
224-
domainSocket.close();
225-
domainSocket = null;
226+
if (domainSocket != null) {
227+
domainSocket.close();
228+
domainSocket = null;
229+
pathToDomainSocket.remove(path);
230+
}
226231
if (retries == 0) {
227232
throw new SocketException("Create domain socket failed");
228233
}
@@ -240,7 +245,7 @@ public void run() {
240245
} else {
241246
shm.getEndpointShmManager().shutdown(shm);
242247
IOUtilsClient.cleanupWithLogger(LOG, domainSocket, out);
243-
domainSocket = null;
248+
pathToDomainSocket.remove(path);
244249
}
245250
}
246251
}
@@ -354,7 +359,11 @@ public interface ShortCircuitReplicaCreator {
354359
*/
355360
private final DfsClientShmManager shmManager;
356361

357-
private DomainSocket domainSocket = null;
362+
/**
363+
* A map contains all DomainSockets used in SlotReleaser. Keys are the domain socket
364+
* paths of short-circuit shared memory segments.
365+
*/
366+
private Map<String, DomainSocket> pathToDomainSocket = new HashMap<>();
358367

359368
public static ShortCircuitCache fromConf(ShortCircuitConf conf) {
360369
return new ShortCircuitCache(

0 commit comments

Comments
 (0)