AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.
Describe the bug
MysqlSession.save(SessionKey sessionKey, String key, List<? extends State> values) has inconsistent transaction behavior between the "full rewrite" branch and the "incremental append" branch.
full rewrite controls transaction commit manually:
|
if (needsFullRewrite) { |
|
// Transaction: delete all + insert all |
|
conn.setAutoCommit(false); |
|
try { |
|
deleteListItems(conn, sessionId, key); |
|
insertAllItems(conn, sessionId, key, values); |
|
saveHash(conn, sessionId, hashKey, currentHash); |
|
conn.commit(); |
|
} catch (Exception e) { |
|
conn.rollback(); |
|
throw e; |
|
} finally { |
|
conn.setAutoCommit(true); |
|
} |
|
} else if (values.size() > existingCount) { |
|
// Incremental append |
|
List<? extends State> newItems = values.subList(existingCount, values.size()); |
|
insertItems(conn, sessionId, key, newItems, existingCount); |
|
saveHash(conn, sessionId, hashKey, currentHash); |
whereas insert new items does not commit explicitly
|
private void insertItems( |
|
Connection conn, |
|
String sessionId, |
|
String key, |
|
List<? extends State> items, |
|
int startIndex) |
|
throws Exception { |
|
String insertSql = |
|
"INSERT INTO " |
|
+ getFullTableName() |
|
+ " (session_id, state_key, item_index, state_data)" |
|
+ " VALUES (?, ?, ?, ?)"; |
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(insertSql)) { |
|
int index = startIndex; |
|
for (State item : items) { |
|
String json = JsonUtils.getJsonCodec().toJson(item); |
|
stmt.setString(1, sessionId); |
|
stmt.setString(2, key); |
|
stmt.setInt(3, index); |
|
stmt.setString(4, json); |
|
stmt.addBatch(); |
|
index++; |
|
} |
|
stmt.executeBatch(); |
|
} |
|
} |
The use of transaction and auto-commit should be more consistent. And needsFullRewrite path changes the auto-commit behavior of the connection it gets.
To Reproduce
Steps to reproduce the behavior:
- Set auto-commit to false
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
hikari:
auto-commit: false
-
Save a new session
MysqlSession saveSession = new MysqlSession()
agent.saveTo(saveSession, sessionId);
-
No new record is inserted
Environment (please complete the following information):
- AgentScope-Java Version: 1.0.10
- Java Version:17
- OS: windows
AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.
Describe the bug
MysqlSession.save(SessionKey sessionKey, String key, List<? extends State> values)has inconsistent transaction behavior between the "full rewrite" branch and the "incremental append" branch.full rewrite controls transaction commit manually:
agentscope-java/agentscope-extensions/agentscope-extensions-session-mysql/src/main/java/io/agentscope/core/session/mysql/MysqlSession.java
Lines 361 to 379 in 0f48e3f
whereas insert new items does not commit explicitly
agentscope-java/agentscope-extensions/agentscope-extensions-session-mysql/src/main/java/io/agentscope/core/session/mysql/MysqlSession.java
Lines 485 to 511 in 0f48e3f
The use of transaction and auto-commit should be more consistent. And
needsFullRewritepath changes the auto-commit behavior of the connection it gets.To Reproduce
Steps to reproduce the behavior:
Save a new session
MysqlSession saveSession = new MysqlSession()
agent.saveTo(saveSession, sessionId);
No new record is inserted
Environment (please complete the following information):