use of com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent in project metacat by Netflix.
the class TableServiceImpl method deleteAndReturn.
@Override
public TableDto deleteAndReturn(@Nonnull final QualifiedName name, final boolean isMView) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatDeleteTablePreEvent(name, metacatRequestContext, this));
validate(name);
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final Optional<TableDto> oTable = get(name, true);
if (oTable.isPresent()) {
log.info("Drop table {}", name);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
service.delete(connectorContext, name);
}
final TableDto tableDto = oTable.orElseGet(() -> {
// If the table doesn't exist construct a blank copy we can use to delete the definitionMetadata and tags
final TableDto t = new TableDto();
t.setName(name);
return t;
});
// Delete the metadata. Type doesn't matter since we discard the result
log.info("Deleting user metadata for table {}", name);
userMetadataService.deleteMetadatas(metacatRequestContext.getUserName(), Lists.newArrayList(tableDto));
log.info("Deleting tags for table {}", name);
tagService.delete(name, false);
eventBus.postAsync(new MetacatDeleteTablePostEvent(name, metacatRequestContext, this, tableDto));
return tableDto;
}
use of com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent in project metacat by Netflix.
the class ElasticSearchMetacatRefresh method deleteUnmarkedEntities.
private void deleteUnmarkedEntities(final List<QualifiedName> qNames, final List<QualifiedName> excludeQualifiedNames) {
log.info("Start: Delete unmarked entities");
//
// get unmarked qualified names
// check if it not exists
// delete
//
elasticSearchUtil.refresh();
final MetacatRequestContext context = new MetacatRequestContext("admin", "metacat-refresh", null, null, null);
final List<DatabaseDto> unmarkedDatabaseDtos = elasticSearchUtil.getQualifiedNamesByMarkerByNames("database", qNames, refreshMarker, excludeQualifiedNames, DatabaseDto.class);
if (!unmarkedDatabaseDtos.isEmpty()) {
if (unmarkedDatabaseDtos.size() <= config.getElasticSearchThresholdUnmarkedDatabasesDelete()) {
log.info("Start: Delete unmarked databases({})", unmarkedDatabaseDtos.size());
final List<String> unmarkedDatabaseNames = Lists.newArrayList();
final List<DatabaseDto> deleteDatabaseDtos = unmarkedDatabaseDtos.stream().filter(databaseDto -> {
boolean result = false;
try {
unmarkedDatabaseNames.add(databaseDto.getName().toString());
final DatabaseDto dto = databaseService.get(databaseDto.getName(), false);
if (dto == null) {
result = true;
}
} catch (DatabaseNotFoundException ignored) {
result = true;
} catch (Exception ignored) {
}
return result;
}).collect(Collectors.toList());
log.info("Unmarked databases({}): {}", unmarkedDatabaseNames.size(), unmarkedDatabaseNames);
log.info("Deleting databases({})", deleteDatabaseDtos.size());
if (!deleteDatabaseDtos.isEmpty()) {
final List<QualifiedName> deleteDatabaseQualifiedNames = deleteDatabaseDtos.stream().map(DatabaseDto::getName).collect(Collectors.toList());
final List<String> deleteDatabaseNames = deleteDatabaseQualifiedNames.stream().map(QualifiedName::toString).collect(Collectors.toList());
log.info("Deleting databases({}): {}", deleteDatabaseNames.size(), deleteDatabaseNames);
userMetadataService.deleteDefinitionMetadatas(deleteDatabaseQualifiedNames);
elasticSearchUtil.softDelete("database", deleteDatabaseNames, context);
}
log.info("End: Delete unmarked databases({})", unmarkedDatabaseDtos.size());
} else {
log.info("Count of unmarked databases({}) is more than the threshold {}", unmarkedDatabaseDtos.size(), config.getElasticSearchThresholdUnmarkedDatabasesDelete());
registry.counter(registry.createId(Metrics.CounterElasticSearchUnmarkedDatabaseThreshholdReached.name())).increment();
}
}
final List<TableDto> unmarkedTableDtos = elasticSearchUtil.getQualifiedNamesByMarkerByNames("table", qNames, refreshMarker, excludeQualifiedNames, TableDto.class);
if (!unmarkedTableDtos.isEmpty()) {
if (unmarkedTableDtos.size() <= config.getElasticSearchThresholdUnmarkedTablesDelete()) {
log.info("Start: Delete unmarked tables({})", unmarkedTableDtos.size());
final List<String> unmarkedTableNames = Lists.newArrayList();
final List<TableDto> deleteTableDtos = unmarkedTableDtos.stream().filter(tableDto -> {
boolean result = false;
try {
unmarkedTableNames.add(tableDto.getName().toString());
final Optional<TableDto> dto = tableService.get(tableDto.getName(), false);
if (!dto.isPresent()) {
result = true;
}
} catch (Exception ignored) {
}
return result;
}).collect(Collectors.toList());
log.info("Unmarked tables({}): {}", unmarkedTableNames.size(), unmarkedTableNames);
log.info("Deleting tables({}): {}", deleteTableDtos.size());
if (!deleteTableDtos.isEmpty()) {
final List<String> deleteTableNames = deleteTableDtos.stream().map(dto -> dto.getName().toString()).collect(Collectors.toList());
log.info("Deleting tables({}): {}", deleteTableNames.size(), deleteTableNames);
userMetadataService.deleteMetadatas("admin", Lists.newArrayList(deleteTableDtos));
// Publish event. Elasticsearch event handler will take care of updating the index already
// TODO: Re-evaluate events vs. direct calls for these types of situations like in Genie
deleteTableDtos.forEach(tableDto -> {
tagService.delete(tableDto.getName(), false);
this.eventBus.postAsync(new MetacatDeleteTablePostEvent(tableDto.getName(), context, this, tableDto));
});
}
log.info("End: Delete unmarked tables({})", unmarkedTableDtos.size());
} else {
log.info("Count of unmarked tables({}) is more than the threshold {}", unmarkedTableDtos.size(), config.getElasticSearchThresholdUnmarkedTablesDelete());
registry.counter(registry.createId(Metrics.CounterElasticSearchUnmarkedTableThreshholdReached.name())).increment();
}
}
log.info("End: Delete unmarked entities");
}
Aggregations