private void writeFile(final TransactionRecover transaction) { makeDir(); String file = getFullFileName(transaction.getId()); RandomAccessFile raf; try { raf = new RandomAccessFile(file, "rw"); try (FileChannel channel = raf.getChannel()) { byte[] content = TransactionRecoverUtils.convert(transaction, serializer); ByteBuffer buffer = ByteBuffer.allocate(content.length); buffer.put(content); buffer.flip(); while (buffer.hasRemaining()) { channel.write(buffer); } channel.force(true); } } catch (Exception e) { e.printStackTrace(); } }
@Override public int create(final TransactionRecover transactionRecover) { try { zooKeeper.create(getRootPath(transactionRecover.getId()), TransactionRecoverUtils.convert(transactionRecover, objectSerializer), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); return ROWS; } catch (Exception e) { throw new TransactionIoException(e); } }
@Override public int create(final TransactionRecover transactionRecover) { try { final String redisKey = RedisHelper.buildRecoverKey(keyName, transactionRecover.getId()); jedisClient.set(redisKey, TransactionRecoverUtils.convert(transactionRecover, objectSerializer)); return ROWS; } catch (Exception e) { throw new TransactionIoException(e); } }
@Override public int update(final TransactionRecover transactionRecover) throws TransactionRuntimeException { try { final String redisKey = RedisHelper.buildRecoverKey(keyName, transactionRecover.getId()); if (CompensationOperationTypeEnum.TASK_EXECUTE.getCode() == transactionRecover.getOperation()) { TransactionRecover recover = findById(transactionRecover.getId()); recover.setCompleteFlag(CommonConstant.TX_TRANSACTION_COMPLETE_FLAG_OK); jedisClient.set(redisKey, TransactionRecoverUtils.convert(recover, objectSerializer)); return ROWS; } transactionRecover.setVersion(transactionRecover.getVersion() + 1); transactionRecover.setLastTime(new Date()); transactionRecover.setRetriedCount(transactionRecover.getRetriedCount() + 1); jedisClient.set(redisKey, TransactionRecoverUtils.convert(transactionRecover, objectSerializer)); return ROWS; } catch (Exception e) { throw new TransactionRuntimeException(e); } }
@Override public int update(final TransactionRecover transactionRecover) throws TransactionRuntimeException { try { if (CompensationOperationTypeEnum.TASK_EXECUTE.getCode() == transactionRecover.getOperation()) { TransactionRecover recover = findById(transactionRecover.getId()); recover.setCompleteFlag(CommonConstant.TX_TRANSACTION_COMPLETE_FLAG_OK); zooKeeper.setData(getRootPath(recover.getId()), TransactionRecoverUtils.convert(recover, objectSerializer), recover.getVersion() - 2); return ROWS; } transactionRecover.setLastTime(new Date()); transactionRecover.setVersion(transactionRecover.getVersion() + 1); transactionRecover.setRetriedCount(transactionRecover.getRetriedCount() + 1); zooKeeper.setData(getRootPath(transactionRecover.getId()), TransactionRecoverUtils.convert(transactionRecover, objectSerializer), transactionRecover.getVersion() - 2); return ROWS; } catch (Exception e) { throw new TransactionIoException(e); } }