Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate schema template in batches. #386

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

/** this class will create more than one connection. */
public class IoTDB implements IDatabase {

private static final Logger LOGGER = LoggerFactory.getLogger(IoTDB.class);
private static final String ALREADY_KEYWORD = "already";
private static final AtomicBoolean templateInit = new AtomicBoolean(false);
private static final int ACTIVATE_TEMPLATE_THRESHOLD = 1000;
protected final String DELETE_SERIES_SQL;
protected SingleNodeJDBCConnection ioTDBConnection;

Expand Down Expand Up @@ -303,15 +303,28 @@ private void registerStorageGroups(Session metaSession, List<TimeseriesSchema> s
}

private void activateTemplate(Session metaSession, List<TimeseriesSchema> schemaList) {
try {
List<String> devicePaths =
schemaList.stream()
.map(schema -> ROOT_SERIES_NAME + "." + schema.getDeviceSchema().getDevicePath())
.collect(Collectors.toList());
metaSession.createTimeseriesUsingSchemaTemplate(devicePaths);
} catch (Throwable t) {
t.printStackTrace();
}
List<String> partialDevicePaths = 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();
}
});
}

private TimeseriesSchema createTimeseries(DeviceSchema deviceSchema) {
Expand Down
Loading