Skip to content

Commit

Permalink
some modify
Browse files Browse the repository at this point in the history
  • Loading branch information
yu199195 committed Sep 23, 2020
1 parent 0d29c9a commit 4c44cbf
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class ZookeeperConfig extends AbstractConfig {

private String path;

private boolean update;

private String updateFileName;

@Override
public String prefix() {
return PrefixConstants.REMOTE_ZOOKEEPER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Optional;
import java.util.function.Supplier;

import org.dromara.hmily.common.utils.FileUtils;
import org.dromara.hmily.common.utils.StringUtils;
import org.dromara.hmily.config.api.Config;
import org.dromara.hmily.config.api.ConfigEnv;
Expand Down Expand Up @@ -110,6 +111,9 @@ private void zookeeperLoad(final Supplier<Context> context, final LoaderHandler<
if (Objects.isNull(client)) {
client = CuratorZookeeperClient.getInstance(config);
}
if (config.isUpdate()) {
client.persist(config.getPath(), FileUtils.readYAML(config.getUpdateFileName()));
}
InputStream result = client.pull(config.getPath());
String fileExtension = config.getFileExtension();
PropertyLoader propertyLoader = LOADERS.get(fileExtension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@

import java.util.Objects;
import org.dromara.hmily.common.exception.HmilyRuntimeException;
import org.dromara.hmily.common.hook.HmilyShutdownHook;
import org.dromara.hmily.common.utils.StringUtils;
import org.dromara.hmily.config.api.ConfigEnv;
import org.dromara.hmily.config.api.ConfigScan;
import org.dromara.hmily.config.api.entity.HmilyConfig;
import org.dromara.hmily.config.api.entity.HmilyMetricsConfig;
import org.dromara.hmily.config.api.entity.HmilyServer;
import org.dromara.hmily.config.loader.ConfigLoader;
import org.dromara.hmily.config.loader.ServerConfigLoader;
import org.dromara.hmily.config.loader.ConfigLoaderServer;
import org.dromara.hmily.core.disruptor.publisher.HmilyRepositoryEventPublisher;
import org.dromara.hmily.core.holder.SingletonHolder;
import org.dromara.hmily.common.hook.HmilyShutdownHook;
import org.dromara.hmily.core.logo.HmilyLogo;
import org.dromara.hmily.core.provide.ObjectProvide;
import org.dromara.hmily.core.provide.ReflectObject;
Expand Down Expand Up @@ -71,7 +69,7 @@ public static HmilyBootstrap getInstance() {
*/
public void start() {
try {
loadConfig();
ConfigLoaderServer.load();
HmilyConfig hmilyConfig = ConfigEnv.getInstance().getConfig(HmilyConfig.class);
check(hmilyConfig);
registerProvide();
Expand All @@ -91,24 +89,9 @@ private void registerProvide() {
}
}

private void loadConfig() {
ConfigScan.scan();
ServerConfigLoader loader = new ServerConfigLoader();
loader.load(ConfigLoader.Context::new, (context, config) -> {
if (config != null) {
if (StringUtils.isNoneBlank(config.getConfigMode())) {
String configMode = config.getConfigMode();
ConfigLoader<?> configLoader = ExtensionLoaderFactory.load(ConfigLoader.class, configMode);
LOGGER.info("Load the configuration【{}】information...", configMode);
configLoader.load(context, (contextAfter, configAfter) -> LOGGER.info("Configuration information: {}", configAfter));
}
}
});
}

private void initMetrics() {
HmilyMetricsConfig metricsConfig = ConfigEnv.getInstance().getConfig(HmilyMetricsConfig.class);
if (Objects.nonNull(metricsConfig)) {
if (Objects.nonNull(metricsConfig) && StringUtils.isNoneBlank(metricsConfig.getMetricsName())) {
MetricsInit metricsInit = ExtensionLoaderFactory.load(MetricsInit.class);
metricsInit.init(metricsConfig);
registerAutoCloseable(metricsInit);
Expand All @@ -133,7 +116,6 @@ private void loadHmilyRepository(final HmilyConfig hmilyConfig) {
hmilyRepository.setSerializer(hmilySerializer);
hmilyRepository.init(buildAppName(hmilyConfig));
HmilyRepositoryFacade.getInstance().setHmilyRepository(hmilyRepository);
HmilyRepositoryFacade.getInstance().setPhyDeleted(hmilyConfig.isPhyDeleted());
}

private String buildAppName(final HmilyConfig hmilyConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import java.util.List;
import lombok.Setter;
import org.dromara.hmily.common.enums.HmilyActionEnum;
import org.dromara.hmily.config.api.ConfigEnv;
import org.dromara.hmily.config.api.entity.HmilyConfig;
import org.dromara.hmily.repository.spi.HmilyRepository;
import org.dromara.hmily.repository.spi.entity.HmilyParticipant;
import org.dromara.hmily.repository.spi.entity.HmilyParticipantUndo;
import org.dromara.hmily.repository.spi.entity.HmilyTransaction;
import org.dromara.hmily.repository.spi.exception.HmilyRepositoryException;

/**
* The type Hmily coordinator facade.
Expand All @@ -34,11 +37,11 @@ public final class HmilyRepositoryFacade {

private static final HmilyRepositoryFacade INSTANCE = new HmilyRepositoryFacade();

private final HmilyConfig hmilyConfig = ConfigEnv.getInstance().getConfig(HmilyConfig.class);

@Setter
private HmilyRepository hmilyRepository;

@Setter
private boolean phyDeleted;

private HmilyRepositoryFacade() {
}
Expand All @@ -56,69 +59,63 @@ public static HmilyRepositoryFacade getInstance() {
* Create hmily transaction string.
*
* @param hmilyTransaction the hmily transaction
* @return the string
*/
public boolean createHmilyTransaction(final HmilyTransaction hmilyTransaction) {
return hmilyRepository.createHmilyTransaction(hmilyTransaction) > 0;
public void createHmilyTransaction(final HmilyTransaction hmilyTransaction) {
checkRows(hmilyRepository.createHmilyTransaction(hmilyTransaction));
}

/**
* Update hmily transaction status int.
*
* @param transId the trans id
* @param status the status
* @return the int
*/
public boolean updateHmilyTransactionStatus(final Long transId, final Integer status) {
return hmilyRepository.updateHmilyTransactionStatus(transId, status) > 0;
public void updateHmilyTransactionStatus(final Long transId, final Integer status) {
checkRows(hmilyRepository.updateHmilyTransactionStatus(transId, status));
}

/**
* Remove hmily transaction boolean.
* Remove hmily transaction.
*
* @param transId the trans id
* @return the boolean
*/
public boolean removeHmilyTransaction(final Long transId) {
if (phyDeleted) {
return hmilyRepository.removeHmilyTransaction(transId) > 0;
public void removeHmilyTransaction(final Long transId) {
if (hmilyConfig.isPhyDeleted()) {
checkRows(hmilyRepository.removeHmilyTransaction(transId));
} else {
return updateHmilyTransactionStatus(transId, HmilyActionEnum.DELETE.getCode());
updateHmilyTransactionStatus(transId, HmilyActionEnum.DELETE.getCode());
}
}

/**
* Create hmily participant boolean.
* Create hmily participant.
*
* @param hmilyParticipant the hmily participant
* @return the boolean
*/
public boolean createHmilyParticipant(final HmilyParticipant hmilyParticipant) {
return hmilyRepository.createHmilyParticipant(hmilyParticipant) > 0;
public void createHmilyParticipant(final HmilyParticipant hmilyParticipant) {
checkRows(hmilyRepository.createHmilyParticipant(hmilyParticipant));
}

/**
* Update hmily participant status int.
* Update hmily participant status.
*
* @param transId the trans id
* @param status the status
* @return the int
*/
public boolean updateHmilyParticipantStatus(final Long transId, final Integer status) {
return hmilyRepository.updateHmilyParticipantStatus(transId, status) > 0;
public void updateHmilyParticipantStatus(final Long transId, final Integer status) {
checkRows(hmilyRepository.updateHmilyParticipantStatus(transId, status));
}

/**
* Remove hmily participant boolean.
* Remove hmily participant.
*
* @param participantId the participant id
* @return the boolean
*/
public boolean removeHmilyParticipant(final Long participantId) {
if (phyDeleted) {
return hmilyRepository.removeHmilyParticipant(participantId) > 0;
public void removeHmilyParticipant(final Long participantId) {
if (hmilyConfig.isPhyDeleted()) {
checkRows(hmilyRepository.removeHmilyParticipant(participantId));
} else {
return updateHmilyParticipantStatus(participantId, HmilyActionEnum.DELETE.getCode());
updateHmilyParticipantStatus(participantId, HmilyActionEnum.DELETE.getCode());
}
}

Expand All @@ -133,13 +130,12 @@ public List<HmilyParticipant> findHmilyParticipant(final Long participantId) {
}

/**
* Create hmily participant undo boolean.
* Create hmily participant undo.
*
* @param undo the undo
* @return the boolean
*/
public boolean createHmilyParticipantUndo(final HmilyParticipantUndo undo) {
return hmilyRepository.createHmilyParticipantUndo(undo) > 0;
public void createHmilyParticipantUndo(final HmilyParticipantUndo undo) {
checkRows(hmilyRepository.createHmilyParticipantUndo(undo));
}

/**
Expand All @@ -153,27 +149,31 @@ public List<HmilyParticipantUndo> findUndoByParticipantId(final Long participant
}

/**
* Remove hmily participant undo boolean.
* Remove hmily participant undo.
*
* @param undoId the undo id
* @return the boolean
*/
public boolean removeHmilyParticipantUndo(final Long undoId) {
if (phyDeleted) {
return hmilyRepository.removeHmilyParticipantUndo(undoId) > 0;
public void removeHmilyParticipantUndo(final Long undoId) {
if (hmilyConfig.isPhyDeleted()) {
checkRows(hmilyRepository.removeHmilyParticipantUndo(undoId));
} else {
return updateHmilyParticipantUndoStatus(undoId, HmilyActionEnum.DELETE.getCode());
updateHmilyParticipantUndoStatus(undoId, HmilyActionEnum.DELETE.getCode());
}
}

/**
* Update hmily participant undo status boolean.
* Update hmily participant undo status.
*
* @param undoId the undo id
* @param status the status
* @return the boolean
*/
public boolean updateHmilyParticipantUndoStatus(final Long undoId, final Integer status) {
return hmilyRepository.updateHmilyParticipantUndoStatus(undoId, status) > 0;
public void updateHmilyParticipantUndoStatus(final Long undoId, final Integer status) {
checkRows(hmilyRepository.updateHmilyParticipantUndoStatus(undoId, status));
}

private void checkRows(final int rows) {
if (rows != 1) {
throw new HmilyRepositoryException("hmily repository have exception");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class HmilyTransactionRecoveryService {
public boolean cancel(final HmilyParticipant hmilyParticipant) {
try {
HmilyReflector.executor(HmilyActionEnum.CANCELING, ExecutorTypeEnum.LOCAL, hmilyParticipant);
return removeHmilyParticipant(hmilyParticipant.getParticipantId());
removeHmilyParticipant(hmilyParticipant.getParticipantId());
return true;
} catch (Exception e) {
LOGGER.error("hmily Recovery executor cancel exception param {}", hmilyParticipant.toString(), e);
return false;
Expand All @@ -59,14 +60,15 @@ public boolean cancel(final HmilyParticipant hmilyParticipant) {
public boolean confirm(final HmilyParticipant hmilyParticipant) {
try {
HmilyReflector.executor(HmilyActionEnum.CONFIRMING, ExecutorTypeEnum.LOCAL, hmilyParticipant);
return removeHmilyParticipant(hmilyParticipant.getParticipantId());
removeHmilyParticipant(hmilyParticipant.getParticipantId());
return true;
} catch (Exception e) {
LOGGER.error("hmily Recovery executor confirm exception param:{} ", hmilyParticipant.toString(), e);
return false;
}
}

private boolean removeHmilyParticipant(final Long participantId) {
return HmilyRepositoryFacade.getInstance().removeHmilyParticipant(participantId);
private void removeHmilyParticipant(final Long participantId) {
HmilyRepositoryFacade.getInstance().removeHmilyParticipant(participantId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hmily:
retryMax: 10
bufferSize: 8192
consumerThreads: 16
asyncRepository: true
asyncRepository: false
autoSql: true
phyDeleted: true
storeDays: 3
Expand All @@ -36,7 +36,7 @@ repository:
idleTimeout: 600000
maxLifetime: 1800000
file:
path:
path: D:\hmilyLog
prefix: /hmily
mongo:
databaseName:
Expand All @@ -45,7 +45,7 @@ repository:
password:
zookeeper:
host: localhost:2181
sessionTimeOut: 1000
sessionTimeOut: 1000000000
rootPath: /hmily
redis:
cluster: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hmily:
retryMax: 10
bufferSize: 8192
consumerThreads: 16
asyncRepository: true
asyncRepository: false
autoSql: true
phyDeleted: true
storeDays: 3
Expand All @@ -36,7 +36,7 @@ repository:
idleTimeout: 600000
maxLifetime: 1800000
file:
path:
path: D:\hmilyLog
prefix: /hmily
mongo:
databaseName:
Expand All @@ -45,7 +45,7 @@ repository:
password:
zookeeper:
host: localhost:2181
sessionTimeOut: 1000
sessionTimeOut: 1000000000
rootPath: /hmily
redis:
cluster: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hmily:
retryMax: 10
bufferSize: 8192
consumerThreads: 16
asyncRepository: true
asyncRepository: false
autoSql: true
phyDeleted: true
storeDays: 3
Expand All @@ -36,7 +36,7 @@ repository:
idleTimeout: 600000
maxLifetime: 1800000
file:
path:
path: D:\hmilyLog
prefix: /hmily
mongo:
databaseName:
Expand All @@ -45,7 +45,7 @@ repository:
password:
zookeeper:
host: localhost:2181
sessionTimeOut: 1000
sessionTimeOut: 1000000000
rootPath: /hmily
redis:
cluster: false
Expand Down
2 changes: 1 addition & 1 deletion hmily-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<module>hmily-demo-common</module>
<module>hmily-demo-sofa</module>
<module>hmily-demo-tars</module>
<module>hmily-demo-bprc</module>
<module>hmily-demo-brpc</module>
</modules>

<properties>
Expand Down
Loading

0 comments on commit 4c44cbf

Please sign in to comment.