use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class DruidMeta method prepare.
@Override
public StatementHandle prepare(final ConnectionHandle ch, final String sql, final long maxRowCount) {
try {
final StatementHandle statement = createStatement(ch);
final DruidStatement druidStatement;
try {
druidStatement = getDruidStatement(statement);
} catch (NoSuchStatementException e) {
throw logFailure(new ISE(e, e.getMessage()));
}
final DruidConnection druidConnection = getDruidConnection(statement.connectionId);
AuthenticationResult authenticationResult = authenticateConnection(druidConnection);
if (authenticationResult == null) {
throw logFailure(new ForbiddenException("Authentication failed."), "Authentication failed for statement[%s]", druidStatement.getStatementId());
}
statement.signature = druidStatement.prepare(sql, maxRowCount, authenticationResult).getSignature();
LOG.debug("Successfully prepared statement[%s] for execution", druidStatement.getStatementId());
return statement;
} catch (NoSuchConnectionException e) {
throw e;
} catch (Throwable t) {
throw errorHandler.sanitize(t);
}
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class DruidKerberosUtil method authenticateIfRequired.
public static void authenticateIfRequired(String internalClientPrincipal, String internalClientKeytab) {
if (!Strings.isNullOrEmpty(internalClientPrincipal) && !Strings.isNullOrEmpty(internalClientKeytab)) {
Configuration conf = new Configuration();
conf.setClassLoader(DruidKerberosModule.class.getClassLoader());
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
UserGroupInformation.setConfiguration(conf);
try {
// login for the first time.
if (UserGroupInformation.getCurrentUser().hasKerberosCredentials() == false || !UserGroupInformation.getCurrentUser().getUserName().equals(internalClientPrincipal)) {
log.info("trying to authenticate user [%s] with keytab [%s]", internalClientPrincipal, internalClientKeytab);
UserGroupInformation.loginUserFromKeytab(internalClientPrincipal, internalClientKeytab);
return;
}
// try to relogin in case the TGT expired
if (UserGroupInformation.isLoginKeytabBased()) {
log.info("Re-Login from key tab [%s] with principal [%s]", internalClientKeytab, internalClientPrincipal);
UserGroupInformation.getLoginUser().checkTGTAndReloginFromKeytab();
return;
} else if (UserGroupInformation.isLoginTicketBased()) {
log.info("Re-Login from Ticket cache");
UserGroupInformation.getLoginUser().reloginFromTicketCache();
return;
}
} catch (IOException e) {
throw new ISE(e, "Failed to authenticate user principal [%s] with keytab [%s]", internalClientPrincipal, internalClientKeytab);
}
}
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class JdbcCacheGenerator method generateCache.
@Override
@Nullable
public CacheScheduler.VersionedCache generateCache(final JdbcExtractionNamespace namespace, final CacheScheduler.EntryImpl<JdbcExtractionNamespace> entryId, final String lastVersion, final CacheScheduler scheduler) {
final long lastCheck = lastVersion == null ? JodaUtils.MIN_INSTANT : Long.parseLong(lastVersion);
final Long lastDBUpdate;
final long dbQueryStart;
try {
lastDBUpdate = lastUpdates(entryId, namespace);
if (lastDBUpdate != null && lastDBUpdate <= lastCheck) {
return null;
}
} catch (UnableToObtainConnectionException e) {
if (e.getMessage().contains(NO_SUITABLE_DRIVER_FOUND_ERROR)) {
throw new ISE(e, JDBC_DRIVER_JAR_FILES_MISSING_ERROR);
} else {
throw e;
}
}
dbQueryStart = System.currentTimeMillis();
LOG.debug("Updating %s", entryId);
final String newVersion;
if (lastDBUpdate != null) {
newVersion = lastDBUpdate.toString();
} else {
newVersion = StringUtils.format("%d", dbQueryStart);
}
final CacheScheduler.VersionedCache versionedCache = scheduler.createVersionedCache(entryId, newVersion);
final long startNs = System.nanoTime();
try (Handle handle = getHandle(entryId, namespace);
ResultIterator<Pair<String, String>> pairs = getLookupPairs(handle, namespace)) {
final Map<String, String> cache = versionedCache.getCache();
final MapPopulator.PopulateResult populateResult = MapPopulator.populateAndWarnAtByteLimit(pairs, cache, (long) (MAX_MEMORY * namespace.getMaxHeapPercentage() / 100.0), null == entryId ? null : entryId.toString());
final long duration = System.nanoTime() - startNs;
LOG.info("Finished loading %,d values (%d bytes) for [%s] in %,d ns", populateResult.getEntries(), populateResult.getBytes(), entryId, duration);
return versionedCache;
} catch (UnableToObtainConnectionException e) {
if (e.getMessage().contains(NO_SUITABLE_DRIVER_FOUND_ERROR)) {
throw new ISE(e, JDBC_DRIVER_JAR_FILES_MISSING_ERROR);
} else {
throw e;
}
} catch (Throwable t) {
try {
versionedCache.close();
} catch (Exception e) {
t.addSuppressed(e);
}
throw t;
}
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class SegmentMetadataUpdateAction method perform.
@Override
public Void perform(Task task, TaskActionToolbox toolbox) {
TaskLocks.checkLockCoversSegments(task, toolbox.getTaskLockbox(), segments);
try {
toolbox.getTaskLockbox().doInCriticalSection(task, segments.stream().map(DataSegment::getInterval).collect(Collectors.toList()), CriticalAction.builder().onValidLocks(() -> {
toolbox.getIndexerMetadataStorageCoordinator().updateSegmentMetadata(segments);
return null;
}).onInvalidLocks(() -> {
throw new ISE("Some locks for task[%s] are already revoked", task.getId());
}).build());
} catch (Exception e) {
throw new RuntimeException(e);
}
// Emit metrics
final ServiceMetricEvent.Builder metricBuilder = new ServiceMetricEvent.Builder();
IndexTaskUtils.setTaskDimensions(metricBuilder, task);
for (DataSegment segment : segments) {
metricBuilder.setDimension(DruidMetrics.INTERVAL, segment.getInterval().toString());
toolbox.getEmitter().emit(metricBuilder.build("segment/moved/bytes", segment.getSize()));
}
return null;
}
use of org.apache.druid.java.util.common.ISE in project druid by druid-io.
the class SegmentTransactionalInsertAction method checkWithSegmentLock.
private void checkWithSegmentLock() {
final Map<Interval, List<DataSegment>> oldSegmentsMap = groupSegmentsByIntervalAndSort(segmentsToBeOverwritten);
final Map<Interval, List<DataSegment>> newSegmentsMap = groupSegmentsByIntervalAndSort(segments);
oldSegmentsMap.values().forEach(TaskLockHelper::verifyRootPartitionIsAdjacentAndAtomicUpdateGroupIsFull);
newSegmentsMap.values().forEach(TaskLockHelper::verifyRootPartitionIsAdjacentAndAtomicUpdateGroupIsFull);
oldSegmentsMap.forEach((interval, oldSegmentsPerInterval) -> {
final List<DataSegment> newSegmentsPerInterval = Preconditions.checkNotNull(newSegmentsMap.get(interval), "segments of interval[%s]", interval);
// These lists are already sorted in groupSegmentsByIntervalAndSort().
final int oldStartRootPartitionId = oldSegmentsPerInterval.get(0).getStartRootPartitionId();
final int oldEndRootPartitionId = oldSegmentsPerInterval.get(oldSegmentsPerInterval.size() - 1).getEndRootPartitionId();
final int newStartRootPartitionId = newSegmentsPerInterval.get(0).getStartRootPartitionId();
final int newEndRootPartitionId = newSegmentsPerInterval.get(newSegmentsPerInterval.size() - 1).getEndRootPartitionId();
if (oldStartRootPartitionId != newStartRootPartitionId || oldEndRootPartitionId != newEndRootPartitionId) {
throw new ISE("Root partition range[%d, %d] of new segments doesn't match to root partition range[%d, %d] of old segments", newStartRootPartitionId, newEndRootPartitionId, oldStartRootPartitionId, oldEndRootPartitionId);
}
newSegmentsPerInterval.forEach(eachNewSegment -> oldSegmentsPerInterval.forEach(eachOldSegment -> {
if (eachNewSegment.getMinorVersion() <= eachOldSegment.getMinorVersion()) {
throw new ISE("New segment[%s] have a smaller minor version than old segment[%s]", eachNewSegment, eachOldSegment);
}
}));
});
}
Aggregations