From c5d9fef2996d9890386288659634431652d7dc93 Mon Sep 17 00:00:00 2001 From: Renkai Ge Date: Sat, 5 Dec 2020 00:48:49 +0800 Subject: [PATCH] [SpotBugs]Enable spotbugs in module tiered-storage (#8802) Fix issue: https://github.com/streamnative/pulsar/issues/1808 This PR enables SpotBugs for module `tiered-storage` --- pom.xml | 20 +++++++------- tiered-storage/file-system/pom.xml | 21 +++++++++++++-- tiered-storage/jcloud/pom.xml | 18 +++++++++++++ .../impl/BlobStoreBackedReadHandleImpl.java | 4 ++- .../jcloud/impl/OffloadIndexBlockImpl.java | 18 +++++-------- .../provider/TieredStorageConfiguration.java | 6 +---- tiered-storage/pom.xml | 22 ++++++++++++++++ .../src/main/resources/findbugsExclude.xml | 26 +++++++++++++++++++ 8 files changed, 105 insertions(+), 30 deletions(-) create mode 100644 tiered-storage/src/main/resources/findbugsExclude.xml diff --git a/pom.xml b/pom.xml index 082d6d3c5364d..91a4f5e159be4 100644 --- a/pom.xml +++ b/pom.xml @@ -1342,16 +1342,16 @@ flexible messaging model and an intuitive client API. enforce - - - - [1.8.0,) - - - [3.3.9,) - - - + + + + [1.8.0,) + + + [3.3.9,) + + + diff --git a/tiered-storage/file-system/pom.xml b/tiered-storage/file-system/pom.xml index 74dda918005c0..bd403167f71c3 100644 --- a/tiered-storage/file-system/pom.xml +++ b/tiered-storage/file-system/pom.xml @@ -90,7 +90,7 @@ test - + @@ -100,13 +100,30 @@ - + org.apache.nifi nifi-nar-maven-plugin + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + + ${basedir}/../src/main/resources/findbugsExclude.xml + + + + spotbugs + verify + + check + + + + diff --git a/tiered-storage/jcloud/pom.xml b/tiered-storage/jcloud/pom.xml index 170081cc658df..4e7c67f3df37b 100644 --- a/tiered-storage/jcloud/pom.xml +++ b/tiered-storage/jcloud/pom.xml @@ -94,6 +94,24 @@ org.apache.nifi nifi-nar-maven-plugin + + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + + ${basedir}/../src/main/resources/findbugsExclude.xml + + + + spotbugs + verify + + check + + + + diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java index b48751e830945..16368fae5027e 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedReadHandleImpl.java @@ -26,6 +26,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; +import lombok.val; import org.apache.bookkeeper.client.BKException; import org.apache.bookkeeper.client.api.LastConfirmedAndEntry; import org.apache.bookkeeper.client.api.LedgerEntries; @@ -133,7 +134,8 @@ public CompletableFuture readAsync(long firstEntry, long lastEntr nextExpectedId, entryId, lastEntry); throw new BKException.BKUnexpectedConditionException(); } else { - inputStream.skip(length); + val skipped = inputStream.skip(length); + log.info("Skipped {} bytes.", skipped); } } diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexBlockImpl.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexBlockImpl.java index 80fd62f35e1da..864a942dd09bc 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexBlockImpl.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/OffloadIndexBlockImpl.java @@ -18,13 +18,13 @@ */ package org.apache.bookkeeper.mledger.offload.jcloud.impl; +import static com.google.common.base.Preconditions.checkState; +import static org.apache.bookkeeper.mledger.offload.OffloadUtils.buildLedgerMetadataFormat; import com.google.common.collect.Maps; - import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; import io.netty.util.Recycler; import io.netty.util.Recycler.Handle; - import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; @@ -33,22 +33,17 @@ import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; - import org.apache.bookkeeper.client.api.DigestType; import org.apache.bookkeeper.client.api.LedgerMetadata; import org.apache.bookkeeper.mledger.offload.jcloud.OffloadIndexBlock; import org.apache.bookkeeper.mledger.offload.jcloud.OffloadIndexEntry; -import org.apache.bookkeeper.net.BookieSocketAddress; +import org.apache.bookkeeper.net.BookieId; import org.apache.bookkeeper.proto.DataFormats; import org.apache.bookkeeper.proto.DataFormats.LedgerMetadataFormat; import org.apache.pulsar.common.allocator.PulsarByteBufAllocator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.google.common.base.Preconditions.checkState; -import static org.apache.bookkeeper.mledger.offload.OffloadUtils.buildLedgerMetadataFormat; -import org.apache.bookkeeper.net.BookieId; - public class OffloadIndexBlockImpl implements OffloadIndexBlock { private static final Logger log = LoggerFactory.getLogger(OffloadIndexBlockImpl.class); @@ -177,7 +172,6 @@ public OffloadIndexBlock.IndexInputStream toStream() throws IOException { } static private class InternalLedgerMetadata implements LedgerMetadata { - private LedgerMetadataFormat ledgerMetadataFormat; private int ensembleSize; private int writeQuorumSize; @@ -189,8 +183,8 @@ static private class InternalLedgerMetadata implements LedgerMetadata { private State state; private Map customMetadata = Maps.newHashMap(); private TreeMap> ensembles = - new TreeMap>(); - + new TreeMap<>(); + InternalLedgerMetadata(LedgerMetadataFormat ledgerMetadataFormat) { this.ensembleSize = ledgerMetadataFormat.getEnsembleSize(); this.writeQuorumSize = ledgerMetadataFormat.getQuorumSize(); @@ -340,7 +334,7 @@ private OffloadIndexBlock fromStream(InputStream stream) throws IOException { throw new IOException(String.format("Invalid MagicWord. read: 0x%x expected: 0x%x", magic, INDEX_MAGIC_WORD)); } - int indexBlockLength = dis.readInt(); + dis.readInt(); // no used index block length this.dataObjectLength = dis.readLong(); this.dataHeaderLength = dis.readLong(); int indexEntryCount = dis.readInt(); diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/provider/TieredStorageConfiguration.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/provider/TieredStorageConfiguration.java index ac2bed9e01ccf..7d7d7fae3086b 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/provider/TieredStorageConfiguration.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/provider/TieredStorageConfiguration.java @@ -20,18 +20,14 @@ import static org.apache.bookkeeper.mledger.offload.jcloud.provider.JCloudBlobStoreProvider.AWS_S3; import static org.apache.bookkeeper.mledger.offload.jcloud.provider.JCloudBlobStoreProvider.GOOGLE_CLOUD_STORAGE; - import com.google.common.collect.ImmutableMap; - import java.io.IOException; -import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.stream.Collectors; - import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -57,7 +53,7 @@ *

*/ @Slf4j -public class TieredStorageConfiguration implements Serializable, Cloneable { +public class TieredStorageConfiguration { private static final long serialVersionUID = 1L; public static final String BLOB_STORE_PROVIDER_KEY = "managedLedgerOffloadDriver"; diff --git a/tiered-storage/pom.xml b/tiered-storage/pom.xml index 8c847fbe295a2..38674fa8559cb 100644 --- a/tiered-storage/pom.xml +++ b/tiered-storage/pom.xml @@ -40,4 +40,26 @@ jcloud file-system + + + + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + + ${basedir}/src/main/resources/findbugsExclude.xml + + + + spotbugs + verify + + check + + + + + + diff --git a/tiered-storage/src/main/resources/findbugsExclude.xml b/tiered-storage/src/main/resources/findbugsExclude.xml new file mode 100644 index 0000000000000..5a9926c0e8116 --- /dev/null +++ b/tiered-storage/src/main/resources/findbugsExclude.xml @@ -0,0 +1,26 @@ + + + + + + +