Skip to content
Open
Show file tree
Hide file tree
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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
<jettison.version>1.5.4</jettison.version>
<jsr305.version>3.0.0</jsr305.version>
<junit.version>4.13.2</junit.version>
<leveldbjni.group>org.fusesource.leveldbjni</leveldbjni.group>
<leveldb.version>0.12</leveldb.version>
<leveldbjni-all.version>1.8</leveldbjni-all.version>
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
<metrics-core.version>3.1.0</metrics-core.version>
Expand Down Expand Up @@ -810,10 +812,15 @@
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.fusesource.leveldbjni</groupId>
<groupId>${leveldbjni.group}</groupId>
<artifactId>leveldbjni-all</artifactId>
<version>${leveldbjni-all.version}</version>
</dependency>
<dependency>
<groupId>org.iq80.leveldb</groupId>
<artifactId>leveldb</artifactId>
<version>${leveldb.version}</version>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
Expand Down Expand Up @@ -1358,6 +1365,18 @@
</plugins>
</reporting>
</profile>
<profile>
<id>aarch64</id>
<properties>
<leveldbjni.group>org.openlabtesting.leveldbjni</leveldbjni.group>
</properties>
<activation>
<os>
<family>linux</family>
<arch>aarch64</arch>
</os>
</activation>
</profile>
</profiles>

<!-- TODO: TEZ-4597: IncludePublicAnnotationsStandardDoclet is not JDK9+ compatible -->
Expand Down
32 changes: 31 additions & 1 deletion tez-plugins/tez-aux-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-server-common</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand All @@ -64,6 +70,10 @@
<groupId>io.netty</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -90,6 +100,12 @@
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-shuffle</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tez</groupId>
Expand All @@ -110,10 +126,14 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.fusesource.leveldbjni</groupId>
<groupId>${leveldbjni.group}</groupId>
<artifactId>leveldbjni-all</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.iq80.leveldb</groupId>
<artifactId>leveldb</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
Expand Down Expand Up @@ -141,6 +161,10 @@
<groupId>io.netty</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -154,6 +178,12 @@
<artifactId>hadoop-yarn-server-tests</artifactId>
<scope>test</scope>
<type>test-jar</type>
<exclusions>
<exclusion>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import static org.fusesource.leveldbjni.JniDBFactory.asString;
import static org.fusesource.leveldbjni.JniDBFactory.bytes;
import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -89,7 +88,6 @@
import org.apache.hadoop.yarn.server.api.AuxiliaryService;
import org.apache.hadoop.yarn.server.records.Version;
import org.apache.hadoop.yarn.server.records.impl.pb.VersionPBImpl;
import org.apache.hadoop.yarn.server.utils.LeveldbIterator;
import org.apache.tez.common.security.JobTokenIdentifier;
import org.apache.tez.common.security.JobTokenSecretManager;
import org.apache.tez.runtime.library.common.Constants;
Expand Down Expand Up @@ -149,10 +147,10 @@
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.GlobalEventExecutor;

import org.fusesource.leveldbjni.JniDBFactory;
import org.fusesource.leveldbjni.internal.NativeDB;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBException;
import org.iq80.leveldb.DBFactory;
import org.iq80.leveldb.DBIterator;
import org.iq80.leveldb.Logger;
import org.iq80.leveldb.Options;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -210,6 +208,7 @@ public class ShuffleHandler extends AuxiliaryService {
private JobTokenSecretManager secretManager;

private DB stateDb = null;
private static final DBFactory DB_FACTORY = createDBFactory();

public static final String TEZ_SHUFFLE_SERVICEID =
"tez_shuffle";
Expand Down Expand Up @@ -643,6 +642,7 @@ protected void serviceStop() throws Exception {
destroyPipeline();
if (stateDb != null) {
stateDb.close();
stateDb = null;
}
super.serviceStop();
}
Expand Down Expand Up @@ -671,9 +671,9 @@ private void recoverState(Configuration conf) throws IOException {
if (recoveryRoot != null) {
startStore(recoveryRoot);
Pattern jobPattern = Pattern.compile(JobID.JOBID_REGEX);
LeveldbIterator iter = null;
DBIterator iter = null;
try {
iter = new LeveldbIterator(stateDb);
iter = stateDb.iterator();
iter.seek(bytes(JobID.JOB));
while (iter.hasNext()) {
Map.Entry<byte[],byte[]> entry = iter.next();
Expand All @@ -695,26 +695,23 @@ private void recoverState(Configuration conf) throws IOException {

private void startStore(Path recoveryRoot) throws IOException {
Options options = new Options();
options.createIfMissing(false);
options.logger(new LevelDBLogger());
Path dbPath = new Path(recoveryRoot, STATE_DB_NAME);
LOG.info("Using state database at " + dbPath + " for recovery");
File dbfile = new File(dbPath.toString());
boolean dbExists = dbfile.exists();
options.createIfMissing(!dbExists);
try {
stateDb = JniDBFactory.factory.open(dbfile, options);
} catch (NativeDB.DBException e) {
if (e.isNotFound() || e.getMessage().contains(" does not exist ")) {
LOG.info("Creating state database at " + dbfile);
options.createIfMissing(true);
try {
stateDb = JniDBFactory.factory.open(dbfile, options);
storeVersion();
} catch (DBException dbExc) {
throw new IOException("Unable to create state store", dbExc);
}
} else {
throw e;
stateDb = DB_FACTORY.open(dbfile, options);
} catch (Exception e) {
if (e instanceof IOException) {
throw (IOException) e;
}
throw new IOException("Unable to open state store", e);
}
if (!dbExists) {
LOG.info("Created state database at " + dbfile);
storeVersion();
}
checkVersion();
}
Expand Down Expand Up @@ -843,6 +840,27 @@ private void removeJobShuffleInfo(JobID jobId) throws IOException {
}
}

private static DBFactory createDBFactory() {
// Try native JNI LevelDB first (fastest), fall back to pure-Java iq80
try {
DBFactory jniFactory = org.fusesource.leveldbjni.JniDBFactory.factory;
LOG.info("Using JNI LevelDB factory");
return jniFactory;
} catch (Throwable t) {
LOG.info("Native LevelDB JNI library not available ({}), "
+ "falling back to pure-Java implementation", t.getMessage());
return new org.iq80.leveldb.impl.Iq80DBFactory();
}
}

private static byte[] bytes(String value) {
return value.getBytes(UTF_8);
}

private static String asString(byte[] value) {
return new String(value, UTF_8);
}

private static class LevelDBLogger implements Logger {
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(LevelDBLogger.class);

Expand Down