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

Enforce and apply Google Java Style formatting #416

Merged
merged 51 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
15e39ec
enable compiler warnings and linting
bpkroth Dec 7, 2023
d66eaba
address some trailing whitespace warnings
bpkroth Dec 7, 2023
9fde340
Merge branch 'main' into strict-compiler
bpkroth Dec 8, 2023
3b3906c
compiler fixups
bpkroth Dec 8, 2023
092e06d
compiler fixups
bpkroth Dec 8, 2023
8038636
add some warning suppressions for unused variables
bpkroth Dec 8, 2023
139c953
omit those entirely
bpkroth Dec 8, 2023
259cca6
fixups
bpkroth Dec 8, 2023
77c74ae
whitespace
bpkroth Dec 8, 2023
7abe2e8
use autoclose
bpkroth Dec 8, 2023
a3f7fec
remove more suppressed cast issues
bpkroth Dec 8, 2023
554406d
unnecessary cast
bpkroth Dec 8, 2023
79e7187
avoid unused errors
bpkroth Dec 8, 2023
d93caf7
add serialization requirements
bpkroth Dec 8, 2023
7f89237
whitespace
bpkroth Dec 8, 2023
ff5507d
more minor avoid raw type issues
bpkroth Dec 8, 2023
fc97c1e
in the couple of utility classes, just suppress more warnings
bpkroth Dec 8, 2023
5220c3f
convert throw type to avoid InterruptedException handling warnings
bpkroth Dec 8, 2023
df432f3
docs
bpkroth Dec 8, 2023
d93c61d
enable deprecations
bpkroth Dec 8, 2023
9b95f48
enable auto formatting on compile
bpkroth Dec 8, 2023
e894950
check formatting at ci time
bpkroth Dec 8, 2023
062f7a1
enable vscode configs for formatting
bpkroth Dec 8, 2023
500240d
do format checks in docker build step too
bpkroth Dec 8, 2023
b0398b1
more compiler warning fixups
bpkroth Dec 8, 2023
96ad74b
Merge branch 'strict-compiler' into java-formatting
bpkroth Dec 8, 2023
db891e9
Merge branch 'main' into strict-compiler
bpkroth Dec 8, 2023
9fed075
fixup
bpkroth Dec 8, 2023
c53ea80
revert order
bpkroth Dec 8, 2023
e5e9c00
need the col++
bpkroth Dec 8, 2023
94385e7
address some unused and other lint issues
bpkroth Dec 8, 2023
2a2006d
Merge branch 'strict-compiler' into java-formatting
bpkroth Dec 8, 2023
448ca24
fixup
bpkroth Dec 8, 2023
0e9174a
Merge branch 'strict-compiler' into java-formatting
bpkroth Dec 8, 2023
1e411d4
fixup
bpkroth Dec 8, 2023
121f547
Merge branch 'strict-compiler' into java-formatting
bpkroth Dec 8, 2023
2937b46
add a readme with additional developer notes per PR suggestion
bpkroth Dec 11, 2023
4b22f8d
tweak comment
bpkroth Dec 11, 2023
fa34754
add more developer notes
bpkroth Dec 11, 2023
be0f414
include some extension recommendations
bpkroth Dec 11, 2023
43b5cee
update extensions
bpkroth Dec 11, 2023
a5b755c
Merge branch 'strict-compiler' into java-formatting
bpkroth Dec 11, 2023
986c0fb
include style notes in the contributor file
bpkroth Dec 11, 2023
4556f10
address more unused warnings
bpkroth Dec 11, 2023
f5bcb19
Merge branch 'strict-compiler' into java-formatting
bpkroth Dec 11, 2023
5939e2d
ignore another error
bpkroth Dec 11, 2023
e277f99
Merge branch 'strict-compiler' into java-formatting
bpkroth Dec 11, 2023
cbbe401
Merge branch 'main' into java-formatting
bpkroth Dec 13, 2023
690b024
fixup toc
bpkroth Dec 13, 2023
b845c6d
also compile test sources
bpkroth Dec 13, 2023
a51a1ea
reformat java files
bpkroth Dec 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ jobs:
cache: 'maven'
distribution: 'temurin'

- name: Check formatting
run: mvn -B fmt:check --file pom.xml

- name: Compile with Maven
run: mvn -B compile test-compile --file pom.xml

- name: Test with Maven
run: mvn -B test --file pom.xml

Expand Down Expand Up @@ -605,6 +611,7 @@ jobs:
- name: Build the benchbase docker image with all profiles using the dev image
env:
SKIP_TESTS: 'false'
DO_FORMAT_CHECKS: 'true'
run: |
./docker/benchbase/build-full-image.sh
- name: Run a basic test from the docker image against postgres test DB
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"huntertran.auto-markdown-toc",
"vscjava.vscode-java-pack"
]
}
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.watcherExclude": {
"**/target": true
},
"java.format.settings.profile": "GoogleStyle",
"java.format.enabled": true
}
12 changes: 11 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ We welcome all contributions! Please open a [pull request](https://github.com/cm
- [IDE](#ide)
- [Adding a new DBMS](#adding-a-new-dbms)
- [Java Development Notes](#java-development-notes)
- [Avoid var keyword](#avoid-var-keyword)
- [Code Style](#code-style)
- [Compiler Warnings](#compiler-warnings)
- [Avoid var keyword](#avoid-var-keyword)
- [Alternatives to arrays of generics](#alternatives-to-arrays-of-generics)
- [this-escape warnings](#this-escape-warnings)

<!-- /TOC -->

Expand All @@ -31,6 +33,14 @@ Please see the existing MySQL and PostgreSQL code for an example.

## Java Development Notes

### Code Style

To allow reviewers to focus more on code content and not style nits, [PR #416](https://github.com/cmu-db/benchbase/pulls/416) added support for auto formatting code at compile time according to [Google Java Style](https://google.github.io/styleguide/javaguide.html) using [google-java-format](https://github.com/google/google-java-format) and [fmt-maven-plugin](https://github.com/spotify/fmt-maven-plugin) Maven plugins.

Be sure to commit and include these changes in your PRs when submitting them so that the CI pipeline passes.

Additionally, this formatting style is included in the VSCode settings files for this repo.

### Compiler Warnings

In an effort to enforce clean, safe, maintainable code, [PR #413](https://github.com/cmu-db/benchbase/pull/413) enabled the `-Werror` and `-Xlint:all` options for the `javac` compiler.
Expand Down
2 changes: 2 additions & 0 deletions docker/benchbase/common-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export BENCHBASE_PROFILE="${BENCHBASE_PROFILE:-postgres}"
export CLEAN_BUILD="${CLEAN_BUILD:-true}" # true, pre, post, false
# Whether to run the test target during build.
export SKIP_TESTS="${SKIP_TESTS:-false}"
# Whether to do format checks during build (mostly for CI).
export DO_FORMAT_CHECKS="${DO_FORMAT_CHECKS:-false}"

# Setting this allows us to easily tag and publish the image name in our CI pipelines or locally.
CONTAINER_REGISTRY_NAME="${CONTAINER_REGISTRY_NAME:-}"
Expand Down
7 changes: 7 additions & 0 deletions docker/benchbase/devcontainer/build-in-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set -eu -o pipefail
BENCHBASE_PROFILES="${BENCHBASE_PROFILES:-cockroachdb mariadb mysql oracle phoenix postgres spanner sqlite sqlserver}"
CLEAN_BUILD="${CLEAN_BUILD:-true}" # true, false, pre, post
SKIP_TESTS="${SKIP_TESTS:-false}"
DO_FORMAT_CHECKS="${DO_FORMAT_CHECKS:-false}"

cd /benchbase
mkdir -p results
Expand Down Expand Up @@ -95,6 +96,12 @@ else
echo "WARNING: Unhandled SKIP_TESTS mode: '$SKIP_TESTS'" >&2
fi

# Pre format checks are mostly for CI.
# Else, things are reformatted during compile.
if [ "${DO_FORMAT_CHECKS:-}" == 'true' ]; then
mvn -B --file pom.xml fmt:check
fi

# Fetch resources serially to work around mvn races with downloading the same
# file in multiple processes (mvn uses *.part instead of use tmpfile naming).
for profile in ${BENCHBASE_PROFILES}; do
Expand Down
1 change: 1 addition & 0 deletions docker/benchbase/run-dev-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ docker run ${INTERACTIVE_ARGS:-} --rm \
--env BENCHBASE_PROFILES="$BENCHBASE_PROFILES" \
--env CLEAN_BUILD="$CLEAN_BUILD" \
--env SKIP_TESTS="$SKIP_TESTS" \
--env DO_FORMAT_CHECKS="$DO_FORMAT_CHECKS" \
--env EXTRA_MAVEN_ARGS="${EXTRA_MAVEN_ARGS:-}" \
--user "$CONTAINERUSER_UID:$CONTAINERUSER_GID" \
-v "$MAVEN_CONFIG:/home/containeruser/.m2" \
Expand Down
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,25 @@
<artifactId>janino</artifactId>
<version>3.1.11</version>
</dependency>

</dependencies>

<build>
<directory>${buildDirectory}</directory>
<plugins>
<plugin>
<!-- format/check code via google style format -->
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.21.1</version>
<executions>
<execution>
<goals>
<goal>check</goal>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
148 changes: 69 additions & 79 deletions src/main/java/com/oltpbenchmark/BenchmarkState.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,109 +18,99 @@
package com.oltpbenchmark;

import com.oltpbenchmark.types.State;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class BenchmarkState {

private static final Logger LOG = LoggerFactory.getLogger(BenchmarkState.class);
private static final Logger LOG = LoggerFactory.getLogger(BenchmarkState.class);

private final long testStartNs;
private final CountDownLatch startBarrier;
private final AtomicInteger notDoneCount;
private volatile State state = State.WARMUP;
private final long testStartNs;
private final CountDownLatch startBarrier;
private final AtomicInteger notDoneCount;
private volatile State state = State.WARMUP;

/**
* @param numThreads number of threads involved in the test: including the
* master thread.
*/
public BenchmarkState(int numThreads) {
startBarrier = new CountDownLatch(numThreads);
notDoneCount = new AtomicInteger(numThreads);
/**
* @param numThreads number of threads involved in the test: including the master thread.
*/
public BenchmarkState(int numThreads) {
startBarrier = new CountDownLatch(numThreads);
notDoneCount = new AtomicInteger(numThreads);

testStartNs = System.nanoTime();
}

testStartNs = System.nanoTime();
}
// Protected by this

// Protected by this
public long getTestStartNs() {
return testStartNs;
}

public long getTestStartNs() {
return testStartNs;
public State getState() {
synchronized (this) {
return state;
}
}

public State getState() {
synchronized (this) {
return state;
}
/** Wait for all threads to call this. Returns once all the threads have entered. */
public void blockForStart() {

startBarrier.countDown();
try {
startBarrier.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

/**
* Wait for all threads to call this. Returns once all the threads have
* entered.
*/
public void blockForStart() {
public void startMeasure() {
state = State.MEASURE;
}

public void startColdQuery() {
state = State.COLD_QUERY;
}

startBarrier.countDown();
try {
startBarrier.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public void startHotQuery() {
state = State.MEASURE;
}

public void startMeasure() {
state = State.MEASURE;
}
public void signalLatencyComplete() {
state = State.LATENCY_COMPLETE;
}

public void startColdQuery() {
state = State.COLD_QUERY;
}
public void ackLatencyComplete() {
state = State.MEASURE;
}

public void startHotQuery() {
state = State.MEASURE;
}
public void signalError() {
// A thread died, decrement the count and set error state
notDoneCount.decrementAndGet();
state = State.ERROR;
}

public void signalLatencyComplete() {
state = State.LATENCY_COMPLETE;
}
public void startCoolDown() {
state = State.DONE;

public void ackLatencyComplete() {
state = State.MEASURE;
}
// The master thread must also signal that it is done
signalDone();
}

public void signalError() {
// A thread died, decrement the count and set error state
notDoneCount.decrementAndGet();
state = State.ERROR;
}
/** Notify that this thread has entered the done state. */
public int signalDone() {

public void startCoolDown() {
state = State.DONE;
int current = notDoneCount.decrementAndGet();

// The master thread must also signal that it is done
signalDone();
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("%d workers are not done. Waiting until they finish", current));
}

/**
* Notify that this thread has entered the done state.
*/
public int signalDone() {

int current = notDoneCount.decrementAndGet();

if (LOG.isDebugEnabled()) {
LOG.debug(String.format("%d workers are not done. Waiting until they finish", current));
}
if (current == 0) {
// We are the last thread to notice that we are done: wake any
// blocked workers
this.state = State.EXIT;
}
return current;
if (current == 0) {
// We are the last thread to notice that we are done: wake any
// blocked workers
this.state = State.EXIT;
}

}
return current;
}
}
Loading
Loading