SAMZA-2804: Concurrency issues identified in run-class.sh on samza-yarn (#1716)

* Add annotations for each line identified as having a potential issue.

* Resolve multiple concurrency issues

## Race condition in pathing jar manifest creation

A race condition exists when setting up the classpath during container launch.

During container launch using samza-yarn, run-class.sh creates a pathing jar file (which holds the classpath for the container launch). However, during the creation of this pathing jar, temporary files, as well as the pathing jar itself is not placed in a location unique to the container. This results in multiple containers writing to the same pathing jar location and temporary file location, which results in a race condition.

This race condition may show up in several ways, such as when Yarn removes jars from a finished container (other containers will point to a classpath which no longer exists) or when multiple run-class.sh scripts attempt to write the manifest.txt or pathing jar at the same time.

Note that host affinity being enabled will make this problem worse. The pathing.jar is written to the usercache, so when the container which created the pathing.jar is finished and removed, any new container which launches on that host will point to jar files which do not exist anymore. When host affinity is enabled, it will not move to a new host and just keep failing.

## Container logging directory fallback is not unique for each container

The fallback log directory is the same among all containers running on the same host. It should be unique per-container.

## Container tmp dir is not unique per-container

The JAVA_TMP_DIR directory is the same for all containers. We should make sure that it's safe to use the same directory for all containers.

* Simplify comments and print manifest file locations
2 files changed
tree: 03e2edd996562c3279c7d2ecbd47ca3755163cb9
  1. .github/
  2. bin/
  3. checkstyle/
  4. docs/
  5. gradle/
  6. samza-api/
  7. samza-aws/
  8. samza-azure/
  9. samza-core/
  10. samza-elasticsearch/
  11. samza-hdfs/
  12. samza-kafka/
  13. samza-kv/
  14. samza-kv-couchbase/
  15. samza-kv-inmemory/
  16. samza-kv-rocksdb/
  17. samza-log4j/
  18. samza-log4j2/
  19. samza-rest/
  20. samza-shell/
  21. samza-sql/
  22. samza-sql-shell/
  23. samza-test/
  24. samza-tools/
  25. samza-yarn/
  26. samza-yarn3/
  27. .gitignore
  28. .reviewboardrc
  29. bootstrap.gradle
  30. build.gradle
  31. doap_Samza.rdf
  32. gradle.properties
  33. gradlew
  34. gradlew.bat
  35. HEADER
  36. KEYS
  37. LICENSE
  38. NOTICE
  39. README.md
  40. RELEASE.md
  41. settings.gradle
  42. sonar-project.properties
README.md

What is Samza? Build Status

Apache Samza is a distributed stream processing framework. It uses Apache Kafka for messaging, and Apache Hadoop YARN to provide fault tolerance, processor isolation, security, and resource management.

Samza's key features include:

  • Simple API: Unlike most low-level messaging system APIs, Samza provides a very simple callback-based “process message” API comparable to MapReduce.
  • Managed state: Samza manages snapshotting and restoration of a stream processor's state. When the processor is restarted, Samza restores its state to a consistent snapshot. Samza is built to handle large amounts of state (many gigabytes per partition).
  • Fault tolerance: Whenever a machine in the cluster fails, Samza works with YARN to transparently migrate your tasks to another machine.
  • Durability: Samza uses Kafka to guarantee that messages are processed in the order they were written to a partition, and that no messages are ever lost.
  • Scalability: Samza is partitioned and distributed at every level. Kafka provides ordered, partitioned, replayable, fault-tolerant streams. YARN provides a distributed environment for Samza containers to run in.
  • Pluggable: Though Samza works out of the box with Kafka and YARN, Samza provides a pluggable API that lets you run Samza with other messaging systems and execution environments.
  • Processor isolation: Samza works with Apache YARN, which supports Hadoop's security model, and resource isolation through Linux CGroups.

Check out Hello Samza to try Samza. Read the Background page to learn more about Samza.

Building Samza

To build Samza from a git checkout, run:

./gradlew clean build

To build Samza from a source release, it is first necessary to download the gradle wrapper script above. This bootstrapping process requires Gradle to be installed on the source machine. Gradle is available through most package managers or directly from its website. To bootstrap the wrapper, run:

gradle -b bootstrap.gradle

After the bootstrap script has completed, the regular gradlew instructions below are available.

Java Version Support

This project is built with Java 8 and can run in a Java 8 runtime enviornment. Additionally, it also supports running in a Java 11 runtime environment. If you intend to use Samza in a Java 11 runtime environment, it means you will also need to use YARN 3.3.4+ and in which case, you should also use the samza-yarn3 module (built with YARN 3.3.4) instead of the samza-yarn (built with YARN 2.10.1). There is also a samza-shell-yarn3 that depends on the samza-yarn3 module, so use that shell module if you intend on using Yarn 3.

Scala and YARN

Samza builds with Scala 2.11 or 2.12 and YARN 2.10.1, by default. Use the -PscalaSuffix switches to change Scala versions. Samza supports building Scala with 2.11 and 2.12 and provides a YARN 2 module (samze-yarn) and a YARN 3 module (samza-yarn3).

NOTE: Some modules currently do not officially support Java 11 Runtime and are still using the YARN 2.10.1 dependency:

  • samza-yarn

  • samza-shell

  • samza-test

  • samza-hdfs

    ./gradlew -PscalaSuffix=2.12 clean build

Also, you can make use of bin/check-all.sh in order to test multiple variants of Java JDKs, Scala, and Yarn.

Testing Samza

To run all tests:

./gradlew clean test

To run a single test:

./gradlew clean :samza-test:test -Dtest.single=TestStatefulTask

To run key-value performance tests:

./gradlew samza-shell:kvPerformanceTest -PconfigPath=file://$PWD/samza-test/src/main/config/perf/kv-perf.properties

To run yarn integration tests:

./bin/integration-tests.sh <dir> yarn-integration-tests

To run standalone integration tests:

./bin/integration-tests.sh <dir> standalone-integration-tests

Running checkstyle on the java code

./gradlew checkstyleMain checkstyleTest

Job Management

To run a job (defined in a properties file):

./gradlew samza-shell:runJob -PconfigPath=/path/to/job/config.properties

To inspect a job's latest checkpoint:

./gradlew samza-shell:checkpointTool -PconfigPath=/path/to/job/config.properties

To modify a job's checkpoint (assumes that the job is not currently running), give it a file with the new offset for each partition, in the format systems.<system>.streams.<topic>.partitions.<partition>=<offset>:

./gradlew samza-shell:checkpointTool -PconfigPath=/path/to/job/config.properties \
    -PnewOffsets=file:///path/to/new/offsets.properties

Developers

To get Eclipse projects, run:

./gradlew eclipse

For IntelliJ, run:

./gradlew idea

Contribution

To start contributing on Samza please read Rules and Contributor Corner. Notice that Samza git repository does not support git pull request.

Apache Software Foundation

Apache Samza is a top level project of the Apache Software Foundation.

Apache Software Foundation Logo