【 使用环境 】 测试环境
【 OB or 其他组件 】 OB
【 使用版本 】 5.7.25-OceanBase_CE-v4.3.4.0
【问题描述】OceanBase写数据提交事务后同一会话不能马上查出数据 。但是如果是 select for update 的写法就可以查到数据。是否和设置了3分副本有关?
【复现路径】
【附件及日志】 附代码如下
建表语句:
CREATE TABLE t3
(
c1
varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT ’ ',
c2
varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT ’ ',
c3
varchar(64) COLLATE utf8mb4_bin DEFAULT NULL COMMENT ’ ',
create_time
datetime DEFAULT CURRENT_TIMESTAMP COMMENT ‘创建时间’,
update_time
datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘修改时间’
) DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = DYNAMIC COMPRESSION = ‘zstd_1.3.8’ REPLICA_NUM = 3 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0;
public static void testBatchPreparedStatement() throws Exception {
Statement st = con.createStatement();
st.execute(“truncate t3;”);
st.close();
PreparedStatement pst = con.prepareStatement("insert into t3(c1,c2) values(?,?)");
Long beginTime1 = System.currentTimeMillis();
con.setAutoCommit(false);
System.out.println("insert in testBatchPreparedStatement: ");
for (int i = 0; i < insTimes; i++) {
pst.setString(1, "testRecord" + i);
pst.setInt(2, i);
pst.addBatch();
if ((i + 1) % (batNum) == 0) {
pst.executeBatch();
con.commit();
System.out.println((System.currentTimeMillis() - beginTime1) + " ms");
beginTime1 = System.currentTimeMillis();
}
}
pst.close();
}
public static List<Map<String, Object>> testQuery(String sql) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
Statement st = con.createStatement();
Long beginTime1 = System.currentTimeMillis();
String key = null;
Object value = null;
ResultSet rs=st.executeQuery(sql);
if(rs!=null) {
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
Map<String, Object> hm = new HashMap< String, Object >();
for (int j1 = 1; j1 <= rsmd.getColumnCount(); j1++) {
key = rsmd.getColumnLabel(j1);
value = rs.getObject(j1);
//
// if (hm.containsKey(key)) {
// throw new RuntimeException(“字段名重复:” + key);
// }
hm.put(key, value);
}
list.add(hm);
}
}
Long endTime1 = System.currentTimeMillis();
System.out.println((endTime1 - beginTime1) + " ms");
st.close();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public static void main(String arg[]){
System.out.println("begin test");
try {
testConnDb();
testBatchPreparedStatement();
List<Map<String, Object>> maps = testQuery("select count(1) cc from t3 ");
// List<Map<String, Object>> maps = testQuery(“select count(1) cc from t3 for update”);
Long cc = (Long) maps.get(0).get(“cc”);
System.out.println(cc);
} catch(Exception e) {
e.printStackTrace();
} finally{
JdbcUtils.closeConnection(con);
}
System.out.println(“end test”);
}