Skip to content

Commit

Permalink
chore: intrdouce spotbugs for s3stream, and reslove all the P1 issues (
Browse files Browse the repository at this point in the history
…#902)

Signed-off-by: daniel-y <[email protected]>
  • Loading branch information
daniel-y authored Jan 25, 2024
1 parent ffdc0de commit a5e1c0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
18 changes: 18 additions & 0 deletions s3stream/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
/*
* This file was generated by the Gradle 'init' task.
*/
import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort

plugins {
id 'java-library'
id 'maven-publish'
id("com.github.spotbugs") version "6.0.7"
}

spotbugsMain {
reports {
html {
required = true
outputLocation = file("$buildDir/reports/spotbugs.html")
setStylesheet("fancy-hist.xsl")
}
}
}

spotbugs {
effort = Effort.valueOf('DEFAULT')
reportLevel = Confidence.valueOf('HIGH')
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class WriteBench implements AutoCloseable {
private final WriteAheadLog log;
private final TrimOffset trimOffset = new TrimOffset();

// Generate random payloads for this benchmark tool
private Random random = new Random();

public WriteBench(Config config) throws IOException {
BlockWALService.BlockWALServiceBuilder builder = BlockWALService.builder(config.path, config.capacity);
if (config.depth != null) {
Expand Down Expand Up @@ -177,7 +180,7 @@ private void runAppendTask(int index, AppendTaskConfig config, Stat stat) throws
System.out.printf("Append task %d started\n", index);

byte[] bytes = new byte[config.recordSizeBytes];
new Random().nextBytes(bytes);
random.nextBytes(bytes);
ByteBuf payload = Unpooled.wrappedBuffer(bytes).retain();
int intervalNanos = (int) TimeUnit.SECONDS.toNanos(1) / Math.max(1, config.throughputBytes / config.recordSizeBytes);
long lastAppendTimeNanos = System.nanoTime();
Expand Down
14 changes: 8 additions & 6 deletions s3stream/src/main/java/com/automq/stream/utils/S3Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void checkS3Access(S3Context context) {
System.exit(1);
}

try (MultipartObjectOperationTask task = new MultipartObjectOperationTask(context)) {
try (S3MultipartUploadTestTask task = new S3MultipartUploadTestTask(context)) {
task.run();
} catch (Throwable e) {
System.out.println("ERROR: " + ExceptionUtils.getRootCause(e));
Expand Down Expand Up @@ -135,9 +135,11 @@ public void close() {
}
}

private static class MultipartObjectOperationTask extends ObjectOperationTask {
public MultipartObjectOperationTask(S3Context context) {
super(context, MultipartObjectOperationTask.class.getSimpleName());
// This task is used to test s3 multipart upload
private static class S3MultipartUploadTestTask extends ObjectOperationTask {
private Random random = new Random();
public S3MultipartUploadTestTask(S3Context context) {
super(context, S3MultipartUploadTestTask.class.getSimpleName());
}

@Override
Expand All @@ -152,12 +154,12 @@ public void run() {
int totalSize = data1Size + data2Size;

byte[] randomBytes = new byte[data1Size];
new Random().nextBytes(randomBytes);
random.nextBytes(randomBytes);
ByteBuf data1 = Unpooled.wrappedBuffer(randomBytes);
writePart(uploadId, path, bucketName, data1, 1).thenAccept(parts::add).get();

byte[] randomBytes2 = new byte[data2Size];
new Random().nextBytes(randomBytes2);
random.nextBytes(randomBytes2);
ByteBuf data2 = Unpooled.wrappedBuffer(randomBytes2);
writePart(uploadId, path, bucketName, data2, 2).thenAccept(parts::add).get();

Expand Down

0 comments on commit a5e1c0f

Please sign in to comment.