Skip to content

Commit

Permalink
Fix bug of activating template (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuheng55555 authored Jan 5, 2024
1 parent befaa91 commit dc00324
Showing 1 changed file with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,28 +304,37 @@ private void registerStorageGroups(Session metaSession, List<TimeseriesSchema> s
}

private void activateTemplate(Session metaSession, List<TimeseriesSchema> schemaList) {
List<String> partialDevicePaths = new ArrayList<>();
List<String> someDevicePaths = new ArrayList<>();
AtomicLong activatedDeviceCount = new AtomicLong();
schemaList.stream()
.map(schema -> ROOT_SERIES_NAME + "." + schema.getDeviceSchema().getDevicePath())
.forEach(
path -> {
partialDevicePaths.add(path);
if (partialDevicePaths.size() >= ACTIVATE_TEMPLATE_THRESHOLD) {
try {
metaSession.createTimeseriesUsingSchemaTemplate(partialDevicePaths);
} catch (Exception e) {
LOGGER.error(
"Activate {}~{} devices' schema template fail",
activatedDeviceCount.get(),
activatedDeviceCount.get() + partialDevicePaths.size(),
e);
System.exit(1);
}
activatedDeviceCount.addAndGet(partialDevicePaths.size());
partialDevicePaths.clear();
someDevicePaths.add(path);
if (someDevicePaths.size() >= ACTIVATE_TEMPLATE_THRESHOLD) {
activateTemplateForSomeDevices(
metaSession, someDevicePaths, activatedDeviceCount.get());
activatedDeviceCount.addAndGet(someDevicePaths.size());
someDevicePaths.clear();
}
});
if (!someDevicePaths.isEmpty()) {
activateTemplateForSomeDevices(metaSession, someDevicePaths, activatedDeviceCount.get());
}
}

private void activateTemplateForSomeDevices(
Session metaSession, List<String> partialDevicePaths, long startIndex) {
try {
metaSession.createTimeseriesUsingSchemaTemplate(partialDevicePaths);
} catch (Exception e) {
LOGGER.error(
"Activate {}~{} devices' schema template fail",
startIndex,
startIndex + partialDevicePaths.size(),
e);
System.exit(1);
}
}

private TimeseriesSchema createTimeseries(DeviceSchema deviceSchema) {
Expand Down

0 comments on commit dc00324

Please sign in to comment.