Search in sources :

Example 26 with SchemaChangeLog

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

Example 27 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class SchemaChangeLogServiceImpl method recordChangeSet.

private SchemaChangeLog recordChangeSet(String namespace, long executionTimestamp, int executionOrder, ChangeSet changeSet) {
    CheckSum checkSum = CheckSum.compute(CheckSum.getCurrentVersion(), changeSet.getValue());
    SchemaChangeLog schemaChangeLog = new SchemaChangeLog.Builder().id(changeSet.getId()).execTimestamp(executionTimestamp).execOrder(executionOrder).checkSum(checkSum).value(changeSet.getValue()).build();
    schemaChangeLogDao.insertChangeLog(namespace, schemaChangeLog);
    return schemaChangeLog;
}
Also used : CheckSum(com.navercorp.pinpoint.hbase.schema.core.CheckSum) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Example 28 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class SchemaChangeLogServiceImpl method recordChangeSets.

@Override
public List<SchemaChangeLog> recordChangeSets(String namespace, int executionOrder, List<ChangeSet> changeSets) {
    if (CollectionUtils.isEmpty(changeSets)) {
        return Collections.emptyList();
    }
    int startingOrder = executionOrder;
    long executionTimestamp = System.currentTimeMillis();
    List<SchemaChangeLog> schemaChangeLogs = new ArrayList<>();
    for (ChangeSet changeSet : changeSets) {
        SchemaChangeLog schemaChangeLog = recordChangeSet(namespace, executionTimestamp, startingOrder, changeSet);
        schemaChangeLogs.add(schemaChangeLog);
        startingOrder++;
    }
    return schemaChangeLogs;
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Example 29 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog in project pinpoint by naver.

the class PrintSchemaChangeLogTask method run.

@Override
public void run(List<String> arguments) {
    if (CollectionUtils.isEmpty(arguments)) {
        List<SchemaChangeLog> schemaChangeLogs = hbaseSchemaService.getChangeLogs(namespace);
        if (CollectionUtils.isEmpty(schemaChangeLogs)) {
            logger.info("No schema change logs found.");
        } else {
            for (SchemaChangeLog schemaChangeLog : schemaChangeLogs) {
                printDetailedSchemaChangeLog(schemaChangeLog);
            }
        }
    } else {
        String changeSetId = arguments.get(0);
        SchemaChangeLog schemaChangeLog = hbaseSchemaService.getChangeLog(namespace, changeSetId);
        if (schemaChangeLog == null) {
            logger.info("No schema change log found with id : {}", changeSetId);
        } else {
            printDetailedSchemaChangeLog(schemaChangeLog);
        }
    }
}
Also used : SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Aggregations

SchemaChangeLog (com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)29 ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 HbaseSchemaStatus (com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus)3 ChangeSetManager (com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager)1 CheckSum (com.navercorp.pinpoint.hbase.schema.core.CheckSum)1 HbaseSchemaCommandManager (com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1