jt2594838 commented on code in PR #17069:
URL: https://github.com/apache/iotdb/pull/17069#discussion_r2726213678
##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java:
##########
@@ -149,23 +150,78 @@ public TsTableColumnSchema getColumnSchema(final String
columnName) {
}
/**
- * Execute a write operation with optimistic lock support. This method
handles the write flag and
- * version increment automatically.
+ * Execute a write operation with Copy-on-Write support. This method creates
new copies of the
+ * maps before modification to ensure thread-safe reads without locks.
*
- * @param writeOperation the write operation to execute
+ * @param writeOperation the write operation to execute on the new map copies
*/
- private void executeWrite(Runnable writeOperation) {
+ private void executeWrite(WriteOperation writeOperation) {
readWriteLock.writeLock().lock();
isNotWrite.set(false);
try {
- writeOperation.run();
+ // Copy-on-Write: create local copies first
+ Map<String, TsTableColumnSchema> newColumnSchemaMap = new
LinkedHashMap<>(columnSchemaMap);
+ Map<String, Integer> newTagColumnIndexMap = new
HashMap<>(tagColumnIndexMap);
+ Map<String, Integer> newIdColumnIndexMap = new
HashMap<>(idColumnIndexMap);
+
+ // Execute write operation on local copies
+ writeOperation.execute(newColumnSchemaMap, newTagColumnIndexMap,
newIdColumnIndexMap);
+
+ // After write completes, atomically update the class fields
+ columnSchemaMap = newColumnSchemaMap;
+ tagColumnIndexMap = newTagColumnIndexMap;
+ idColumnIndexMap = newIdColumnIndexMap;
Review Comment:
And, may only retain tagColumnIndexMap since `id` is a deprecated name
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]