Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
[fix][sec] Revert "[fix][sec] Add a check for the input time value (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
liangyepianzhou authored Mar 13, 2024
1 parent d15e87d commit ffff639
Show file tree
Hide file tree
Showing 22 changed files with 2 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ public int getMinimumRolloverTimeMs() {
* the time unit
*/
public void setMinimumRolloverTime(int minimumRolloverTime, TimeUnit unit) {
checkArgument(minimumRolloverTime >= 0);
this.minimumRolloverTimeMs = (int) unit.toMillis(minimumRolloverTime);
checkArgument(maximumRolloverTimeMs >= minimumRolloverTimeMs,
"Minimum rollover time needs to be less than maximum rollover time");
Expand All @@ -196,7 +195,6 @@ public long getMaximumRolloverTimeMs() {
* the time unit
*/
public void setMaximumRolloverTime(int maximumRolloverTime, TimeUnit unit) {
checkArgument(maximumRolloverTime >= 0);
this.maximumRolloverTimeMs = unit.toMillis(maximumRolloverTime);
checkArgument(maximumRolloverTimeMs >= minimumRolloverTimeMs,
"Maximum rollover time needs to be greater than minimum rollover time");
Expand Down Expand Up @@ -413,8 +411,7 @@ public ManagedLedgerConfig setThrottleMarkDelete(double throttleMarkDelete) {
* time unit for retention time
*/
public ManagedLedgerConfig setRetentionTime(int retentionTime, TimeUnit unit) {
checkArgument(retentionTime >= -1, "The retention time should be -1, 0 or value > 0");
this.retentionTimeMs = retentionTime != -1 ? unit.toMillis(retentionTime) : -1;
this.retentionTimeMs = unit.toMillis(retentionTime);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.bookkeeper.mledger.impl;

import static com.google.common.base.Preconditions.checkArgument;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import org.apache.bookkeeper.mledger.ManagedLedgerFactoryMXBean;
Expand All @@ -42,7 +41,6 @@ public ManagedLedgerFactoryMBeanImpl(ManagedLedgerFactoryImpl factory) throws Ex
}

public void refreshStats(long period, TimeUnit unit) {
checkArgument(period >= 0);
double seconds = unit.toMillis(period) / 1000.0;

if (seconds <= 0.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.bookkeeper.mledger.impl;

import static com.google.common.base.Preconditions.checkArgument;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import org.apache.bookkeeper.mledger.ManagedCursor;
Expand Down Expand Up @@ -65,7 +64,6 @@ public ManagedLedgerMBeanImpl(ManagedLedgerImpl managedLedger) {
}

public void refreshStats(long period, TimeUnit unit) {
checkArgument(period >= 0);
double seconds = unit.toMillis(period) / 1000.0;
if (seconds <= 0.0) {
// skip refreshing stats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.broker.stats;

import static com.google.common.base.Preconditions.checkArgument;
import static io.prometheus.client.CollectorRegistry.defaultRegistry;
import io.prometheus.client.Collector;
import io.prometheus.client.Summary;
Expand Down Expand Up @@ -71,7 +70,6 @@ public DimensionStats(String name, long updateDurationInSec) {
}

public void recordDimensionTimeValue(long latency, TimeUnit unit) {
checkArgument(latency >= 0);
summary.observe(unit.toMillis(latency));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.broker.stats.prometheus.metrics;

import static com.google.common.base.Preconditions.checkArgument;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
import org.apache.bookkeeper.stats.Counter;
Expand Down Expand Up @@ -58,7 +57,6 @@ public void addCount(long delta) {

@Override
public void addLatency(long eventLatency, TimeUnit unit) {
checkArgument(eventLatency >= 0);
long valueMillis = unit.toMillis(eventLatency);
counter.add(valueMillis);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ private void checkTopicRetentionPolicy(String topicName, RetentionPolicies reten
ManagedLedgerConfig config = pulsar.getBrokerService()
.getManagedLedgerConfig(TopicName.get(topicName)).get();
Assert.assertEquals(config.getRetentionSizeInMB(), retentionPolicies.getRetentionSizeInMB());
Assert.assertEquals(config.getRetentionTimeMillis(), retentionPolicies.getRetentionTimeInMinutes() < 0
? retentionPolicies.getRetentionTimeInMinutes()
: retentionPolicies.getRetentionTimeInMinutes() * 60000L);
Assert.assertEquals(config.getRetentionTimeMillis(),retentionPolicies.getRetentionTimeInMinutes() * 60000L);
}

private void testCompactionCursorRetention(String topic) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ public ClientConfiguration setServiceUrl(String serviceUrl) {
* @param unit the time unit in which the duration is defined
*/
public void setConnectionTimeout(int duration, TimeUnit unit) {
checkArgument(duration >= 0);
confData.setConnectionTimeoutMs((int) unit.toMillis(duration));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public long getAckTimeoutMillis() {
* @return {@link ConsumerConfiguration}
*/
public ConsumerConfiguration setAckTimeout(long ackTimeout, TimeUnit timeUnit) {
checkArgument(ackTimeout >= 0);
long ackTimeoutMillis = timeUnit.toMillis(ackTimeout);
checkArgument(ackTimeoutMillis >= minAckTimeoutMillis,
"Ack timeout should be should be greater than " + minAckTimeoutMillis + " ms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.client.admin.internal;

import static com.google.common.base.Preconditions.checkArgument;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -201,21 +200,18 @@ public PulsarAdminBuilder tlsProtocols(Set<String> tlsProtocols) {

@Override
public PulsarAdminBuilder connectionTimeout(int connectionTimeout, TimeUnit connectionTimeoutUnit) {
checkArgument(connectionTimeout >= 0);
this.conf.setConnectionTimeoutMs((int) connectionTimeoutUnit.toMillis(connectionTimeout));
return this;
}

@Override
public PulsarAdminBuilder readTimeout(int readTimeout, TimeUnit readTimeoutUnit) {
checkArgument(readTimeout >= 0);
this.conf.setReadTimeoutMs((int) readTimeoutUnit.toMillis(readTimeout));
return this;
}

@Override
public PulsarAdminBuilder requestTimeout(int requestTimeout, TimeUnit requestTimeoutUnit) {
checkArgument(requestTimeout >= 0);
this.conf.setRequestTimeoutMs((int) requestTimeoutUnit.toMillis(requestTimeout));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public TransactionPendingAckStats getPendingAckStats(String topic, String subNam
@Override
public CompletableFuture<Map<String, TransactionMetadata>> getSlowTransactionsByCoordinatorIdAsync(
Integer coordinatorId, long timeout, TimeUnit timeUnit) {
checkArgument(timeout >= 0);
WebTarget path = adminV3Transactions.path("slowTransactions");
path = path.path(timeUnit.toMillis(timeout) + "");
if (coordinatorId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ public AutoClusterFailoverBuilder switchBackDelay(long switchBackDelay, TimeUnit

@Override
public AutoClusterFailoverBuilder checkInterval(long interval, TimeUnit timeUnit) {
checkArgument(interval >= 0L, "check interval time must not be negative.");
this.checkIntervalMs = timeUnit.toMillis(interval);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public ClientBuilder operationTimeout(int operationTimeout, TimeUnit unit) {

@Override
public ClientBuilder lookupTimeout(int lookupTimeout, TimeUnit unit) {
checkArgument(lookupTimeout >= 0, "lookupTimeout must not be negative");
conf.setLookupTimeoutMs(unit.toMillis(lookupTimeout));
return this;
}
Expand Down Expand Up @@ -334,7 +333,6 @@ public ClientBuilder keepAliveInterval(int keepAliveInterval, TimeUnit unit) {

@Override
public ClientBuilder connectionTimeout(int duration, TimeUnit unit) {
checkArgument(duration >= 0, "connectionTimeout needs to be >= 0");
conf.setConnectionTimeoutMs((int) unit.toMillis(duration));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ public void acknowledge(Messages<?> messages) throws PulsarClientException {

@Override
public void reconsumeLater(Message<?> message, long delayTime, TimeUnit unit) throws PulsarClientException {
checkArgument(delayTime >= 0, "The delay time must not be negative.");
reconsumeLater(message, null, delayTime, unit);
}

Expand Down Expand Up @@ -564,7 +563,6 @@ public CompletableFuture<Void> reconsumeLaterAsync(Message<?> message, long dela
@Override
public CompletableFuture<Void> reconsumeLaterAsync(
Message<?> message, Map<String, String> customProperties, long delayTime, TimeUnit unit) {
checkArgument(delayTime >= 0, "The delay time must not be negative.");
if (!conf.isRetryEnable()) {
return FutureUtil.failedFuture(new PulsarClientException(RECONSUME_LATER_ERROR_MSG));
}
Expand Down Expand Up @@ -601,14 +599,12 @@ public CompletableFuture<Void> acknowledgeCumulativeAsync(Message<?> message) {

@Override
public CompletableFuture<Void> reconsumeLaterCumulativeAsync(Message<?> message, long delayTime, TimeUnit unit) {
checkArgument(delayTime >= 0, "The delay time must not be negative.");
return reconsumeLaterCumulativeAsync(message, null, delayTime, unit);
}

@Override
public CompletableFuture<Void> reconsumeLaterCumulativeAsync(
Message<?> message, Map<String, String> customProperties, long delayTime, TimeUnit unit) {
checkArgument(delayTime >= 0, "The delay time must not be negative.");
if (!conf.isRetryEnable()) {
return FutureUtil.failedFuture(new PulsarClientException(RECONSUME_LATER_ERROR_MSG));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ public ConsumerBuilder<T> enableBatchIndexAcknowledgment(boolean batchIndexAckno

@Override
public ConsumerBuilder<T> expireTimeOfIncompleteChunkedMessage(long duration, TimeUnit unit) {
checkArgument(duration >= 0, "expired time of incomplete chunk message must not be negative");
conf.setExpireTimeOfIncompleteChunkedMessageMillis(unit.toMillis(duration));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ public ControlledClusterFailoverBuilder urlProviderHeader(Map<String, String> he

@Override
public ControlledClusterFailoverBuilder checkInterval(long interval, @NonNull TimeUnit timeUnit) {
checkArgument(interval >= 0, "The check interval time must not be negative.");
this.interval = timeUnit.toMillis(interval);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ public ReaderBuilder<T> autoAckOldestChunkedMessageOnQueueFull(boolean autoAckOl

@Override
public ReaderBuilder<T> expireTimeOfIncompleteChunkedMessage(long duration, TimeUnit unit) {
checkArgument(duration >= 0, "The expired time must not be negative.");
conf.setExpireTimeOfIncompleteChunkedMessageMillis(unit.toMillis(duration));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.client.impl;

import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.VisibleForTesting;
import io.netty.buffer.ByteBuf;
import io.netty.util.Recycler;
Expand Down Expand Up @@ -206,7 +205,6 @@ private void failPendingRequest() {
}

public CompletableFuture<TxnID> newTransactionAsync(long timeout, TimeUnit unit) {
checkArgument(timeout >= 0, "The timeout must not be negative.");
if (LOG.isDebugEnabled()) {
LOG.debug("New transaction with timeout in ms {}", unit.toMillis(timeout));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public TypedMessageBuilder<T> disableReplication() {

@Override
public TypedMessageBuilder<T> deliverAfter(long delay, TimeUnit unit) {
checkArgument(delay >= 0, "The delay time must not be negative.");
return deliverAt(System.currentTimeMillis() + unit.toMillis(delay));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.client.impl.transaction;

import static com.google.common.base.Preconditions.checkArgument;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -46,7 +45,6 @@ public TransactionBuilderImpl(PulsarClientImpl client, TransactionCoordinatorCli

@Override
public TransactionBuilder withTransactionTimeout(long txnTimeout, TimeUnit timeoutUnit) {
checkArgument(txnTimeout >= 0, "The txn timeout must not be negative.");
this.txnTimeout = txnTimeout;
this.timeUnit = timeoutUnit;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.pulsar.client.util;

import static com.google.common.base.Preconditions.checkArgument;
import java.time.Clock;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand All @@ -34,7 +33,6 @@ public class ObjectCache<T> implements Supplier<T> {

public ObjectCache(Supplier<T> supplier, long cacheDuration, TimeUnit unit) {
this(supplier, cacheDuration, unit, Clock.systemUTC());
checkArgument(cacheDuration >= 0, "The cache duration must not be negative.");
}

ObjectCache(Supplier<T> supplier, long cacheDuration, TimeUnit unit, Clock clock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.bookkeeper.client;

import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -365,7 +364,6 @@ public synchronized CompletableFuture<Void> promiseAfter(int steps, List<Complet
}

public synchronized void addEntryDelay(long delay, TimeUnit unit) {
checkArgument(delay >= 0, "The delay time must not be negative.");
addEntryDelaysMillis.add(unit.toMillis(delay));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.bookkeeper.client;

import static com.google.common.base.Preconditions.checkArgument;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -66,7 +65,6 @@ public void addCount(long delta) {

@Override
public void addLatency(long eventLatency, TimeUnit unit) {
checkArgument(eventLatency >= 0, "The event latency must not be negative.");
long valueMillis = unit.toMillis(eventLatency);
updateMax(val.addAndGet(valueMillis));
}
Expand Down

0 comments on commit ffff639

Please sign in to comment.