From dc003247ec5fcbc9de5ba96c54de276b20b28304 Mon Sep 17 00:00:00 2001 From: Li Yu Heng Date: Fri, 5 Jan 2024 11:28:12 +0800 Subject: [PATCH] Fix bug of activating template (#391) --- .../iot/benchmark/iotdb110/IoTDB.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java b/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java index 42f121ce5..7a8096c54 100644 --- a/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java +++ b/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java @@ -304,28 +304,37 @@ private void registerStorageGroups(Session metaSession, List s } private void activateTemplate(Session metaSession, List schemaList) { - List partialDevicePaths = new ArrayList<>(); + List 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 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) {