use of com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager in project pinpoint by naver.
the class HbaseSchemaServiceImpl method updateExistingSchemas.
private boolean updateExistingSchemas(String namespace, String compression, List<ChangeSet> changeSets, List<HTableDescriptor> currentHtds, List<SchemaChangeLog> executedLogs) {
logger.info("[{}] Updating hbase schema.", namespace);
List<String> executedChangeLogIds = executedLogs.stream().map(SchemaChangeLog::getId).collect(Collectors.toList());
logger.info("[{}] Executed change logs : {}", namespace, executedChangeLogIds);
ChangeSetManager changeSetManager = new ChangeSetManager(changeSets);
// Check if the current table schema matches the expected schema specified by the executed schema change logs.
HbaseSchemaCommandManager initCommandManager = new HbaseSchemaCommandManager(namespace, compression);
List<ChangeSet> executedChangeSets = changeSetManager.getExecutedChangeSets(executedLogs);
for (ChangeSet executedChangeSet : executedChangeSets) {
initCommandManager.applyChangeSet(executedChangeSet);
}
if (!hbaseSchemaVerifier.verifySchemas(initCommandManager.getSchemaSnapshot(), currentHtds)) {
throw new IllegalStateException("Current table schema does not match the schema change log records.");
}
List<ChangeSet> changeSetsToApply = changeSetManager.filterExecutedChangeSets(executedLogs);
if (changeSetsToApply.isEmpty()) {
logger.info("[{}] Hbase schema already at latest version", namespace);
return false;
}
HbaseSchemaCommandManager updateCommandManager = new HbaseSchemaCommandManager(namespace, compression, currentHtds);
return applyChangeSets(updateCommandManager, changeSetsToApply, executedLogs);
}
use of com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager in project pinpoint by naver.
the class HbaseSchemaServiceImpl method getSchemaStatus.
/**
* This implementation uses the executed schema change logs to compare against the specified {@code changeSets} to
* check the current schema status, regardless of how the actual schema looks like.
*/
// TODO May be a good idea to compare the actual tables against each of the change sets in the future.
@Override
public HbaseSchemaStatus getSchemaStatus(String namespace, List<ChangeSet> changeSets) {
if (CollectionUtils.isEmpty(changeSets)) {
throw new IllegalArgumentException("changeSets must not be empty");
}
if (!schemaChangeLogService.isAvailable(namespace)) {
return HbaseSchemaStatus.NONE;
}
List<SchemaChangeLog> schemaChangeLogs = schemaChangeLogService.getSchemaChangeLogs(namespace);
if (CollectionUtils.isEmpty(schemaChangeLogs)) {
return HbaseSchemaStatus.NONE;
}
List<ChangeSet> unexecutedChangeSets;
ChangeSetManager changeSetManager = new ChangeSetManager(changeSets);
try {
unexecutedChangeSets = changeSetManager.filterExecutedChangeSets(schemaChangeLogs);
} catch (IllegalArgumentException e) {
logger.error("[{}] Invalid hbase schema, cause : {}", namespace, e.getMessage());
return HbaseSchemaStatus.INVALID;
}
if (CollectionUtils.isEmpty(unexecutedChangeSets)) {
return HbaseSchemaStatus.VALID;
}
return HbaseSchemaStatus.VALID_OUT_OF_DATE;
}
Aggregations