mirror of https://github.com/apache/druid.git
Fix a couple bugs due to calling Period.getMillis(). (#4006)
This commit is contained in:
parent
337f3870d8
commit
df623ebfe3
|
@ -23,7 +23,6 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import io.druid.java.util.common.logger.Logger;
|
||||
import io.druid.query.lookup.LookupExtractorFactory;
|
||||
import io.druid.query.lookup.LookupIntrospectHandler;
|
||||
|
@ -63,7 +62,11 @@ public class PollingLookupFactory implements LookupExtractorFactory
|
|||
this.pollPeriod = pollPeriod == null ? Period.ZERO : pollPeriod;
|
||||
this.dataFetcher = dataFetcher;
|
||||
this.cacheFactory = cacheFactory;
|
||||
this.pollingLookup = new PollingLookup(this.pollPeriod.getMillis(), this.dataFetcher, this.cacheFactory);
|
||||
this.pollingLookup = new PollingLookup(
|
||||
this.pollPeriod.toStandardDuration().getMillis(),
|
||||
this.dataFetcher,
|
||||
this.cacheFactory
|
||||
);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
@ -22,7 +22,7 @@ package io.druid.metadata;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -133,8 +133,8 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
private static final EmittingLogger log = new EmittingLogger(SQLMetadataRuleManager.class);
|
||||
|
||||
private final ObjectMapper jsonMapper;
|
||||
private final Supplier<MetadataRuleManagerConfig> config;
|
||||
private final Supplier<MetadataStorageTablesConfig> dbTables;
|
||||
private final MetadataRuleManagerConfig config;
|
||||
private final MetadataStorageTablesConfig dbTables;
|
||||
private final IDBI dbi;
|
||||
private final AtomicReference<ImmutableMap<String, List<Rule>>> rules;
|
||||
private final AuditManager auditManager;
|
||||
|
@ -151,8 +151,8 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
@Inject
|
||||
public SQLMetadataRuleManager(
|
||||
@Json ObjectMapper jsonMapper,
|
||||
Supplier<MetadataRuleManagerConfig> config,
|
||||
Supplier<MetadataStorageTablesConfig> dbTables,
|
||||
MetadataRuleManagerConfig config,
|
||||
MetadataStorageTablesConfig dbTables,
|
||||
SQLMetadataConnector connector,
|
||||
AuditManager auditManager
|
||||
)
|
||||
|
@ -163,6 +163,10 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
this.dbi = connector.getDBI();
|
||||
this.auditManager = auditManager;
|
||||
|
||||
// Verify configured Periods can be treated as Durations (fail-fast before they're needed).
|
||||
Preconditions.checkNotNull(config.getAlertThreshold().toStandardDuration());
|
||||
Preconditions.checkNotNull(config.getPollDuration().toStandardDuration());
|
||||
|
||||
this.rules = new AtomicReference<>(
|
||||
ImmutableMap.<String, List<Rule>>of()
|
||||
);
|
||||
|
@ -178,7 +182,7 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
|
||||
exec = MoreExecutors.listeningDecorator(Execs.scheduledSingleThreaded("DatabaseRuleManager-Exec--%d"));
|
||||
|
||||
createDefaultRule(dbi, getRulesTable(), config.get().getDefaultRule(), jsonMapper);
|
||||
createDefaultRule(dbi, getRulesTable(), config.getDefaultRule(), jsonMapper);
|
||||
future = exec.scheduleWithFixedDelay(
|
||||
new Runnable()
|
||||
{
|
||||
|
@ -194,7 +198,7 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
}
|
||||
},
|
||||
0,
|
||||
config.get().getPollDuration().toStandardDuration().getMillis(),
|
||||
config.getPollDuration().toStandardDuration().getMillis(),
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
|
||||
|
@ -300,7 +304,7 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
retryStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() - retryStartTime > config.get().getAlertThreshold().getMillis()) {
|
||||
if (System.currentTimeMillis() - retryStartTime > config.getAlertThreshold().toStandardDuration().getMillis()) {
|
||||
log.makeAlert(e, "Exception while polling for rules")
|
||||
.emit();
|
||||
retryStartTime = 0;
|
||||
|
@ -328,8 +332,8 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
if (theRules.get(dataSource) != null) {
|
||||
retVal.addAll(theRules.get(dataSource));
|
||||
}
|
||||
if (theRules.get(config.get().getDefaultRule()) != null) {
|
||||
retVal.addAll(theRules.get(config.get().getDefaultRule()));
|
||||
if (theRules.get(config.getDefaultRule()) != null) {
|
||||
retVal.addAll(theRules.get(config.getDefaultRule()));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
@ -398,6 +402,6 @@ public class SQLMetadataRuleManager implements MetadataRuleManager
|
|||
|
||||
private String getRulesTable()
|
||||
{
|
||||
return dbTables.get().getRulesTable();
|
||||
return dbTables.getRulesTable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,10 +20,8 @@
|
|||
package io.druid.metadata;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import io.druid.audit.AuditManager;
|
||||
import io.druid.java.util.common.lifecycle.Lifecycle;
|
||||
import io.druid.server.audit.SQLAuditManager;
|
||||
|
@ -34,8 +32,8 @@ import org.skife.jdbi.v2.IDBI;
|
|||
public class SQLMetadataRuleManagerProvider implements MetadataRuleManagerProvider
|
||||
{
|
||||
private final ObjectMapper jsonMapper;
|
||||
private final Supplier<MetadataRuleManagerConfig> config;
|
||||
private final Supplier<MetadataStorageTablesConfig> dbTables;
|
||||
private final MetadataRuleManagerConfig config;
|
||||
private final MetadataStorageTablesConfig dbTables;
|
||||
private final SQLMetadataConnector connector;
|
||||
private final Lifecycle lifecycle;
|
||||
private final IDBI dbi;
|
||||
|
@ -44,8 +42,8 @@ public class SQLMetadataRuleManagerProvider implements MetadataRuleManagerProvid
|
|||
@Inject
|
||||
public SQLMetadataRuleManagerProvider(
|
||||
ObjectMapper jsonMapper,
|
||||
Supplier<MetadataRuleManagerConfig> config,
|
||||
Supplier<MetadataStorageTablesConfig> dbTables,
|
||||
MetadataRuleManagerConfig config,
|
||||
MetadataStorageTablesConfig dbTables,
|
||||
SQLMetadataConnector connector,
|
||||
Lifecycle lifecycle,
|
||||
SQLAuditManager auditManager
|
||||
|
@ -72,7 +70,7 @@ public class SQLMetadataRuleManagerProvider implements MetadataRuleManagerProvid
|
|||
{
|
||||
connector.createRulesTable();
|
||||
SQLMetadataRuleManager.createDefaultRule(
|
||||
dbi, dbTables.get().getRulesTable(), config.get().getDefaultRule(), jsonMapper
|
||||
dbi, dbTables.getRulesTable(), config.getDefaultRule(), jsonMapper
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ public class SQLMetadataRuleManagerTest
|
|||
connector.createRulesTable();
|
||||
ruleManager = new SQLMetadataRuleManager(
|
||||
mapper,
|
||||
Suppliers.ofInstance(new MetadataRuleManagerConfig()),
|
||||
Suppliers.ofInstance(tablesConfig),
|
||||
new MetadataRuleManagerConfig(),
|
||||
tablesConfig,
|
||||
connector,
|
||||
auditManager
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue