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));
}
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);
}
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());
}
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()));
}
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));
}
Aggregations