Search in sources :

Example 1 with HbaseSchemaCommandManager

use of com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager 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);
}
Also used : HbaseSchemaCommandManager(com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager) ChangeSetManager(com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)

Example 2 with HbaseSchemaCommandManager

use of com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager in project pinpoint by naver.

the class HbaseSchemaServiceImpl method initFromExistingTables.

private boolean initFromExistingTables(String namespace, String compression, List<ChangeSet> changeSets, List<HTableDescriptor> currentHtds) {
    logger.info("[{}] Initializing hbase schema from existing tables.", namespace);
    // Replay change sets one by one and compare it against the current hbase schema.
    // If they match, all change sets up to that point are seen as already applied.
    HbaseSchemaCommandManager initCommandManager = new HbaseSchemaCommandManager(namespace, compression);
    List<ChangeSet> appliedChangeSets = new ArrayList<>();
    List<ChangeSet> changeSetsToApply = new ArrayList<>();
    for (ChangeSet changeSet : changeSets) {
        initCommandManager.applyChangeSet(changeSet);
        changeSetsToApply.add(changeSet);
        if (hbaseSchemaVerifier.verifySchemas(initCommandManager.getSchemaSnapshot(), currentHtds)) {
            appliedChangeSets.addAll(changeSetsToApply);
            changeSetsToApply = new ArrayList<>();
        }
    }
    if (appliedChangeSets.isEmpty()) {
        logger.info("[{}] Current table schema does not match any schema from the change sets.", namespace);
    } else {
        List<String> appliedChangeSetIds = appliedChangeSets.stream().map(ChangeSet::getId).collect(Collectors.toList());
        logger.info("[{}] Change sets already applied : {}", namespace, appliedChangeSetIds);
    }
    List<SchemaChangeLog> executedLogs = schemaChangeLogService.recordChangeSets(namespace, appliedChangeSets);
    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);
}
Also used : HbaseSchemaCommandManager(com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager) ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Example 3 with HbaseSchemaCommandManager

use of com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager in project pinpoint by naver.

the class HbaseSchemaServiceImpl method init.

private boolean init(String namespace, String compression, List<ChangeSet> changeSets) {
    logger.info("[{}] Initializing hbase schema.", namespace);
    HbaseSchemaCommandManager commandManager = new HbaseSchemaCommandManager(namespace, compression);
    return applyChangeSets(commandManager, changeSets, Collections.emptyList());
}
Also used : HbaseSchemaCommandManager(com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)

Aggregations

HbaseSchemaCommandManager (com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)3 ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)2 ChangeSetManager (com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager)1 SchemaChangeLog (com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)1 ArrayList (java.util.ArrayList)1