|
21 | 21 | import com.codingapi.txlcn.tm.cluster.TMProperties; |
22 | 22 | import com.codingapi.txlcn.tm.config.TxManagerConfig; |
23 | 23 | import com.codingapi.txlcn.tm.core.storage.FastStorage; |
24 | | -import com.codingapi.txlcn.tm.core.storage.GroupProps; |
25 | 24 | import com.codingapi.txlcn.tm.core.storage.LockValue; |
26 | 25 | import com.codingapi.txlcn.tm.core.storage.TransactionUnit; |
27 | 26 | import com.google.common.collect.Sets; |
@@ -71,21 +70,9 @@ public RedisStorage(RedisTemplate<String, Object> redisTemplate, StringRedisTemp |
71 | 70 | } |
72 | 71 |
|
73 | 72 | @Override |
74 | | - public void initGroup(GroupProps groupProps) { |
75 | | - redisTemplate.opsForHash().put(REDIS_GROUP_PREFIX + groupProps.getGroupId(), "root", groupProps); |
76 | | - redisTemplate.expire(REDIS_GROUP_PREFIX + groupProps.getGroupId(), |
77 | | - managerConfig.getDtxTime() + 10000, TimeUnit.MILLISECONDS); |
78 | | - } |
79 | | - |
80 | | - @Override |
81 | | - public GroupProps getGroupProps(String groupId) throws FastStorageException { |
82 | | - return (GroupProps) redisTemplate.opsForHash().get(REDIS_GROUP_PREFIX + groupId, "root"); |
83 | | - } |
84 | | - |
85 | | - @Override |
86 | | - public boolean containsTransactionUnit(String groupId, TransactionUnit transactionUnit) { |
87 | | - Object unit = redisTemplate.opsForHash().get(REDIS_GROUP_PREFIX + groupId, transactionUnit.getUnitId()); |
88 | | - return Objects.nonNull(unit); |
| 73 | + public void initGroup(String groupId) { |
| 74 | + redisTemplate.opsForHash().put(REDIS_GROUP_PREFIX + groupId, "root", ""); |
| 75 | + redisTemplate.expire(REDIS_GROUP_PREFIX + groupId, managerConfig.getDtxTime() + 10000, TimeUnit.MILLISECONDS); |
89 | 76 | } |
90 | 77 |
|
91 | 78 | @Override |
@@ -198,13 +185,13 @@ public void removeToken(String token) { |
198 | 185 | @Override |
199 | 186 | public void saveTMProperties(TMProperties tmProperties) { |
200 | 187 | Objects.requireNonNull(tmProperties); |
201 | | - redisTemplate.opsForHash().put(REDIS_TM_LIST, |
202 | | - tmProperties.getHost() + ":" + tmProperties.getTransactionPort(), tmProperties.getHttpPort()); |
| 188 | + stringRedisTemplate.opsForHash().put(REDIS_TM_LIST, |
| 189 | + tmProperties.getHost() + ":" + tmProperties.getTransactionPort(), String.valueOf(tmProperties.getHttpPort())); |
203 | 190 | } |
204 | 191 |
|
205 | 192 | @Override |
206 | 193 | public List<TMProperties> findTMProperties() { |
207 | | - return redisTemplate.opsForHash().entries(REDIS_TM_LIST).entrySet().stream() |
| 194 | + return stringRedisTemplate.opsForHash().entries(REDIS_TM_LIST).entrySet().stream() |
208 | 195 | .map(entry -> { |
209 | 196 | String[] args = ApplicationInformation.splitAddress(entry.getKey().toString()); |
210 | 197 | TMProperties tmProperties = new TMProperties(); |
@@ -251,12 +238,15 @@ public int acquireOrRefreshMachineId(int machineId, long machineMaxSize, long ti |
251 | 238 | int curId = Math.toIntExact( |
252 | 239 | Objects.requireNonNull( |
253 | 240 | stringRedisTemplate.opsForValue().increment(REDIS_MACHINE_ID_MAP_PREFIX + "cur_id", 1))); |
| 241 | + if (curId > machineMaxSize) { |
| 242 | + stringRedisTemplate.opsForValue().set(REDIS_MACHINE_ID_MAP_PREFIX + "cur_id", "0"); |
| 243 | + curId = 0; |
| 244 | + } |
254 | 245 | if (Optional |
255 | | - .ofNullable(stringRedisTemplate.hasKey(REDIS_MACHINE_ID_MAP_PREFIX + ((curId) &= machineMaxSize))) |
| 246 | + .ofNullable(stringRedisTemplate.hasKey(REDIS_MACHINE_ID_MAP_PREFIX + curId)) |
256 | 247 | .orElse(true)) { |
257 | 248 | continue; |
258 | 249 | } |
259 | | - stringRedisTemplate.opsForValue().set(REDIS_MACHINE_ID_MAP_PREFIX + "cur_id", String.valueOf(curId)); |
260 | 250 | stringRedisTemplate.opsForValue().set(REDIS_MACHINE_ID_MAP_PREFIX + curId, "", timeout, TimeUnit.MILLISECONDS); |
261 | 251 | return curId; |
262 | 252 | } |
|
0 commit comments