Skip to content

Commit 7c4a812

Browse files
smkniaziGautier Berthou
authored and
Gautier Berthou
committed
[HOPS-1553] Fixed ClusterJ logging
1 parent f373a7d commit 7c4a812

File tree

6 files changed

+152
-6
lines changed

6 files changed

+152
-6
lines changed

NDB/clusterj-fixes/clusterj-fix.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ index ac4fcf73..13cb3e1a 100644
3333
// if not using connection pooling, create a new session factory
3434
result = new SessionFactoryImpl(props);
3535
}
36-
+ System.out.println("HopsFS created a ClusterJ VERSION sesseion factory.");
36+
+ logger.info("HopsFS created a ClusterJ VERSION sesseion factory.");
3737
return result;
3838
}
3939

src/main/java/io/hops/metadata/ndb/DBSessionProvider.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.mysql.clusterj.ClusterJHelper;
2323
import com.mysql.clusterj.Constants;
2424
import com.mysql.clusterj.LockMode;
25+
import com.mysql.clusterj.core.util.LoggerFactory;
2526
import io.hops.exception.StorageException;
2627
import io.hops.metadata.ndb.wrapper.HopsExceptionHelper;
2728
import io.hops.metadata.ndb.wrapper.HopsSession;
@@ -66,11 +67,11 @@ public DBSessionProvider(Properties conf, int reuseCount, int initialPoolSize)
6667
}
6768

6869
private void start(int initialPoolSize) throws StorageException {
69-
System.out.println("Database connect string: " +
70+
LOG.info("Database connect string: " +
7071
conf.get(Constants.PROPERTY_CLUSTER_CONNECTSTRING));
71-
System.out.println(
72+
LOG.info(
7273
"Database name: " + conf.get(Constants.PROPERTY_CLUSTER_DATABASE));
73-
System.out.println("Max Transactions: " +
74+
LOG.info("Max Transactions: " +
7475
conf.get(Constants.PROPERTY_CLUSTER_MAX_TRANSACTIONS));
7576
try {
7677
sessionFactory =

src/main/java/io/hops/metadata/ndb/dalimpl/hdfs/INodeClusterj.java

-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ public List<INodeIdentifier> getAllINodeFiles(long startId, long endId)
592592
dobj.where(pred.not().and(pred2));
593593
HopsQuery<InodeDTO> query = session.createQuery(dobj);
594594
query.setParameter("isDirParam", NdbBoolean.convert(true));
595-
//FIXME: InodeId is integer
596595
//startId is inclusive and endId exclusive
597596
query.setParameter("startId", startId);
598597
query.setParameter("endId", endId - 1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package io.hops.metadata.ndb.wrapper;
2+
3+
import com.mysql.clusterj.core.util.Logger;
4+
import org.apache.commons.logging.Log;
5+
6+
public class HopsClusterJLogger implements Logger {
7+
8+
private static final String ENABLE_CLUSTERJ_LOGS_ENV = "ENABLE_CLUSTERJ_LOGS";
9+
private static boolean ENABLE_CLUSTERJ_LOGS = false;
10+
11+
static {
12+
String isLogStr = System.getenv(ENABLE_CLUSTERJ_LOGS_ENV);
13+
try {
14+
if(isLogStr != null) {
15+
ENABLE_CLUSTERJ_LOGS = Boolean.parseBoolean(isLogStr);
16+
}
17+
} catch (Throwable t) {
18+
System.err.println("Unable to parse "+ENABLE_CLUSTERJ_LOGS_ENV+" env variable");
19+
}
20+
}
21+
22+
private final Log LOG;
23+
24+
HopsClusterJLogger(Log delegate) {
25+
LOG = delegate;
26+
}
27+
28+
@Override
29+
public void detail(String s) {
30+
if (ENABLE_CLUSTERJ_LOGS)
31+
LOG.trace(s);
32+
}
33+
34+
@Override
35+
public void debug(String s) {
36+
if (ENABLE_CLUSTERJ_LOGS)
37+
LOG.debug(s);
38+
}
39+
40+
@Override
41+
public void trace(String s) {
42+
if (ENABLE_CLUSTERJ_LOGS)
43+
LOG.trace(s);
44+
}
45+
46+
@Override
47+
public void info(String s) {
48+
if (ENABLE_CLUSTERJ_LOGS)
49+
LOG.info(s);
50+
}
51+
52+
@Override
53+
public void warn(String s) {
54+
if (ENABLE_CLUSTERJ_LOGS)
55+
LOG.warn(s);
56+
}
57+
58+
@Override
59+
public void error(String s) {
60+
if (ENABLE_CLUSTERJ_LOGS)
61+
LOG.error(s);
62+
}
63+
64+
@Override
65+
public void fatal(String s) {
66+
if (ENABLE_CLUSTERJ_LOGS)
67+
LOG.fatal(s);
68+
}
69+
70+
@Override
71+
public boolean isDetailEnabled() {
72+
return ENABLE_CLUSTERJ_LOGS && LOG.isTraceEnabled();
73+
}
74+
75+
@Override
76+
public boolean isDebugEnabled() {
77+
return ENABLE_CLUSTERJ_LOGS && LOG.isDebugEnabled();
78+
}
79+
80+
@Override
81+
public boolean isTraceEnabled() {
82+
return ENABLE_CLUSTERJ_LOGS && LOG.isTraceEnabled();
83+
}
84+
85+
@Override
86+
public boolean isInfoEnabled() {
87+
return ENABLE_CLUSTERJ_LOGS && LOG.isInfoEnabled();
88+
}
89+
}

src/main/java/io/hops/metadata/ndb/wrapper/HopsExceptionHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static boolean isOutOfDBExtents(ClusterJException e){
7777
}
7878

7979
private static boolean isDeadLockException(ClusterJException e){
80-
return isExceptionContains(e, 266);
80+
return isExceptionContains(e, 266) || isExceptionContains(e, 274);
8181
}
8282

8383
private static boolean isExceptionContains(ClusterJException e, int code){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.hops.metadata.ndb.wrapper;
2+
import com.mysql.clusterj.core.util.JDK14LoggerFactoryImpl;
3+
import com.mysql.clusterj.core.util.Logger;
4+
import com.mysql.clusterj.core.util.LoggerFactory;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
import org.apache.commons.logging.Log;
10+
import org.apache.commons.logging.LogFactory;
11+
12+
public class HopsLoggerFactory implements LoggerFactory{
13+
14+
static final Map<String, Logger> loggerMap = new HashMap<String, Logger>();
15+
16+
public HopsLoggerFactory() {
17+
// create all the known loggers for the core project
18+
registerLogger(JDK14LoggerFactoryImpl.CLUSTERJ_LOGGER);
19+
registerLogger(JDK14LoggerFactoryImpl.CLUSTERJ_METADATA_LOGGER);
20+
registerLogger(JDK14LoggerFactoryImpl.CLUSTERJ_QUERY_LOGGER);
21+
registerLogger(JDK14LoggerFactoryImpl.CLUSTERJ_UTIL_LOGGER);
22+
}
23+
24+
public Logger registerLogger(String loggerName) {
25+
final Log log = LogFactory.getLog(loggerName);
26+
Logger result = new HopsClusterJLogger(log);
27+
loggerMap.put(loggerName, result);
28+
return result;
29+
}
30+
31+
@SuppressWarnings("unchecked")
32+
public Logger getInstance(Class cls) {
33+
String loggerName = getPackageName(cls);
34+
return getInstance(loggerName);
35+
}
36+
37+
public synchronized Logger getInstance(String loggerName) {
38+
Logger result = loggerMap.get(loggerName);
39+
if (result == null) {
40+
result = registerLogger(loggerName);
41+
}
42+
return result;
43+
}
44+
45+
/**
46+
* Returns the package portion of the specified class.
47+
* @param cls the class from which to extract the
48+
* package
49+
* @return package portion of the specified class
50+
*/
51+
final private static String getPackageName(Class<?> cls)
52+
{
53+
String className = cls.getName();
54+
int index = className.lastIndexOf('.');
55+
return ((index != -1) ? className.substring(0, index) : ""); // NOI18N
56+
}
57+
}

0 commit comments

Comments
 (0)