Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbxyyx committed Jul 11, 2024
1 parent 542697c commit e24facf
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.seata.server;

import org.apache.seata.common.util.IdWorker;
package org.apache.seata.common.util;

/**
* The type Uuid generator.
*
*/
public class UUIDGenerator {

private static volatile IdWorker idWorker;

/**
* generate UUID using snowflake algorithm
*
* @return UUID
*/
public static long generateUUID() {
Expand All @@ -43,6 +41,7 @@ public static long generateUUID() {

/**
* init IdWorker
*
* @param serverNode the server node id, consider as machine id in snowflake
*/
public static void init(Long serverNode) {
Expand Down
17 changes: 17 additions & 0 deletions common/src/test/resources/io/TestFile.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
====
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
====

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -514,6 +515,11 @@ protected byte[] getRollbackInfo(ResultSet rs) throws SQLException {
return CompressorFactory.getCompressor(compressorType.getCode()).decompress(rollbackInfo);
}

@Override
public int deleteUndoLogByLogCreated(Date logCreated, int limitRows, Connection conn) throws SQLException {
return 0;
}

/**
* get sub rollback info
* @param conn the database connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.apache.seata.common.loader.LoadLevel;
import org.apache.seata.common.util.CollectionUtils;
import org.apache.seata.common.util.IOUtil;
import org.apache.seata.common.util.IdWorker;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.core.compressor.CompressorType;
import org.apache.seata.core.constants.ClientTableColumnsName;
import org.apache.seata.core.rpc.processor.Pair;
Expand Down Expand Up @@ -62,8 +62,6 @@ public class MySQLUndoLogManager extends AbstractUndoLogManager {
private static final String DELETE_UNDO_LOG_BY_CREATE_SQL = "DELETE FROM " + UNDO_LOG_TABLE_NAME +
" WHERE " + ClientTableColumnsName.UNDO_LOG_LOG_CREATED + " <= ? LIMIT ?";

private static final IdWorker ID_WORKER = new IdWorker(null);

@Override
public int deleteUndoLogByLogCreated(Date logCreated, int limitRows, Connection conn) throws SQLException {
try (PreparedStatement deletePST = conn.prepareStatement(DELETE_UNDO_LOG_BY_CREATE_SQL)) {
Expand Down Expand Up @@ -153,7 +151,7 @@ protected void insertUndoLogWithNormal(String xid, long branchId, String rollbac
} else {
byte[] bytes = new byte[Math.min(undoLogContent.length - pos, limit)];
System.arraycopy(undoLogContent, pos, bytes, 0, bytes.length);
long subId = ID_WORKER.nextId();
long subId = UUIDGenerator.generateUUID();
subIdBuilder.append(subId).append(UndoLogConstants.SUB_SPLIT_KEY);
insertUndoLog(xid, subId, subRollbackCtx, bytes, State.Normal, conn);
pos += bytes.length;
Expand Down
1 change: 1 addition & 0 deletions server/src/main/java/org/apache/seata/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.NetUtil;
import org.apache.seata.common.util.StringUtils;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.config.ConfigurationFactory;
import org.apache.seata.core.rpc.netty.NettyRemotingServer;
import org.apache.seata.core.rpc.netty.NettyServerConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.apache.seata.core.model.BranchType;
import org.apache.seata.core.model.GlobalStatus;
import org.apache.seata.core.model.LockStatus;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.cluster.raft.RaftServerManager;
import org.apache.seata.server.lock.LockerManagerFactory;
import org.apache.seata.server.store.SessionStorable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.seata.core.model.BranchType;
import org.apache.seata.core.model.GlobalStatus;
import org.apache.seata.metrics.IdConstants;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.cluster.raft.context.SeataClusterContext;
import org.apache.seata.server.coordinator.DefaultCoordinator;
import org.apache.seata.server.metrics.MetricsPublisher;
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/java/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.apache.seata.common.XID;
import org.apache.seata.common.util.NetUtil;
import org.apache.seata.core.rpc.netty.NettyRemotingServer;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.coordinator.DefaultCoordinator;

import java.util.concurrent.LinkedBlockingQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.seata.server;

import org.apache.seata.common.util.UUIDGenerator;
import org.junit.jupiter.api.Test;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.seata.common.result.PageResult;
import org.apache.seata.core.exception.TransactionException;
import org.apache.seata.core.model.BranchType;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.console.param.GlobalLockParam;
import org.apache.seata.server.console.service.GlobalLockService;
import org.apache.seata.server.console.vo.GlobalLockVO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.apache.seata.common.XID;
import org.apache.seata.core.model.BranchType;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.lock.LockManager;
import org.apache.seata.server.session.BranchSession;
import org.junit.jupiter.api.Assertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.stream.Stream;

import org.apache.seata.core.model.BranchType;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.seata.core.model.BranchStatus;
import org.apache.seata.core.model.BranchType;
import org.apache.seata.core.model.GlobalStatus;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.session.BranchSession;
import org.apache.seata.server.session.GlobalSession;
import org.apache.seata.server.session.SessionCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.seata.core.model.BranchStatus;
import org.apache.seata.core.model.BranchType;
import org.apache.seata.core.model.GlobalStatus;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.session.BranchSession;
import org.apache.seata.server.session.GlobalSession;
import org.apache.seata.server.session.SessionCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springframework.boot.test.context.SpringBootTest;

import org.apache.seata.common.util.BufferUtils;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.session.BranchSession;
import org.apache.seata.server.session.GlobalSession;
import org.apache.seata.server.session.SessionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.apache.seata.core.rpc.TransactionMessageHandler;
import org.apache.seata.mockserver.call.CallRm;
import org.apache.seata.server.AbstractTCInboundHandler;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.session.BranchSession;
import org.apache.seata.server.session.GlobalSession;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.seata.common.thread.NamedThreadFactory;
import org.apache.seata.common.util.NetUtil;
import org.apache.seata.server.ParameterParser;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.seata.rm.datasource.DataSourceProxy;
import org.apache.seata.rm.datasource.sql.struct.TableMetaCacheFactory;
import org.apache.seata.rm.datasource.sql.struct.TableRecords;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.sqlparser.struct.TableMeta;
import org.apache.seata.sqlparser.util.JdbcConstants;
import org.junit.jupiter.api.Assertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.seata.core.protocol.transaction.BranchRegisterResponse;
import org.apache.seata.mockserver.MockServer;
import org.apache.seata.saga.engine.db.AbstractServerTest;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.coordinator.DefaultCoordinator;
import org.apache.seata.server.session.SessionHolder;
import org.junit.jupiter.api.AfterAll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.seata.core.rpc.netty.NettyRemotingServer;
import org.apache.seata.core.rpc.netty.NettyServerConfig;
import org.apache.seata.server.ParameterParser;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.server.coordinator.DefaultCoordinator;
import org.apache.seata.server.metrics.MetricsManager;
import org.apache.seata.server.session.SessionHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.seata.core.model.BranchStatus;
import org.apache.seata.core.model.GlobalStatus;
import org.apache.seata.saga.engine.tm.SagaTransactionalTemplate;
import org.apache.seata.server.UUIDGenerator;
import org.apache.seata.common.util.UUIDGenerator;
import org.apache.seata.tm.api.GlobalTransaction;
import org.apache.seata.tm.api.TransactionalExecutor.ExecutionException;
import org.apache.seata.tm.api.transaction.TransactionInfo;
Expand Down

0 comments on commit e24facf

Please sign in to comment.