use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaServiceImplTest method getSchemaStatus_noTables.
@Test
public void getSchemaStatus_noTables() {
final String namespace = "namespace";
final List<ChangeSet> changeSets = Arrays.asList(newChangeSet("id1", "value1"));
when(schemaChangeLogService.isAvailable(namespace)).thenReturn(false);
HbaseSchemaStatus schemaStatus = hbaseSchemaService.getSchemaStatus(namespace, changeSets);
MatcherAssert.assertThat(schemaStatus, is(HbaseSchemaStatus.NONE));
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet 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.reader.core.ChangeSet 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.reader.core.ChangeSet 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.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaServiceImpl method applyChangeSets.
private boolean applyChangeSets(HbaseSchemaCommandManager commandManager, List<ChangeSet> changeSets, List<SchemaChangeLog> executedLogs) {
if (CollectionUtils.isEmpty(changeSets)) {
return false;
}
String namespace = commandManager.getNamespace();
List<String> changeSetIds = changeSets.stream().map(ChangeSet::getId).collect(Collectors.toList());
logger.info("[{}] Applying change sets : {}", namespace, changeSetIds);
for (ChangeSet changeSet : changeSets) {
commandManager.applyChangeSet(changeSet);
}
List<TableCommand> commands = commandManager.getCommands();
boolean changesMade = commands.stream().map(command -> command.execute(hbaseAdminOperation)).reduce(Boolean::logicalOr).orElse(Boolean.FALSE);
schemaChangeLogService.recordChangeSets(namespace, executedLogs.size() + 1, changeSets);
return changesMade;
}
Aggregations