Skip to content

Commit b2cb6b9

Browse files
harshith-212shubhluck
authored andcommitted
Revert "HDFS-14304: High lock contention on hdfsHashMutex in libhdfs"
This reverts commit 350ffec.
1 parent 437a8a8 commit b2cb6b9

File tree

16 files changed

+732
-549
lines changed

16 files changed

+732
-549
lines changed

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ include_directories(
2929

3030
add_library(native_mini_dfs
3131
native_mini_dfs.c
32+
../libhdfs/common/htable.c
3233
../libhdfs/exception.c
33-
../libhdfs/jclasses.c
3434
../libhdfs/jni_helper.c
3535
${OS_DIR}/mutexes.c
3636
${OS_DIR}/thread_local_storage.c
@@ -39,3 +39,6 @@ add_library(native_mini_dfs
3939
add_executable(test_native_mini_dfs test_native_mini_dfs.c)
4040
target_link_libraries(test_native_mini_dfs native_mini_dfs ${JAVA_JVM_LIBRARY})
4141
add_test(test_test_native_mini_dfs test_native_mini_dfs)
42+
43+
add_executable(test_htable ../libhdfs/common/htable.c test_htable.c)
44+
target_link_libraries(test_htable ${OS_LINK_LIBRARIES})

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/native_mini_dfs.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "exception.h"
20-
#include "jclasses.h"
2120
#include "jni_helper.h"
2221
#include "native_mini_dfs.h"
2322
#include "platform.h"
@@ -37,7 +36,9 @@
3736

3837
#define MINIDFS_CLUSTER_BUILDER "org/apache/hadoop/hdfs/MiniDFSCluster$Builder"
3938
#define MINIDFS_CLUSTER "org/apache/hadoop/hdfs/MiniDFSCluster"
39+
#define HADOOP_CONF "org/apache/hadoop/conf/Configuration"
4040
#define HADOOP_NAMENODE "org/apache/hadoop/hdfs/server/namenode/NameNode"
41+
#define JAVA_INETSOCKETADDRESS "java/net/InetSocketAddress"
4142

4243
struct NativeMiniDfsCluster {
4344
/**
@@ -59,7 +60,8 @@ static int hdfsDisableDomainSocketSecurity(void)
5960
errno = EINTERNAL;
6061
return -1;
6162
}
62-
jthr = invokeMethod(env, NULL, STATIC, NULL, JC_DOMAIN_SOCKET,
63+
jthr = invokeMethod(env, NULL, STATIC, NULL,
64+
"org/apache/hadoop/net/unix/DomainSocket",
6365
"disableBindPathValidation", "()V");
6466
if (jthr) {
6567
errno = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
@@ -124,6 +126,11 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
124126
"nmdCreate: new Configuration");
125127
goto error;
126128
}
129+
if (jthr) {
130+
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
131+
"nmdCreate: Configuration::setBoolean");
132+
goto error;
133+
}
127134
// Disable 'minimum block size' -- it's annoying in tests.
128135
(*env)->DeleteLocalRef(env, jconfStr);
129136
jconfStr = NULL;
@@ -133,9 +140,8 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
133140
"nmdCreate: new String");
134141
goto error;
135142
}
136-
jthr = invokeMethod(env, NULL, INSTANCE, cobj,
137-
JC_CONFIGURATION, "setLong", "(Ljava/lang/String;J)V", jconfStr,
138-
0LL);
143+
jthr = invokeMethod(env, NULL, INSTANCE, cobj, HADOOP_CONF,
144+
"setLong", "(Ljava/lang/String;J)V", jconfStr, 0LL);
139145
if (jthr) {
140146
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
141147
"nmdCreate: Configuration::setLong");
@@ -157,7 +163,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
157163
goto error;
158164
}
159165
}
160-
jthr = findClassAndInvokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
166+
jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
161167
"format", "(Z)L" MINIDFS_CLUSTER_BUILDER ";", conf->doFormat);
162168
if (jthr) {
163169
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: "
@@ -166,7 +172,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
166172
}
167173
(*env)->DeleteLocalRef(env, val.l);
168174
if (conf->webhdfsEnabled) {
169-
jthr = findClassAndInvokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
175+
jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
170176
"nameNodeHttpPort", "(I)L" MINIDFS_CLUSTER_BUILDER ";",
171177
conf->namenodeHttpPort);
172178
if (jthr) {
@@ -177,7 +183,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
177183
(*env)->DeleteLocalRef(env, val.l);
178184
}
179185
if (conf->numDataNodes) {
180-
jthr = findClassAndInvokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
186+
jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
181187
"numDataNodes", "(I)L" MINIDFS_CLUSTER_BUILDER ";", conf->numDataNodes);
182188
if (jthr) {
183189
printExceptionAndFree(env, jthr, PRINT_EXC_ALL, "nmdCreate: "
@@ -186,7 +192,7 @@ struct NativeMiniDfsCluster* nmdCreate(struct NativeMiniDfsConf *conf)
186192
}
187193
}
188194
(*env)->DeleteLocalRef(env, val.l);
189-
jthr = findClassAndInvokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
195+
jthr = invokeMethod(env, &val, INSTANCE, bld, MINIDFS_CLUSTER_BUILDER,
190196
"build", "()L" MINIDFS_CLUSTER ";");
191197
if (jthr) {
192198
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
@@ -236,7 +242,7 @@ int nmdShutdown(struct NativeMiniDfsCluster* cl)
236242
fprintf(stderr, "nmdShutdown: getJNIEnv failed\n");
237243
return -EIO;
238244
}
239-
jthr = findClassAndInvokeMethod(env, NULL, INSTANCE, cl->obj,
245+
jthr = invokeMethod(env, NULL, INSTANCE, cl->obj,
240246
MINIDFS_CLUSTER, "shutdown", "()V");
241247
if (jthr) {
242248
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
@@ -254,7 +260,7 @@ int nmdWaitClusterUp(struct NativeMiniDfsCluster *cl)
254260
fprintf(stderr, "nmdWaitClusterUp: getJNIEnv failed\n");
255261
return -EIO;
256262
}
257-
jthr = findClassAndInvokeMethod(env, NULL, INSTANCE, cl->obj,
263+
jthr = invokeMethod(env, NULL, INSTANCE, cl->obj,
258264
MINIDFS_CLUSTER, "waitClusterUp", "()V");
259265
if (jthr) {
260266
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
@@ -276,7 +282,7 @@ int nmdGetNameNodePort(const struct NativeMiniDfsCluster *cl)
276282
}
277283
// Note: this will have to be updated when HA nativeMiniDfs clusters are
278284
// supported
279-
jthr = findClassAndInvokeMethod(env, &jVal, INSTANCE, cl->obj,
285+
jthr = invokeMethod(env, &jVal, INSTANCE, cl->obj,
280286
MINIDFS_CLUSTER, "getNameNodePort", "()I");
281287
if (jthr) {
282288
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
@@ -301,7 +307,7 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
301307
return -EIO;
302308
}
303309
// First get the (first) NameNode of the cluster
304-
jthr = findClassAndInvokeMethod(env, &jVal, INSTANCE, cl->obj, MINIDFS_CLUSTER,
310+
jthr = invokeMethod(env, &jVal, INSTANCE, cl->obj, MINIDFS_CLUSTER,
305311
"getNameNode", "()L" HADOOP_NAMENODE ";");
306312
if (jthr) {
307313
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
@@ -312,8 +318,8 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
312318
jNameNode = jVal.l;
313319

314320
// Then get the http address (InetSocketAddress) of the NameNode
315-
jthr = findClassAndInvokeMethod(env, &jVal, INSTANCE, jNameNode, HADOOP_NAMENODE,
316-
"getHttpAddress", "()L" JAVA_NET_ISA ";");
321+
jthr = invokeMethod(env, &jVal, INSTANCE, jNameNode, HADOOP_NAMENODE,
322+
"getHttpAddress", "()L" JAVA_INETSOCKETADDRESS ";");
317323
if (jthr) {
318324
ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
319325
"nmdGetNameNodeHttpAddress: "
@@ -322,8 +328,8 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
322328
}
323329
jAddress = jVal.l;
324330

325-
jthr = findClassAndInvokeMethod(env, &jVal, INSTANCE, jAddress,
326-
JAVA_NET_ISA, "getPort", "()I");
331+
jthr = invokeMethod(env, &jVal, INSTANCE, jAddress,
332+
JAVA_INETSOCKETADDRESS, "getPort", "()I");
327333
if (jthr) {
328334
ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
329335
"nmdGetNameNodeHttpAddress: "
@@ -332,7 +338,7 @@ int nmdGetNameNodeHttpAddress(const struct NativeMiniDfsCluster *cl,
332338
}
333339
*port = jVal.i;
334340

335-
jthr = findClassAndInvokeMethod(env, &jVal, INSTANCE, jAddress, JAVA_NET_ISA,
341+
jthr = invokeMethod(env, &jVal, INSTANCE, jAddress, JAVA_INETSOCKETADDRESS,
336342
"getHostName", "()Ljava/lang/String;");
337343
if (jthr) {
338344
ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "common/htable.h"
20+
#include "expect.h"
21+
#include "hdfs_test.h"
22+
23+
#include <errno.h>
24+
#include <inttypes.h>
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
#include <string.h>
28+
29+
// Disable type cast and loss of precision warnings, because the test
30+
// manipulates void* values manually on purpose.
31+
#ifdef WIN32
32+
#pragma warning(disable: 4244 4306)
33+
#endif
34+
35+
static uint32_t simple_hash(const void *key, uint32_t size)
36+
{
37+
uintptr_t k = (uintptr_t)key;
38+
return ((13 + k) * 6367) % size;
39+
}
40+
41+
static int simple_compare(const void *a, const void *b)
42+
{
43+
return a == b;
44+
}
45+
46+
static void expect_102(void *f, void *k, void *v)
47+
{
48+
int *found_102 = f;
49+
uintptr_t key = (uintptr_t)k;
50+
uintptr_t val = (uintptr_t)v;
51+
52+
if ((key == 2) && (val == 102)) {
53+
*found_102 = 1;
54+
} else {
55+
abort();
56+
}
57+
}
58+
59+
static void *htable_pop_val(struct htable *ht, void *key)
60+
{
61+
void *old_key, *old_val;
62+
63+
htable_pop(ht, key, &old_key, &old_val);
64+
return old_val;
65+
}
66+
67+
int main(void)
68+
{
69+
struct htable *ht;
70+
int found_102 = 0;
71+
72+
ht = htable_alloc(4, simple_hash, simple_compare);
73+
EXPECT_INT_EQ(0, htable_used(ht));
74+
EXPECT_INT_EQ(4, htable_capacity(ht));
75+
EXPECT_NULL(htable_get(ht, (void*)123));
76+
EXPECT_NULL(htable_pop_val(ht, (void*)123));
77+
EXPECT_ZERO(htable_put(ht, (void*)123, (void*)456));
78+
EXPECT_INT_EQ(456, (uintptr_t)htable_get(ht, (void*)123));
79+
EXPECT_INT_EQ(456, (uintptr_t)htable_pop_val(ht, (void*)123));
80+
EXPECT_NULL(htable_pop_val(ht, (void*)123));
81+
82+
// Enlarge the hash table
83+
EXPECT_ZERO(htable_put(ht, (void*)1, (void*)101));
84+
EXPECT_ZERO(htable_put(ht, (void*)2, (void*)102));
85+
EXPECT_ZERO(htable_put(ht, (void*)3, (void*)103));
86+
EXPECT_INT_EQ(3, htable_used(ht));
87+
EXPECT_INT_EQ(8, htable_capacity(ht));
88+
EXPECT_INT_EQ(102, (uintptr_t)htable_get(ht, (void*)2));
89+
EXPECT_INT_EQ(101, (uintptr_t)htable_pop_val(ht, (void*)1));
90+
EXPECT_INT_EQ(103, (uintptr_t)htable_pop_val(ht, (void*)3));
91+
EXPECT_INT_EQ(1, htable_used(ht));
92+
htable_visit(ht, expect_102, &found_102);
93+
EXPECT_INT_EQ(1, found_102);
94+
htable_free(ht);
95+
96+
fprintf(stderr, "SUCCESS.\n");
97+
return EXIT_SUCCESS;
98+
}
99+
100+
// vim: ts=4:sw=4:tw=79:et

hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ hadoop_add_dual_library(hdfs
3535
exception.c
3636
jni_helper.c
3737
hdfs.c
38-
jclasses.c
38+
common/htable.c
3939
${OS_DIR}/mutexes.c
4040
${OS_DIR}/thread_local_storage.c
4141
)

0 commit comments

Comments
 (0)