Search in sources :

Example 1 with SchemaChangeLog

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

the class HbaseSchemaServiceImplTest method getSchemaStatus_validButNeedUpdateSchemaChangeLogs.

@Test
public void getSchemaStatus_validButNeedUpdateSchemaChangeLogs() {
    final String namespace = "namespace";
    final List<ChangeSet> changeSets = Arrays.asList(newChangeSet("id1", "value1"), newChangeSet("id2", "value2"), newChangeSet("id3", "value3"));
    final List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value1", 1), newSchemaChangeLog("id2", "value2", 2));
    when(schemaChangeLogService.isAvailable(namespace)).thenReturn(true);
    when(schemaChangeLogService.getSchemaChangeLogs(namespace)).thenReturn(schemaChangeLogs);
    HbaseSchemaStatus schemaStatus = hbaseSchemaService.getSchemaStatus(namespace, changeSets);
    MatcherAssert.assertThat(schemaStatus, is(HbaseSchemaStatus.VALID_OUT_OF_DATE));
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HbaseSchemaStatus(com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 2 with SchemaChangeLog

use of com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog 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 SchemaChangeLog

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

the class SchemaChangeLogServiceImpl method getSchemaChangeLogs.

@Override
public List<SchemaChangeLog> getSchemaChangeLogs(String namespace) {
    List<SchemaChangeLog> schemaChangeLogs = schemaChangeLogDao.getChangeLogs(namespace);
    Map<Integer, SchemaChangeLog> orderedSchemaChangeLogs = new TreeMap<>();
    Set<String> schemaChangeLogIds = new HashSet<>();
    for (SchemaChangeLog schemaChangeLog : schemaChangeLogs) {
        Integer execOrder = schemaChangeLog.getExecOrder();
        String id = schemaChangeLog.getId();
        SchemaChangeLog previousLog = orderedSchemaChangeLogs.put(execOrder, schemaChangeLog);
        if (previousLog != null) {
            throw new IllegalStateException("Corrupted schema change logs. Duplicate order for change set : " + id);
        }
        if (!schemaChangeLogIds.add(schemaChangeLog.getId())) {
            throw new IllegalStateException("Corrupted schema change logs. Duplicate change set : " + id);
        }
    }
    return new ArrayList<>(orderedSchemaChangeLogs.values());
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) HashSet(java.util.HashSet)

Example 4 with SchemaChangeLog

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

the class SchemaChangeLogCodecTest method writeAndRead.

@Test
public void writeAndRead() {
    final String value = UUID.randomUUID().toString();
    SchemaChangeLog schemaChangeLog = new SchemaChangeLog.Builder().id("testId").execTimestamp(System.currentTimeMillis()).execOrder(random.nextInt()).checkSum(CheckSum.compute(CheckSum.getCurrentVersion(), value)).value(UUID.randomUUID().toString()).build();
    byte[] serialized = schemaChangeLogCodec.writeData(schemaChangeLog);
    SchemaChangeLog deserialized = schemaChangeLogCodec.readData(serialized);
    assertThat(deserialized.getId(), is(schemaChangeLog.getId()));
    assertThat(deserialized.getExecTimestamp(), is(schemaChangeLog.getExecTimestamp()));
    assertThat(deserialized.getExecOrder(), is(schemaChangeLog.getExecOrder()));
    assertThat(deserialized.getCheckSum(), is(schemaChangeLog.getCheckSum()));
    assertThat(deserialized.getValue(), is(schemaChangeLog.getValue()));
}
Also used : SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 5 with SchemaChangeLog

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

the class ChangeSetManagerTest method getExecutedChangeSets.

@Test
public void getExecutedChangeSets() {
    ChangeSet changeSet1 = newChangeSet("id1", "value1");
    ChangeSet changeSet2 = newChangeSet("id2", "value2");
    ChangeSet changeSet3 = newChangeSet("id3", "value3");
    ChangeSet changeSet4 = newChangeSet("id4", "value4");
    List<ChangeSet> changeSets = Arrays.asList(changeSet1, changeSet2, changeSet3, changeSet4);
    List<SchemaChangeLog> schemaChangeLogs = newSchemaChangeLogs(changeSet1, changeSet2);
    ChangeSetManager changeSetManager = new ChangeSetManager(changeSets);
    List<ChangeSet> executedChangeSets = changeSetManager.getExecutedChangeSets(schemaChangeLogs);
    assertThat(executedChangeSets, contains(changeSet1, changeSet2));
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

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