Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#150][#178] feat(all): Add launching process and scripts #191

Merged
merged 27 commits into from
Aug 11, 2023
Merged

[#150][#178] feat(all): Add launching process and scripts #191

merged 27 commits into from
Aug 11, 2023

Conversation

xunliu
Copy link
Member

@xunliu xunliu commented Aug 8, 2023

What changes were proposed in this pull request?

Through graviton.sh script launching GravtionServer.

Command

./bin/graviton.sh [--config <conf-dir>] {start|stop|restart|status}

Directory struct

├── bin
│   ├── command.sh
│   └── graviton.sh
├── conf
│   ├── graviton.conf.template
│   ├── graviton-env.sh.template
│   └── log4j.properties.template
└── distribution/package
    ├── bin/
    ├── catalogs/catalog-hive
    ├── conf/
    ├── lib/
    ├── graviton-${version}-bin.tar
    └── graviton-${version}-bin.tar.sha256

Scripts context

  • bin/command.sh: Command functions
  • bin/graviton.sh: Launching scripts
  • conf/graviton.conf.template: All configuration templates for Gravtion
  • conf/gravtion-env.sh.template: Environment variables, etc., JAVA_HOME, GRAVITON_HOME etc.,
  • conf/log4j.properties.template: log4j configuration for Gravtion Server.

Assemble Distribution

  1. ./gradlew clean build

  2. ./gradlew compileDistribution

    • Copy ${project_root_dir}/bin/ directory to ${project_root_dir}/distribution/package/bin/.
    • Copy ${project_root_dir}/conf/ directory to ${project_root_dir}/distribution/package/conf/ and remove .template file name suffix.
    • Copy ${project_root_dir}/${sub_module}/lib to ${project_root_dir}/distribution/package/lib/
    • Copy ${project_root_dir}/catalog-hive}/lib to ${project_root_dir}/distribution/package/catalogs/catalog-hive/lib
  3. ./gradlew assembleDistribution

    • Compress ${project_root_dir}/distribution/package generate graviton-${version}-bin.tar and graviton-${version}-bin.tar.sha256
  4. ./distribution/package/bin/graviton.sh start|stop|status

Why are the changes needed?

Through script launching Graviton Server.

Fix: #178

Does this PR introduce any user-facing change?

N/A

How was this patch tested?

Test on PullRequst submission

@github-actions
Copy link

github-actions bot commented Aug 8, 2023

Code Coverage Report

Overall Project 59.9% -0.26% 🟢
Files changed 43.31% 🔴

Module Coverage
server 81.56% -2.27% 🔴
Files
Module File Coverage
server ServerConfig.java 100% 🟢
JettyServer.java 86.96% 🟢
GravitonServer.java 64.14% -24.24% 🔴
ProjectVersion.java 0% 🔴

run: |
gradle assembleDistribution
ls -l distribution/package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the usage of the ls command?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print package directory to help check.


// Create and config Jetty Server
server = new Server(threadPool);
server = new Server(threadPool2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may not get the context, Why we need to use a new thread pool?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

} catch (Exception e) {
LOG.error("Error while stopping servlet container", e);
}
LOG.info("Done, Shutting down Graviton Server.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shutting down Graviton Server.

Better: Graviton Server has shut down

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
String[] splits = value.split("# ");
if (splits.length == 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid the condition that length of array is 2 is not enough, see:

configkey configvalue  # # this is comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code section has been removed.

@apache apache deleted a comment from yuqi1129 Aug 8, 2023
@xunliu xunliu requested a review from jerryshao August 8, 2023 14:02
@xunliu
Copy link
Member Author

xunliu commented Aug 8, 2023

@jerryshao Please help me to review this PR. thanks.

echo "Failed to start graviton"
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is super necessary to start and test a server here, this will prolong the CI time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed bin/graviont.sh start test. And split Integration Test into a single workflow.

- name: Package with Gradle
run: |
gradle assembleDistribution
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is necessary to add package process here in build.yml, this script is mainly for UT. Is it better to use another workflow for package things?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Remove the compress tar.gz process, only retain only create distribution/package directory.
  2. Split Integration Test into a single workflow.

bin/common.sh Outdated
fi

if [ "$JVM_VERSION" -lt 8 ] || { [ "$JVM_VERSION" -eq 8 ] && [ "${jvmver#*_}" -lt 151 ]; } ; then
echo "Graviton requires either Java 8 update 151 or newer"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Java 8 enough, do we require a Java version larger than 151? Also, I was worrying about the way you get Java version using regex, you may not get the version number from some customized java release like zuul, kona jdk?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Because after JDK 8u151, Oracle fixed a number of security vulnerabilities and issues to improve system stability and security. We suggest using after JDK 8u151.
    https://www.oracle.com/java/technologies/javase/8u151-relnotes.html

  2. Because we only test passed in Oracle JDK, Other JDK versions not tested, better limit JDK type & version.

Copy link
Member

@justinmclean justinmclean Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest not using Oracle JDK 8 as it has a restrictive license. Oracle JDK Java 8 is under the OTN License Agreement for Java (https://www.oracle.com/cis/downloads/licenses/oracle-javase-license.html). This requires a fee / license for commercial use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using OpenJDK / Corretto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, @justinmclean thank you for your suggestion.
I create issue #215 to track this problem.

if [[ "$1" == "--config" ]]; then
shift
conf_dir="$1"
if [[ ! -d "${conf_dir}" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be it is not necessary to add --config <conf-dir>? I think we can use GRAVITON_CONF_DIR or GRAVITON_HOME to infer the conf dir programatically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --config parameter is an option that allows us to easily change the configuration directory in the start scripts.

  • When the --config parameter is not specified, GRAVITON_CONF_DIR is the default environment in the graviton-env.sh
  • When the --config parameter is specified, the GRAVITON_CONF_DIR environment is overwritten.


function found_graviton_server_pid() {
process_name='GravitonServer';
RUNNING_PIDS=$(ps x | grep ${process_name} | grep -v grep | awk '{print $1}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to write pid to a file to avoid same name process?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PID file is a traditional operation, and I have implemented this function in another version.

  • Generation the PID file in the graviton.sh start command.
  • Deleted the PID file in the graviton.sh stop command.

However, when the Graviton Server itself exits abnormally, the PID file is not deleted properly.
You will not be able to restart Gravtion Server the next time because there is already an old PID file.
So I think might be better to get the directory PID in the operation system.

I suggest that we can keep this implementation, and consider modifying it later when we have a specific problem.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure.

build.gradle.kts Outdated
if (it.name == "catalog-hive") {
// println("copyCatalogRuntimeClass: ${it.name}")
from(it.configurations.runtimeClasspath)
into("distribution/package/catalog/catalog-hive/lib")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catalogs/catalog-hive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (it.name != "catalog-hive") {
// println("copyRuntimeClass: ${it.name}")
from(it.configurations.runtimeClasspath)
into("distribution/package/lib")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to copy client jar into lib?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catalog-hive JAR need copy to another directory(distribution/package/catalog/catalog-hive/lib), So I split two different Tasks, copyCatalogRuntimeClass() and copySubmoduleClass().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is client-jar lib, I think we don't need to include this module's jar files into server's lib.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -133,7 +133,6 @@ Properties loadPropertiesFromFile(File file) throws IOException {
try (InputStream in = Files.newInputStream(file.toPath())) {
properties.load(in);
return properties;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a unnecessary change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has been rollback.

LOG.info("Shutting down Graviton Server ... ");
try {
server.stop();
Thread.sleep(3000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd better not make this hardcoded.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, added SERVER_SHUTDOWN_TIMEOUT into Configure.

rootLogger.level = debug

# Root logger referring to console appender
rootLogger.appenderRef.stdout.ref = consoleLogger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file seems not necessary, as we already removed this in the previous pr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this log4j2.properties file.

@xunliu xunliu closed this Aug 10, 2023
@xunliu xunliu reopened this Aug 10, 2023
bin/common.sh Outdated
function addEachJarInDirRecursive(){
if [[ -d "${1}" ]]; then
for jar in "${1}"/**/*.jar ; do
GRAVITON_CLASSPATH="$jar:$GRAVITON_CLASSPATH"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add "{}" to variables to avoid potentially issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

println()
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we only print some dependency information here for this allDeps task, is this necessary? Also gradle has a similar functionality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I using a new function to replace it.

val allDeps by tasks.registering(DependencyReportTask::class)

Now if you execute ./gradlew allDeps command, will print all subproject dependency

LOG.info("Shutting down Graviton Server ... ");
try {
server.stop();
Thread.sleep(server.serverConfig.get(ServerConfig.SERVER_SHUTDOWN_TIMEOUT));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to put this configuration into graviton.conf.template?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it into graviton.conf.template.

@@ -185,7 +188,7 @@ private ExecutorThreadPool createThreadPool(int coreThreads, int maxThreads) {
maxThreads,
60,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(),
new LinkedBlockingQueue<>(100),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to make this configurable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerryshao I think so.
An unbounded queue is dangerous and not recommended in Java when using thread pool. here I notice this problem and advice @xunliu to change here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added graviton.server.webserver.executorThreadPoolSize configuration parameter to graviton.conf.

echo "Graviton requires either Java 8 update 151 or newer"
exit 1;
fi
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indention of this method is 4 spaces.

Copy link
Member Author

@xunliu xunliu Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indention of this method is 4 spaces.

This is not fixed.

@xunliu xunliu changed the title [#178] feat(all): Add launching process and scripts [#150][#178] feat(all): Add launching process and scripts Aug 10, 2023
@@ -59,6 +59,13 @@ public class ServerConfig extends Config {
.intConf()
.createWithDefault(128 * 1024);

public static final ConfigEntry<Integer> WEBSERVER_EXECUTOR_THREAD_POOL_SIZE =
new ConfigBuilder("graviton.server.webserver.executorThreadPoolSize")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration may not be the thread pool size? I think it should be queue size?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, modify to WEBSERVER_THREAD_POOL_WORK_QUEUE_SIZE.

Copy link
Contributor

@jerryshao jerryshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm going to merge this PR. We don't restrict the JDK vendor version, I think there's no issue here, and can be addressed later if necessary.

@jerryshao jerryshao merged commit b97e382 into apache:main Aug 11, 2023
2 checks passed
@xunliu xunliu deleted the issue-178 branch August 28, 2023 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Subtask] Add launching process and scripts
4 participants