Skip to content

Commit

Permalink
[SpotBugs]Enable spotbugs in module tiered-storage (apache#8802)
Browse files Browse the repository at this point in the history
Fix issue: https://github.com/streamnative/pulsar/issues/1808

This PR enables SpotBugs for module `tiered-storage`
  • Loading branch information
Renkai authored Dec 4, 2020
1 parent 03f5b54 commit c5d9fef
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 30 deletions.
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1342,16 +1342,16 @@ flexible messaging model and an intuitive client API.</description>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8.0,)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.3.9,)</version>
</requireMavenVersion>
</rules>
</configuration>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8.0,)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.3.9,)</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
21 changes: 19 additions & 2 deletions tiered-storage/file-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -100,13 +100,30 @@
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-nar-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>${basedir}/../src/main/resources/findbugsExclude.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<id>spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
18 changes: 18 additions & 0 deletions tiered-storage/jcloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-nar-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>${basedir}/../src/main/resources/findbugsExclude.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<id>spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,7 +134,8 @@ public CompletableFuture<LedgerEntries> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -189,8 +183,8 @@ static private class InternalLedgerMetadata implements LedgerMetadata {
private State state;
private Map<String, byte[]> customMetadata = Maps.newHashMap();
private TreeMap<Long, ArrayList<BookieId>> ensembles =
new TreeMap<Long, ArrayList<BookieId>>();
new TreeMap<>();

InternalLedgerMetadata(LedgerMetadataFormat ledgerMetadataFormat) {
this.ensembleSize = ledgerMetadataFormat.getEnsembleSize();
this.writeQuorumSize = ledgerMetadataFormat.getQuorumSize();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,7 +53,7 @@
* </p>
*/
@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";
Expand Down
22 changes: 22 additions & 0 deletions tiered-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,26 @@
<module>jcloud</module>
<module>file-system</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>${basedir}/src/main/resources/findbugsExclude.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<id>spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
26 changes: 26 additions & 0 deletions tiered-storage/src/main/resources/findbugsExclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<FindBugsFilter>
<Match>
<Class name="~org.apache.zookeeper.*"/>
<Bug pattern="DM_EXIT,DM_DEFAULT_ENCODING"/>
</Match>
</FindBugsFilter>

0 comments on commit c5d9fef

Please sign in to comment.